Completed
Branch BUG/11155/fix-payment-capabili... (aa00b4)
by
unknown
11:45 queued 11s
created
admin_pages/transactions/Transactions_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -2166,6 +2166,7 @@
 block discarded – undo
2166 2166
      *
2167 2167
      * @access protected
2168 2168
      * @param \EE_Payment | null $payment
2169
+     * @param EE_Payment $payment
2169 2170
      */
2170 2171
     protected function _maybe_send_notifications($payment = null)
2171 2172
     {
Please login to merge, or discard this patch.
Indentation   +2358 added lines, -2358 removed lines patch added patch discarded remove patch
@@ -16,2362 +16,2362 @@
 block discarded – undo
16 16
 class Transactions_Admin_Page extends EE_Admin_Page
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Transaction
21
-     */
22
-    private $_transaction;
23
-
24
-    /**
25
-     * @var EE_Session
26
-     */
27
-    private $_session;
28
-
29
-    /**
30
-     * @var array $_txn_status
31
-     */
32
-    private static $_txn_status;
33
-
34
-    /**
35
-     * @var array $_pay_status
36
-     */
37
-    private static $_pay_status;
38
-
39
-    /**
40
-     * @var array $_existing_reg_payment_REG_IDs
41
-     */
42
-    protected $_existing_reg_payment_REG_IDs = null;
43
-
44
-
45
-    /**
46
-     * @Constructor
47
-     * @access public
48
-     * @param bool $routing
49
-     * @throws EE_Error
50
-     * @throws InvalidArgumentException
51
-     * @throws ReflectionException
52
-     * @throws InvalidDataTypeException
53
-     * @throws InvalidInterfaceException
54
-     */
55
-    public function __construct($routing = true)
56
-    {
57
-        parent::__construct($routing);
58
-    }
59
-
60
-
61
-    /**
62
-     *    _init_page_props
63
-     *
64
-     * @return void
65
-     */
66
-    protected function _init_page_props()
67
-    {
68
-        $this->page_slug        = TXN_PG_SLUG;
69
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
70
-        $this->_admin_base_url  = TXN_ADMIN_URL;
71
-        $this->_admin_base_path = TXN_ADMIN;
72
-    }
73
-
74
-
75
-    /**
76
-     *    _ajax_hooks
77
-     *
78
-     * @return void
79
-     */
80
-    protected function _ajax_hooks()
81
-    {
82
-        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
83
-        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
84
-        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
85
-    }
86
-
87
-
88
-    /**
89
-     *    _define_page_props
90
-     *
91
-     * @return void
92
-     */
93
-    protected function _define_page_props()
94
-    {
95
-        $this->_admin_page_title = $this->page_label;
96
-        $this->_labels           = array(
97
-            'buttons' => array(
98
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
99
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
100
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
101
-            ),
102
-        );
103
-    }
104
-
105
-
106
-    /**
107
-     *        grab url requests and route them
108
-     *
109
-     * @access private
110
-     * @return void
111
-     * @throws EE_Error
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     */
116
-    public function _set_page_routes()
117
-    {
118
-
119
-        $this->_set_transaction_status_array();
120
-
121
-        $txn_id = ! empty($this->_req_data['TXN_ID'])
122
-                  && ! is_array($this->_req_data['TXN_ID'])
123
-            ? $this->_req_data['TXN_ID']
124
-            : 0;
125
-
126
-        $this->_page_routes = array(
127
-
128
-            'default' => array(
129
-                'func'       => '_transactions_overview_list_table',
130
-                'capability' => 'ee_read_transactions',
131
-            ),
132
-
133
-            'view_transaction' => array(
134
-                'func'       => '_transaction_details',
135
-                'capability' => 'ee_read_transaction',
136
-                'obj_id'     => $txn_id,
137
-            ),
138
-
139
-            'send_payment_reminder' => array(
140
-                'func'       => '_send_payment_reminder',
141
-                'noheader'   => true,
142
-                'capability' => 'ee_send_message',
143
-            ),
144
-
145
-            'espresso_apply_payment' => array(
146
-                'func'       => 'apply_payments_or_refunds',
147
-                'noheader'   => true,
148
-                'capability' => 'ee_edit_payments',
149
-            ),
150
-
151
-            'espresso_apply_refund' => array(
152
-                'func'       => 'apply_payments_or_refunds',
153
-                'noheader'   => true,
154
-                'capability' => 'ee_edit_payments',
155
-            ),
156
-
157
-            'espresso_delete_payment' => array(
158
-                'func'       => 'delete_payment',
159
-                'noheader'   => true,
160
-                'capability' => 'ee_delete_payments',
161
-            ),
162
-
163
-        );
164
-    }
165
-
166
-
167
-    protected function _set_page_config()
168
-    {
169
-        $this->_page_config = array(
170
-            'default'          => array(
171
-                'nav'           => array(
172
-                    'label' => esc_html__('Overview', 'event_espresso'),
173
-                    'order' => 10,
174
-                ),
175
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
176
-                'help_tabs'     => array(
177
-                    'transactions_overview_help_tab'                       => array(
178
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
179
-                        'filename' => 'transactions_overview',
180
-                    ),
181
-                    'transactions_overview_table_column_headings_help_tab' => array(
182
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
183
-                        'filename' => 'transactions_overview_table_column_headings',
184
-                    ),
185
-                    'transactions_overview_views_filters_help_tab'         => array(
186
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
187
-                        'filename' => 'transactions_overview_views_filters_search',
188
-                    ),
189
-                ),
190
-                'help_tour'     => array('Transactions_Overview_Help_Tour'),
191
-                /**
192
-                 * commented out because currently we are not displaying tips for transaction list table status but this
193
-                 * may change in a later iteration so want to keep the code for then.
194
-                 */
195
-                //'qtips' => array( 'Transactions_List_Table_Tips' ),
196
-                'require_nonce' => false,
197
-            ),
198
-            'view_transaction' => array(
199
-                'nav'       => array(
200
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
201
-                    'order'      => 5,
202
-                    'url'        => isset($this->_req_data['TXN_ID'])
203
-                        ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
204
-                        : $this->_admin_base_url,
205
-                    'persistent' => false,
206
-                ),
207
-                'help_tabs' => array(
208
-                    'transactions_view_transaction_help_tab'                                              => array(
209
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
210
-                        'filename' => 'transactions_view_transaction',
211
-                    ),
212
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
213
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
214
-                        'filename' => 'transactions_view_transaction_transaction_details_table',
215
-                    ),
216
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => array(
217
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
218
-                        'filename' => 'transactions_view_transaction_attendees_registered',
219
-                    ),
220
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
221
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
222
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
223
-                    ),
224
-                ),
225
-                'qtips'     => array('Transaction_Details_Tips'),
226
-                'help_tour' => array('Transaction_Details_Help_Tour'),
227
-                'metaboxes' => array('_transaction_details_metaboxes'),
228
-
229
-                'require_nonce' => false,
230
-            ),
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * The below methods aren't used by this class currently
237
-     */
238
-    protected function _add_screen_options()
239
-    {
240
-        //noop
241
-    }
242
-
243
-    protected function _add_feature_pointers()
244
-    {
245
-        //noop
246
-    }
247
-
248
-    public function admin_init()
249
-    {
250
-        // IF a registration was JUST added via the admin...
251
-        if (isset(
252
-            $this->_req_data['redirect_from'],
253
-            $this->_req_data['EVT_ID'],
254
-            $this->_req_data['event_name']
255
-        )) {
256
-            // then set a cookie so that we can block any attempts to use
257
-            // the back button as a way to enter another registration.
258
-            setcookie(
259
-                'ee_registration_added',
260
-                $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'
261
-            );
262
-            // and update the global
263
-            $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
264
-        }
265
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
266
-            '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.',
267
-            'event_espresso'
268
-        );
269
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
270
-            'An error occurred! Please refresh the page and try again.',
271
-            'event_espresso'
272
-        );
273
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
274
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
275
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
276
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
277
-            'This transaction has been overpaid ! Payments Total',
278
-            'event_espresso'
279
-        );
280
-    }
281
-
282
-    public function admin_notices()
283
-    {
284
-        //noop
285
-    }
286
-
287
-    public function admin_footer_scripts()
288
-    {
289
-        //noop
290
-    }
291
-
292
-
293
-    /**
294
-     * _set_transaction_status_array
295
-     * sets list of transaction statuses
296
-     *
297
-     * @access private
298
-     * @return void
299
-     * @throws EE_Error
300
-     * @throws InvalidArgumentException
301
-     * @throws InvalidDataTypeException
302
-     * @throws InvalidInterfaceException
303
-     */
304
-    private function _set_transaction_status_array()
305
-    {
306
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
307
-    }
308
-
309
-
310
-    /**
311
-     * get_transaction_status_array
312
-     * return the transaction status array for wp_list_table
313
-     *
314
-     * @access public
315
-     * @return array
316
-     */
317
-    public function get_transaction_status_array()
318
-    {
319
-        return self::$_txn_status;
320
-    }
321
-
322
-
323
-    /**
324
-     *    get list of payment statuses
325
-     *
326
-     * @access private
327
-     * @return void
328
-     * @throws EE_Error
329
-     * @throws InvalidArgumentException
330
-     * @throws InvalidDataTypeException
331
-     * @throws InvalidInterfaceException
332
-     */
333
-    private function _get_payment_status_array()
334
-    {
335
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
336
-        $this->_template_args['payment_status'] = self::$_pay_status;
337
-
338
-    }
339
-
340
-
341
-    /**
342
-     *    _add_screen_options_default
343
-     *
344
-     * @access protected
345
-     * @return void
346
-     * @throws InvalidArgumentException
347
-     * @throws InvalidDataTypeException
348
-     * @throws InvalidInterfaceException
349
-     */
350
-    protected function _add_screen_options_default()
351
-    {
352
-        $this->_per_page_screen_option();
353
-    }
354
-
355
-
356
-    /**
357
-     * load_scripts_styles
358
-     *
359
-     * @access public
360
-     * @return void
361
-     */
362
-    public function load_scripts_styles()
363
-    {
364
-        //enqueue style
365
-        wp_register_style(
366
-            'espresso_txn',
367
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
368
-            array(),
369
-            EVENT_ESPRESSO_VERSION
370
-        );
371
-        wp_enqueue_style('espresso_txn');
372
-        //scripts
373
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
374
-            'ee_admin_js',
375
-            'ee-datepicker',
376
-            'jquery-ui-datepicker',
377
-            'jquery-ui-draggable',
378
-            'ee-dialog',
379
-            'ee-accounting',
380
-            'ee-serialize-full-array',
381
-        ), EVENT_ESPRESSO_VERSION, true);
382
-        wp_enqueue_script('espresso_txn');
383
-    }
384
-
385
-
386
-    /**
387
-     *    load_scripts_styles_view_transaction
388
-     *
389
-     * @access public
390
-     * @return void
391
-     */
392
-    public function load_scripts_styles_view_transaction()
393
-    {
394
-        //styles
395
-        wp_enqueue_style('espresso-ui-theme');
396
-    }
397
-
398
-
399
-    /**
400
-     *    load_scripts_styles_default
401
-     *
402
-     * @access public
403
-     * @return void
404
-     */
405
-    public function load_scripts_styles_default()
406
-    {
407
-        //styles
408
-        wp_enqueue_style('espresso-ui-theme');
409
-    }
410
-
411
-
412
-    /**
413
-     *    _set_list_table_views_default
414
-     *
415
-     * @access protected
416
-     * @return void
417
-     */
418
-    protected function _set_list_table_views_default()
419
-    {
420
-        $this->_views = array(
421
-            'all'       => array(
422
-                'slug'  => 'all',
423
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
424
-                'count' => 0,
425
-            ),
426
-            'abandoned' => array(
427
-                'slug'  => 'abandoned',
428
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
429
-                'count' => 0,
430
-            ),
431
-            'failed'    => array(
432
-                'slug'  => 'failed',
433
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
434
-                'count' => 0,
435
-            ),
436
-        );
437
-    }
438
-
439
-
440
-    /**
441
-     * _set_transaction_object
442
-     * This sets the _transaction property for the transaction details screen
443
-     *
444
-     * @access private
445
-     * @return void
446
-     * @throws EE_Error
447
-     * @throws InvalidArgumentException
448
-     * @throws RuntimeException
449
-     * @throws InvalidDataTypeException
450
-     * @throws InvalidInterfaceException
451
-     */
452
-    private function _set_transaction_object()
453
-    {
454
-        if ($this->_transaction instanceof EE_Transaction) {
455
-            return;
456
-        } //get out we've already set the object
457
-
458
-        $TXN_ID = ! empty($this->_req_data['TXN_ID'])
459
-            ? absint($this->_req_data['TXN_ID'])
460
-            : false;
461
-
462
-        //get transaction object
463
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
464
-        $this->_session     = $this->_transaction instanceof EE_Transaction
465
-            ? $this->_transaction->get('TXN_session_data')
466
-            : null;
467
-        $this->_transaction->verify_abandoned_transaction_status();
468
-
469
-        if (! $this->_transaction instanceof EE_Transaction) {
470
-            $error_msg = sprintf(
471
-                esc_html__(
472
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
473
-                    'event_espresso'
474
-                ),
475
-                $TXN_ID
476
-            );
477
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
478
-        }
479
-    }
480
-
481
-
482
-    /**
483
-     *    _transaction_legend_items
484
-     *
485
-     * @access protected
486
-     * @return array
487
-     * @throws EE_Error
488
-     * @throws InvalidArgumentException
489
-     * @throws ReflectionException
490
-     * @throws InvalidDataTypeException
491
-     * @throws InvalidInterfaceException
492
-     */
493
-    protected function _transaction_legend_items()
494
-    {
495
-        EE_Registry::instance()->load_helper('MSG_Template');
496
-        $items = array();
497
-
498
-        if (EE_Registry::instance()->CAP->current_user_can(
499
-            'ee_read_global_messages',
500
-            'view_filtered_messages'
501
-        )) {
502
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
503
-            if (is_array($related_for_icon)
504
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
505
-            ) {
506
-                $items['view_related_messages'] = array(
507
-                    'class' => $related_for_icon['css_class'],
508
-                    'desc'  => $related_for_icon['label'],
509
-                );
510
-            }
511
-        }
512
-
513
-        $items = apply_filters(
514
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
515
-            array_merge(
516
-                $items,
517
-                array(
518
-                    'view_details'          => array(
519
-                        'class' => 'dashicons dashicons-cart',
520
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
521
-                    ),
522
-                    'view_invoice'          => array(
523
-                        'class' => 'dashicons dashicons-media-spreadsheet',
524
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
525
-                    ),
526
-                    'view_receipt'          => array(
527
-                        'class' => 'dashicons dashicons-media-default',
528
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
529
-                    ),
530
-                    'view_registration'     => array(
531
-                        'class' => 'dashicons dashicons-clipboard',
532
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
533
-                    ),
534
-                    'payment_overview_link' => array(
535
-                        'class' => 'dashicons dashicons-money',
536
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
537
-                    ),
538
-                )
539
-            )
540
-        );
541
-
542
-        if (EE_Registry::instance()->CAP->current_user_can(
543
-            'ee_send_message',
544
-            'espresso_transactions_send_payment_reminder'
545
-        )) {
546
-            if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
547
-                $items['send_payment_reminder'] = array(
548
-                    'class' => 'dashicons dashicons-email-alt',
549
-                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
550
-                );
551
-            } else {
552
-                $items['blank*'] = array(
553
-                    'class' => '',
554
-                    'desc'  => '',
555
-                );
556
-            }
557
-        } else {
558
-            $items['blank*'] = array(
559
-                'class' => '',
560
-                'desc'  => '',
561
-            );
562
-        }
563
-        $more_items = apply_filters(
564
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
565
-            array(
566
-                'overpaid'   => array(
567
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
568
-                    'desc'  => EEH_Template::pretty_status(
569
-                        EEM_Transaction::overpaid_status_code,
570
-                        false,
571
-                        'sentence'
572
-                    ),
573
-                ),
574
-                'complete'   => array(
575
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
576
-                    'desc'  => EEH_Template::pretty_status(
577
-                        EEM_Transaction::complete_status_code,
578
-                        false,
579
-                        'sentence'
580
-                    ),
581
-                ),
582
-                'incomplete' => array(
583
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
584
-                    'desc'  => EEH_Template::pretty_status(
585
-                        EEM_Transaction::incomplete_status_code,
586
-                        false,
587
-                        'sentence'
588
-                    ),
589
-                ),
590
-                'abandoned'  => array(
591
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
592
-                    'desc'  => EEH_Template::pretty_status(
593
-                        EEM_Transaction::abandoned_status_code,
594
-                        false,
595
-                        'sentence'
596
-                    ),
597
-                ),
598
-                'failed'     => array(
599
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
600
-                    'desc'  => EEH_Template::pretty_status(
601
-                        EEM_Transaction::failed_status_code,
602
-                        false,
603
-                        'sentence'
604
-                    ),
605
-                ),
606
-            )
607
-        );
608
-
609
-        return array_merge($items, $more_items);
610
-    }
611
-
612
-
613
-    /**
614
-     *    _transactions_overview_list_table
615
-     *
616
-     * @access protected
617
-     * @return void
618
-     * @throws DomainException
619
-     * @throws EE_Error
620
-     * @throws InvalidArgumentException
621
-     * @throws InvalidDataTypeException
622
-     * @throws InvalidInterfaceException
623
-     * @throws ReflectionException
624
-     */
625
-    protected function _transactions_overview_list_table()
626
-    {
627
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
628
-        $event = isset($this->_req_data['EVT_ID'])
629
-            ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
630
-            : null;
631
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
632
-            ? sprintf(
633
-                esc_html__(
634
-                    '%sViewing Transactions for the Event: %s%s',
635
-                    'event_espresso'
636
-                ),
637
-                '<h3>',
638
-                '<a href="'
639
-                . EE_Admin_Page::add_query_args_and_nonce(
640
-                    array('action' => 'edit', 'post' => $event->ID()),
641
-                    EVENTS_ADMIN_URL
642
-                )
643
-                . '" title="'
644
-                . esc_attr__(
645
-                    'Click to Edit event',
646
-                    'event_espresso'
647
-                )
648
-                . '">' . $event->get('EVT_name') . '</a>',
649
-                '</h3>'
650
-            )
651
-            : '';
652
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
653
-        $this->display_admin_list_table_page_with_no_sidebar();
654
-    }
655
-
656
-
657
-    /**
658
-     *    _transaction_details
659
-     * generates HTML for the View Transaction Details Admin page
660
-     *
661
-     * @access protected
662
-     * @return void
663
-     * @throws DomainException
664
-     * @throws EE_Error
665
-     * @throws InvalidArgumentException
666
-     * @throws InvalidDataTypeException
667
-     * @throws InvalidInterfaceException
668
-     * @throws RuntimeException
669
-     */
670
-    protected function _transaction_details()
671
-    {
672
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
673
-
674
-        $this->_set_transaction_status_array();
675
-
676
-        $this->_template_args                      = array();
677
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
678
-
679
-        $this->_set_transaction_object();
680
-
681
-        $primary_registration = $this->_transaction->primary_registration();
682
-        $attendee = $primary_registration instanceof EE_Registration
683
-            ? $primary_registration->attendee()
684
-            : null;
685
-
686
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
687
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
688
-
689
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
690
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
691
-
692
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
693
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
694
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
695
-
696
-        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
697
-        $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
698
-
699
-        if ($attendee instanceof EE_Attendee
700
-            && EE_Registry::instance()->CAP->current_user_can(
701
-                'ee_send_message',
702
-                'espresso_transactions_send_payment_reminder'
703
-            )
704
-        ) {
705
-            $this->_template_args['send_payment_reminder_button'] =
706
-                EEH_MSG_Template::is_mt_active('payment_reminder')
707
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
708
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
709
-                    ? EEH_Template::get_button_or_link(
710
-                        EE_Admin_Page::add_query_args_and_nonce(
711
-                            array(
712
-                                'action'      => 'send_payment_reminder',
713
-                                'TXN_ID'      => $this->_transaction->ID(),
714
-                                'redirect_to' => 'view_transaction',
715
-                            ),
716
-                            TXN_ADMIN_URL
717
-                        ),
718
-                        __(' Send Payment Reminder', 'event_espresso'),
719
-                        'button secondary-button right',
720
-                        'dashicons dashicons-email-alt'
721
-                    )
722
-                    : '';
723
-        } else {
724
-            $this->_template_args['send_payment_reminder_button'] = '';
725
-        }
726
-
727
-        $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
728
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
729
-            $amount_due,
730
-            true
731
-        );
732
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
733
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
734
-                                                  . $this->_template_args['amount_due'];
735
-        } else {
736
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
737
-        }
738
-        $this->_template_args['amount_due_class'] = '';
739
-
740
-        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
741
-            // paid in full
742
-            $this->_template_args['amount_due'] = false;
743
-        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
744
-            // overpaid
745
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
746
-        } elseif ($this->_transaction->get('TXN_total') > 0
747
-                  && $this->_transaction->get('TXN_paid') > 0
748
-        ) {
749
-            // monies owing
750
-            $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
751
-        } elseif ($this->_transaction->get('TXN_total') > 0
752
-                  && $this->_transaction->get('TXN_paid') == 0
753
-        ) {
754
-            // no payments made yet
755
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
756
-        } elseif ($this->_transaction->get('TXN_total') == 0) {
757
-            // free event
758
-            $this->_template_args['amount_due'] = false;
759
-        }
760
-
761
-        $payment_method = $this->_transaction->payment_method();
762
-
763
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
764
-            ? $payment_method->admin_name()
765
-            : esc_html__('Unknown', 'event_espresso');
766
-
767
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
768
-        // link back to overview
769
-        $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
770
-            ? $_SERVER['HTTP_REFERER']
771
-            : TXN_ADMIN_URL;
772
-
773
-
774
-        // next link
775
-        $next_txn                                 = $this->_transaction->next(
776
-            null,
777
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
778
-            'TXN_ID'
779
-        );
780
-        $this->_template_args['next_transaction'] = $next_txn
781
-            ? $this->_next_link(
782
-                EE_Admin_Page::add_query_args_and_nonce(
783
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
784
-                    TXN_ADMIN_URL
785
-                ),
786
-                'dashicons dashicons-arrow-right ee-icon-size-22'
787
-            )
788
-            : '';
789
-        // previous link
790
-        $previous_txn                                 = $this->_transaction->previous(
791
-            null,
792
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
793
-            'TXN_ID'
794
-        );
795
-        $this->_template_args['previous_transaction'] = $previous_txn
796
-            ? $this->_previous_link(
797
-                EE_Admin_Page::add_query_args_and_nonce(
798
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
799
-                    TXN_ADMIN_URL
800
-                ),
801
-                'dashicons dashicons-arrow-left ee-icon-size-22'
802
-            )
803
-            : '';
804
-
805
-        // were we just redirected here after adding a new registration ???
806
-        if (isset(
807
-            $this->_req_data['redirect_from'],
808
-            $this->_req_data['EVT_ID'],
809
-            $this->_req_data['event_name']
810
-        )) {
811
-            if (EE_Registry::instance()->CAP->current_user_can(
812
-                'ee_edit_registrations',
813
-                'espresso_registrations_new_registration',
814
-                $this->_req_data['EVT_ID']
815
-            )) {
816
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
817
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
818
-                    array(
819
-                        'page'     => 'espresso_registrations',
820
-                        'action'   => 'new_registration',
821
-                        'return'   => 'default',
822
-                        'TXN_ID'   => $this->_transaction->ID(),
823
-                        'event_id' => $this->_req_data['EVT_ID'],
824
-                    ),
825
-                    REG_ADMIN_URL
826
-                );
827
-                $this->_admin_page_title .= '">';
828
-
829
-                $this->_admin_page_title .= sprintf(
830
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
831
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
832
-                );
833
-                $this->_admin_page_title .= '</a>';
834
-            }
835
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
836
-        }
837
-        // grab messages at the last second
838
-        $this->_template_args['notices'] = EE_Error::get_notices();
839
-        // path to template
840
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
841
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
842
-            $template_path,
843
-            $this->_template_args,
844
-            true
845
-        );
846
-
847
-        // the details template wrapper
848
-        $this->display_admin_page_with_sidebar();
849
-
850
-    }
851
-
852
-
853
-    /**
854
-     *        _transaction_details_metaboxes
855
-     *
856
-     * @access protected
857
-     * @return void
858
-     * @throws EE_Error
859
-     * @throws InvalidArgumentException
860
-     * @throws InvalidDataTypeException
861
-     * @throws InvalidInterfaceException
862
-     * @throws RuntimeException
863
-     */
864
-    protected function _transaction_details_metaboxes()
865
-    {
866
-
867
-        $this->_set_transaction_object();
868
-
869
-        add_meta_box(
870
-            'edit-txn-details-mbox',
871
-            esc_html__('Transaction Details', 'event_espresso'),
872
-            array($this, 'txn_details_meta_box'),
873
-            $this->_wp_page_slug,
874
-            'normal',
875
-            'high'
876
-        );
877
-        add_meta_box(
878
-            'edit-txn-attendees-mbox',
879
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
880
-            array($this, 'txn_attendees_meta_box'),
881
-            $this->_wp_page_slug,
882
-            'normal',
883
-            'high',
884
-            array('TXN_ID' => $this->_transaction->ID())
885
-        );
886
-        add_meta_box(
887
-            'edit-txn-registrant-mbox',
888
-            esc_html__('Primary Contact', 'event_espresso'),
889
-            array($this, 'txn_registrant_side_meta_box'),
890
-            $this->_wp_page_slug,
891
-            'side',
892
-            'high'
893
-        );
894
-        add_meta_box(
895
-            'edit-txn-billing-info-mbox',
896
-            esc_html__('Billing Information', 'event_espresso'),
897
-            array($this, 'txn_billing_info_side_meta_box'),
898
-            $this->_wp_page_slug,
899
-            'side',
900
-            'high'
901
-        );
902
-    }
903
-
904
-
905
-    /**
906
-     * txn_details_meta_box
907
-     * generates HTML for the Transaction main meta box
908
-     *
909
-     * @access public
910
-     * @return void
911
-     * @throws DomainException
912
-     * @throws EE_Error
913
-     * @throws InvalidArgumentException
914
-     * @throws InvalidDataTypeException
915
-     * @throws InvalidInterfaceException
916
-     * @throws RuntimeException
917
-     */
918
-    public function txn_details_meta_box()
919
-    {
920
-
921
-        $this->_set_transaction_object();
922
-        $this->_template_args['TXN_ID']   = $this->_transaction->ID();
923
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
924
-            ? $this->_transaction->primary_registration()->attendee()
925
-            : null;
926
-
927
-        //get line table
928
-        EEH_Autoloader::register_line_item_display_autoloaders();
929
-        $Line_Item_Display                       = new EE_Line_Item_Display(
930
-            'admin_table',
931
-            'EE_Admin_Table_Line_Item_Display_Strategy'
932
-        );
933
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
934
-            $this->_transaction->total_line_item()
935
-        );
936
-        $this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')
937
-                                                                      ->get('REG_code');
938
-
939
-        // process taxes
940
-        $taxes                         = $this->_transaction->get_many_related(
941
-            'Line_Item',
942
-            array(array('LIN_type' => EEM_Line_Item::type_tax))
943
-        );
944
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
945
-
946
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
947
-            $this->_transaction->get('TXN_total'),
948
-            false,
949
-            false
950
-        );
951
-        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
952
-        $this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
953
-
954
-        // process payment details
955
-        $payments = $this->_transaction->get_many_related('Payment');
956
-        if (! empty($payments)) {
957
-            $this->_template_args['payments']              = $payments;
958
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
959
-        } else {
960
-            $this->_template_args['payments']              = false;
961
-            $this->_template_args['existing_reg_payments'] = array();
962
-        }
963
-
964
-        $this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
965
-        $this->_template_args['delete_payment_url'] = add_query_arg(
966
-            array('action' => 'espresso_delete_payment'),
967
-            TXN_ADMIN_URL
968
-        );
969
-
970
-        if (isset($txn_details['invoice_number'])) {
971
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
972
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
973
-                'Invoice Number',
974
-                'event_espresso'
975
-            );
976
-        }
977
-
978
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
979
-            ->get_first_related('Registration')
980
-            ->get('REG_session');
981
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
982
-            'Registration Session',
983
-            'event_espresso'
984
-        );
985
-
986
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
987
-            ? $this->_session['ip_address']
988
-            : '';
989
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
990
-            'Transaction placed from IP',
991
-            'event_espresso'
992
-        );
993
-
994
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
995
-            ? $this->_session['user_agent']
996
-            : '';
997
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
998
-            'Registrant User Agent',
999
-            'event_espresso'
1000
-        );
1001
-
1002
-        $reg_steps = '<ul>';
1003
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1004
-            if ($reg_step_status === true) {
1005
-                $reg_steps .= '<li style="color:#70cc50">'
1006
-                              . sprintf(
1007
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1008
-                                  ucwords(str_replace('_', ' ', $reg_step))
1009
-                              )
1010
-                              . '</li>';
1011
-            } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1012
-                $reg_steps .= '<li style="color:#2EA2CC">'
1013
-                              . sprintf(
1014
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1015
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1016
-                                  date(
1017
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1018
-                                      ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1019
-                                  )
1020
-                              )
1021
-                              . '</li>';
1022
-            } else {
1023
-                $reg_steps .= '<li style="color:#E76700">'
1024
-                              . sprintf(
1025
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1026
-                                  ucwords(str_replace('_', ' ', $reg_step))
1027
-                              )
1028
-                              . '</li>';
1029
-            }
1030
-        }
1031
-        $reg_steps                                                 .= '</ul>';
1032
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1033
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1034
-            'Registration Step Progress',
1035
-            'event_espresso'
1036
-        );
1037
-
1038
-
1039
-        $this->_get_registrations_to_apply_payment_to();
1040
-        $this->_get_payment_methods($payments);
1041
-        $this->_get_payment_status_array();
1042
-        $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1043
-
1044
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
1045
-            'action'  => 'edit_transaction',
1046
-            'process' => 'transaction',
1047
-        ), TXN_ADMIN_URL);
1048
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1049
-            'page'   => 'espresso_transactions',
1050
-            'action' => 'espresso_apply_payment',
1051
-        ), WP_AJAX_URL);
1052
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(array(
1053
-            'page'   => 'espresso_transactions',
1054
-            'action' => 'espresso_delete_payment',
1055
-        ), WP_AJAX_URL);
1056
-
1057
-        // 'espresso_delete_payment_nonce'
1058
-
1059
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1060
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1061
-    }
1062
-
1063
-
1064
-    /**
1065
-     * _get_registration_payment_IDs
1066
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1067
-     *
1068
-     * @access protected
1069
-     * @param EE_Payment[] $payments
1070
-     * @return array
1071
-     * @throws EE_Error
1072
-     * @throws InvalidArgumentException
1073
-     * @throws InvalidDataTypeException
1074
-     * @throws InvalidInterfaceException
1075
-     */
1076
-    protected function _get_registration_payment_IDs($payments = array())
1077
-    {
1078
-        $existing_reg_payments = array();
1079
-        // get all reg payments for these payments
1080
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(array(
1081
-            array(
1082
-                'PAY_ID' => array(
1083
-                    'IN',
1084
-                    array_keys($payments),
1085
-                ),
1086
-            ),
1087
-        ));
1088
-        if (! empty($reg_payments)) {
1089
-            foreach ($payments as $payment) {
1090
-                if (! $payment instanceof EE_Payment) {
1091
-                    continue;
1092
-                } elseif (! isset($existing_reg_payments[$payment->ID()])) {
1093
-                    $existing_reg_payments[$payment->ID()] = array();
1094
-                }
1095
-                foreach ($reg_payments as $reg_payment) {
1096
-                    if ($reg_payment instanceof EE_Registration_Payment
1097
-                        && $reg_payment->payment_ID() === $payment->ID()
1098
-                    ) {
1099
-                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1100
-                    }
1101
-                }
1102
-            }
1103
-        }
1104
-
1105
-        return $existing_reg_payments;
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * _get_registrations_to_apply_payment_to
1111
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1112
-     * which allows the admin to only apply the payment to the specific registrations
1113
-     *
1114
-     * @access protected
1115
-     * @return void
1116
-     * @throws \EE_Error
1117
-     */
1118
-    protected function _get_registrations_to_apply_payment_to()
1119
-    {
1120
-        // we want any registration with an active status (ie: not deleted or cancelled)
1121
-        $query_params                      = array(
1122
-            array(
1123
-                'STS_ID' => array(
1124
-                    'IN',
1125
-                    array(
1126
-                        EEM_Registration::status_id_approved,
1127
-                        EEM_Registration::status_id_pending_payment,
1128
-                        EEM_Registration::status_id_not_approved,
1129
-                    ),
1130
-                ),
1131
-            ),
1132
-        );
1133
-        $registrations_to_apply_payment_to = EEH_HTML::br()
1134
-                                             . EEH_HTML::div(
1135
-                                                 '',
1136
-                                                 'txn-admin-apply-payment-to-registrations-dv',
1137
-                                                 '',
1138
-                                                 'clear: both; margin: 1.5em 0 0; display: none;'
1139
-                                             );
1140
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1141
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1142
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1143
-            EEH_HTML::tr(
1144
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1145
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1146
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1147
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1148
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1149
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1150
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1151
-            )
1152
-        );
1153
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1154
-        // get registrations for TXN
1155
-        $registrations = $this->_transaction->registrations($query_params);
1156
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1157
-        foreach ($registrations as $registration) {
1158
-            if ($registration instanceof EE_Registration) {
1159
-                $attendee_name                     = $registration->attendee() instanceof EE_Attendee
1160
-                    ? $registration->attendee()->full_name()
1161
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1162
-                $owing                             = $registration->final_price() - $registration->paid();
1163
-                $taxable                           = $registration->ticket()->taxable()
1164
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1165
-                    : '';
1166
-                $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1167
-                    ? ' checked="checked"'
1168
-                    : '';
1169
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1170
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1171
-                    EEH_HTML::td($registration->ID()) .
1172
-                    EEH_HTML::td($attendee_name) .
1173
-                    EEH_HTML::td(
1174
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1175
-                    ) .
1176
-                    EEH_HTML::td($registration->event_name()) .
1177
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1178
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1179
-                    EEH_HTML::td(
1180
-                        '<input type="checkbox" value="' . $registration->ID()
1181
-                        . '" name="txn_admin_payment[registrations]"'
1182
-                        . $checked . $disabled . '>',
1183
-                        '',
1184
-                        'jst-cntr'
1185
-                    ),
1186
-                    'apply-payment-registration-row-' . $registration->ID()
1187
-                );
1188
-            }
1189
-        }
1190
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1191
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1192
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1193
-        $registrations_to_apply_payment_to                         .= EEH_HTML::p(
1194
-            esc_html__(
1195
-                '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.',
1196
-                'event_espresso'
1197
-            ),
1198
-            '',
1199
-            'clear description'
1200
-        );
1201
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1202
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1203
-    }
1204
-
1205
-
1206
-    /**
1207
-     * _get_reg_status_selection
1208
-     *
1209
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1210
-     *         instead of events.
1211
-     * @access protected
1212
-     * @return void
1213
-     * @throws EE_Error
1214
-     */
1215
-    protected function _get_reg_status_selection()
1216
-    {
1217
-        //first get all possible statuses
1218
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1219
-        //let's add a "don't change" option.
1220
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1221
-        $status_array                                        = array_merge($status_array, $statuses);
1222
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1223
-            'txn_reg_status_change[reg_status]',
1224
-            $status_array,
1225
-            'NAN',
1226
-            'id="txn-admin-payment-reg-status-inp"',
1227
-            'txn-reg-status-change-reg-status'
1228
-        );
1229
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1230
-            'delete_txn_reg_status_change[reg_status]',
1231
-            $status_array,
1232
-            'NAN',
1233
-            'delete-txn-admin-payment-reg-status-inp',
1234
-            'delete-txn-reg-status-change-reg-status'
1235
-        );
1236
-    }
1237
-
1238
-
1239
-    /**
1240
-     *    _get_payment_methods
1241
-     * Gets all the payment methods available generally, or the ones that are already
1242
-     * selected on these payments (in case their payment methods are no longer active).
1243
-     * Has the side-effect of updating the template args' payment_methods item
1244
-     *
1245
-     * @access private
1246
-     * @param EE_Payment[] to show on this page
1247
-     * @return void
1248
-     * @throws EE_Error
1249
-     * @throws InvalidArgumentException
1250
-     * @throws InvalidDataTypeException
1251
-     * @throws InvalidInterfaceException
1252
-     */
1253
-    private function _get_payment_methods($payments = array())
1254
-    {
1255
-        $payment_methods_of_payments = array();
1256
-        foreach ($payments as $payment) {
1257
-            if ($payment instanceof EE_Payment) {
1258
-                $payment_methods_of_payments[] = $payment->get('PMD_ID');
1259
-            }
1260
-        }
1261
-        if ($payment_methods_of_payments) {
1262
-            $query_args = array(
1263
-                array(
1264
-                    'OR*payment_method_for_payment' => array(
1265
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1266
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1267
-                    ),
1268
-                ),
1269
-            );
1270
-        } else {
1271
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1272
-        }
1273
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * txn_attendees_meta_box
1279
-     *    generates HTML for the Attendees Transaction main meta box
1280
-     *
1281
-     * @access public
1282
-     * @param WP_Post $post
1283
-     * @param array   $metabox
1284
-     * @return void
1285
-     * @throws DomainException
1286
-     * @throws EE_Error
1287
-     */
1288
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1289
-    {
1290
-
1291
-        /** @noinspection NonSecureExtractUsageInspection */
1292
-        extract($metabox['args']);
1293
-        $this->_template_args['post']            = $post;
1294
-        $this->_template_args['event_attendees'] = array();
1295
-        // process items in cart
1296
-        $line_items = $this->_transaction->get_many_related(
1297
-            'Line_Item',
1298
-            array(array('LIN_type' => 'line-item'))
1299
-        );
1300
-        if (! empty($line_items)) {
1301
-            foreach ($line_items as $item) {
1302
-                if ($item instanceof EE_Line_Item) {
1303
-                    switch ($item->OBJ_type()) {
1304
-                        case 'Event':
1305
-                            break;
1306
-                        case 'Ticket':
1307
-                            $ticket = $item->ticket();
1308
-                            //right now we're only handling tickets here.
1309
-                            //Cause its expected that only tickets will have attendees right?
1310
-                            if (! $ticket instanceof EE_Ticket) {
1311
-                                continue;
1312
-                            }
1313
-                            try {
1314
-                                $event_name = $ticket->get_event_name();
1315
-                            } catch (Exception $e) {
1316
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1317
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1318
-                            }
1319
-                            $event_name   .= ' - ' . $item->get('LIN_name');
1320
-                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1321
-                            // now get all of the registrations for this transaction that use this ticket
1322
-                            $registrations = $ticket->get_many_related(
1323
-                                'Registration',
1324
-                                array(array('TXN_ID' => $this->_transaction->ID()))
1325
-                            );
1326
-                            foreach ($registrations as $registration) {
1327
-                                if (! $registration instanceof EE_Registration) {
1328
-                                    continue;
1329
-                                }
1330
-                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1331
-                                    = $registration->status_ID();
1332
-                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']
1333
-                                    = $registration->count();
1334
-                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1335
-                                    = $event_name;
1336
-                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1337
-                                    = $ticket_price;
1338
-                                // attendee info
1339
-                                $attendee = $registration->get_first_related('Attendee');
1340
-                                if ($attendee instanceof EE_Attendee) {
1341
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']
1342
-                                        = $attendee->ID();
1343
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1344
-                                        = $attendee->full_name();
1345
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']
1346
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1347
-                                          . esc_html__(
1348
-                                              ' Event',
1349
-                                              'event_espresso'
1350
-                                          )
1351
-                                          . '">' . $attendee->email() . '</a>';
1352
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']
1353
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1354
-                                } else {
1355
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1356
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1357
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1358
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1359
-                                }
1360
-                            }
1361
-                            break;
1362
-
1363
-                    }
1364
-                }
1365
-            }
1366
-
1367
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1368
-                array(
1369
-                    'action'  => 'edit_transaction',
1370
-                    'process' => 'attendees',
1371
-                ),
1372
-                TXN_ADMIN_URL
1373
-            );
1374
-            echo EEH_Template::display_template(
1375
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1376
-                $this->_template_args,
1377
-                true
1378
-            );
1379
-
1380
-        } else {
1381
-            echo sprintf(
1382
-                esc_html__(
1383
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1384
-                    'event_espresso'
1385
-                ),
1386
-                '<p class="important-notice">',
1387
-                '</p>'
1388
-            );
1389
-        }
1390
-    }
1391
-
1392
-
1393
-    /**
1394
-     * txn_registrant_side_meta_box
1395
-     * generates HTML for the Edit Transaction side meta box
1396
-     *
1397
-     * @access public
1398
-     * @return void
1399
-     * @throws DomainException
1400
-     * @throws EE_Error
1401
-     * @throws InvalidArgumentException
1402
-     * @throws InvalidDataTypeException
1403
-     * @throws InvalidInterfaceException
1404
-     */
1405
-    public function txn_registrant_side_meta_box()
1406
-    {
1407
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1408
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1409
-            : null;
1410
-        if (! $primary_att instanceof EE_Attendee) {
1411
-            $this->_template_args['no_attendee_message'] = esc_html__(
1412
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1413
-                'event_espresso'
1414
-            );
1415
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1416
-        }
1417
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1418
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1419
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1420
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1421
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1422
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1423
-            'action' => 'edit_attendee',
1424
-            'post'   => $primary_att->ID(),
1425
-        ), REG_ADMIN_URL);
1426
-        // get formatted address for registrant
1427
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1428
-        echo EEH_Template::display_template(
1429
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1430
-            $this->_template_args,
1431
-            true
1432
-        );
1433
-    }
1434
-
1435
-
1436
-    /**
1437
-     * txn_billing_info_side_meta_box
1438
-     *    generates HTML for the Edit Transaction side meta box
1439
-     *
1440
-     * @access public
1441
-     * @return void
1442
-     * @throws DomainException
1443
-     * @throws EE_Error
1444
-     */
1445
-    public function txn_billing_info_side_meta_box()
1446
-    {
1447
-
1448
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1449
-        $this->_template_args['billing_form_url'] = add_query_arg(
1450
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1451
-            TXN_ADMIN_URL
1452
-        );
1453
-
1454
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1455
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1456
-    }
1457
-
1458
-
1459
-    /**
1460
-     * apply_payments_or_refunds
1461
-     *    registers a payment or refund made towards a transaction
1462
-     *
1463
-     * @access public
1464
-     * @return void
1465
-     * @throws EE_Error
1466
-     * @throws InvalidArgumentException
1467
-     * @throws ReflectionException
1468
-     * @throws RuntimeException
1469
-     * @throws InvalidDataTypeException
1470
-     * @throws InvalidInterfaceException
1471
-     */
1472
-    public function apply_payments_or_refunds()
1473
-    {
1474
-        $json_response_data = array('return_data' => false);
1475
-        $valid_data         = $this->_validate_payment_request_data();
1476
-        $has_access = EE_Registry::instance()->CAP->current_user_can(
1477
-            'ee_edit_payments',
1478
-            'apply_payment_or_refund_from_registration_details'
1479
-        );
1480
-        if (! empty($valid_data) && $has_access) {
1481
-            $PAY_ID = $valid_data['PAY_ID'];
1482
-            //save  the new payment
1483
-            $payment = $this->_create_payment_from_request_data($valid_data);
1484
-            // get the TXN for this payment
1485
-            $transaction = $payment->transaction();
1486
-            // verify transaction
1487
-            if ($transaction instanceof EE_Transaction) {
1488
-                // calculate_total_payments_and_update_status
1489
-                $this->_process_transaction_payments($transaction);
1490
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1491
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1492
-                // apply payment to registrations (if applicable)
1493
-                if (! empty($REG_IDs)) {
1494
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1495
-                    $this->_maybe_send_notifications();
1496
-                    // now process status changes for the same registrations
1497
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1498
-                }
1499
-                $this->_maybe_send_notifications($payment);
1500
-                //prepare to render page
1501
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1502
-                do_action(
1503
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1504
-                    $transaction,
1505
-                    $payment
1506
-                );
1507
-            } else {
1508
-                EE_Error::add_error(
1509
-                    esc_html__(
1510
-                        'A valid Transaction for this payment could not be retrieved.',
1511
-                        'event_espresso'
1512
-                    ),
1513
-                    __FILE__,
1514
-                    __FUNCTION__,
1515
-                    __LINE__
1516
-                );
1517
-            }
1518
-        } else {
1519
-            if ($has_access) {
1520
-                EE_Error::add_error(
1521
-                    esc_html__(
1522
-                        'The payment form data could not be processed. Please try again.',
1523
-                        'event_espresso'
1524
-                    ),
1525
-                    __FILE__,
1526
-                    __FUNCTION__,
1527
-                    __LINE__
1528
-                );
1529
-            } else {
1530
-                EE_Error::add_error(
1531
-                    esc_html__(
1532
-                        'You do not have access to apply payments or refunds to a registration.',
1533
-                        'event_espresso'
1534
-                    ),
1535
-                    __FILE__,
1536
-                    __FUNCTION__,
1537
-                    __LINE__
1538
-                );
1539
-            }
1540
-        }
1541
-        $notices              = EE_Error::get_notices(
1542
-            false,
1543
-            false,
1544
-            false
1545
-        );
1546
-        $this->_template_args = array(
1547
-            'data'    => $json_response_data,
1548
-            'error'   => $notices['errors'],
1549
-            'success' => $notices['success'],
1550
-        );
1551
-        $this->_return_json();
1552
-    }
1553
-
1554
-
1555
-    /**
1556
-     * _validate_payment_request_data
1557
-     *
1558
-     * @return array
1559
-     */
1560
-    protected function _validate_payment_request_data()
1561
-    {
1562
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1563
-            return false;
1564
-        }
1565
-        $payment_form = $this->_generate_payment_form_section();
1566
-        try {
1567
-            if ($payment_form->was_submitted()) {
1568
-                $payment_form->receive_form_submission();
1569
-                if (! $payment_form->is_valid()) {
1570
-                    $submission_error_messages = array();
1571
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1572
-                        if ($validation_error instanceof EE_Validation_Error) {
1573
-                            $submission_error_messages[] = sprintf(
1574
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1575
-                                $validation_error->get_form_section()->html_label_text(),
1576
-                                $validation_error->getMessage()
1577
-                            );
1578
-                        }
1579
-                    }
1580
-                    EE_Error::add_error(
1581
-                        implode('<br />', $submission_error_messages),
1582
-                        __FILE__,
1583
-                        __FUNCTION__,
1584
-                        __LINE__
1585
-                    );
1586
-
1587
-                    return array();
1588
-                }
1589
-            }
1590
-        } catch (EE_Error $e) {
1591
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1592
-
1593
-            return array();
1594
-        }
1595
-
1596
-        return $payment_form->valid_data();
1597
-    }
1598
-
1599
-
1600
-    /**
1601
-     * _generate_payment_form_section
1602
-     *
1603
-     * @return EE_Form_Section_Proper
1604
-     */
1605
-    protected function _generate_payment_form_section()
1606
-    {
1607
-        return new EE_Form_Section_Proper(
1608
-            array(
1609
-                'name'        => 'txn_admin_payment',
1610
-                'subsections' => array(
1611
-                    'PAY_ID'          => new EE_Text_Input(
1612
-                        array(
1613
-                            'default'               => 0,
1614
-                            'required'              => false,
1615
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1616
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1617
-                        )
1618
-                    ),
1619
-                    'TXN_ID'          => new EE_Text_Input(
1620
-                        array(
1621
-                            'default'               => 0,
1622
-                            'required'              => true,
1623
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1624
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1625
-                        )
1626
-                    ),
1627
-                    'type'            => new EE_Text_Input(
1628
-                        array(
1629
-                            'default'               => 1,
1630
-                            'required'              => true,
1631
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1632
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1633
-                        )
1634
-                    ),
1635
-                    'amount'          => new EE_Text_Input(
1636
-                        array(
1637
-                            'default'               => 0,
1638
-                            'required'              => true,
1639
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1640
-                            'validation_strategies' => array(new EE_Float_Normalization()),
1641
-                        )
1642
-                    ),
1643
-                    'status'          => new EE_Text_Input(
1644
-                        array(
1645
-                            'default'         => EEM_Payment::status_id_approved,
1646
-                            'required'        => true,
1647
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1648
-                        )
1649
-                    ),
1650
-                    'PMD_ID'          => new EE_Text_Input(
1651
-                        array(
1652
-                            'default'               => 2,
1653
-                            'required'              => true,
1654
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1655
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1656
-                        )
1657
-                    ),
1658
-                    'date'            => new EE_Text_Input(
1659
-                        array(
1660
-                            'default'         => time(),
1661
-                            'required'        => true,
1662
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1663
-                        )
1664
-                    ),
1665
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1666
-                        array(
1667
-                            'default'               => '',
1668
-                            'required'              => false,
1669
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1670
-                            'validation_strategies' => array(
1671
-                                new EE_Max_Length_Validation_Strategy(
1672
-                                    esc_html__('Input too long', 'event_espresso'),
1673
-                                    100
1674
-                                ),
1675
-                            ),
1676
-                        )
1677
-                    ),
1678
-                    'po_number'       => new EE_Text_Input(
1679
-                        array(
1680
-                            'default'               => '',
1681
-                            'required'              => false,
1682
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1683
-                            'validation_strategies' => array(
1684
-                                new EE_Max_Length_Validation_Strategy(
1685
-                                    esc_html__('Input too long', 'event_espresso'),
1686
-                                    100
1687
-                                ),
1688
-                            ),
1689
-                        )
1690
-                    ),
1691
-                    'accounting'      => new EE_Text_Input(
1692
-                        array(
1693
-                            'default'               => '',
1694
-                            'required'              => false,
1695
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1696
-                            'validation_strategies' => array(
1697
-                                new EE_Max_Length_Validation_Strategy(
1698
-                                    esc_html__('Input too long', 'event_espresso'),
1699
-                                    100
1700
-                                ),
1701
-                            ),
1702
-                        )
1703
-                    ),
1704
-                ),
1705
-            )
1706
-        );
1707
-    }
1708
-
1709
-
1710
-    /**
1711
-     * _create_payment_from_request_data
1712
-     *
1713
-     * @param array $valid_data
1714
-     * @return EE_Payment
1715
-     * @throws EE_Error
1716
-     */
1717
-    protected function _create_payment_from_request_data($valid_data)
1718
-    {
1719
-        $PAY_ID = $valid_data['PAY_ID'];
1720
-        // get payment amount
1721
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1722
-        // payments have a type value of 1 and refunds have a type value of -1
1723
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1724
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1725
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1726
-        $date    = $valid_data['date']
1727
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1728
-            : date('Y-m-d g:i a', current_time('timestamp'));
1729
-        $payment = EE_Payment::new_instance(
1730
-            array(
1731
-                'TXN_ID'              => $valid_data['TXN_ID'],
1732
-                'STS_ID'              => $valid_data['status'],
1733
-                'PAY_timestamp'       => $date,
1734
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1735
-                'PMD_ID'              => $valid_data['PMD_ID'],
1736
-                'PAY_amount'          => $amount,
1737
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1738
-                'PAY_po_number'       => $valid_data['po_number'],
1739
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1740
-                'PAY_details'         => $valid_data,
1741
-                'PAY_ID'              => $PAY_ID,
1742
-            ),
1743
-            '',
1744
-            array('Y-m-d', 'g:i a')
1745
-        );
1746
-
1747
-        if (! $payment->save()) {
1748
-            EE_Error::add_error(
1749
-                sprintf(
1750
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1751
-                    $payment->ID()
1752
-                ),
1753
-                __FILE__, __FUNCTION__, __LINE__
1754
-            );
1755
-        }
1756
-
1757
-        return $payment;
1758
-    }
1759
-
1760
-
1761
-    /**
1762
-     * _process_transaction_payments
1763
-     *
1764
-     * @param \EE_Transaction $transaction
1765
-     * @return void
1766
-     * @throws EE_Error
1767
-     * @throws InvalidArgumentException
1768
-     * @throws ReflectionException
1769
-     * @throws InvalidDataTypeException
1770
-     * @throws InvalidInterfaceException
1771
-     */
1772
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1773
-    {
1774
-        /** @type EE_Transaction_Payments $transaction_payments */
1775
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1776
-        //update the transaction with this payment
1777
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1778
-            EE_Error::add_success(esc_html__(
1779
-                'The payment has been processed successfully.', 'event_espresso'),
1780
-                __FILE__,
1781
-                __FUNCTION__,
1782
-                __LINE__
1783
-            );
1784
-        } else {
1785
-            EE_Error::add_error(
1786
-                esc_html__(
1787
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1788
-                    'event_espresso'
1789
-                )
1790
-                ,
1791
-                __FILE__,
1792
-                __FUNCTION__,
1793
-                __LINE__
1794
-            );
1795
-        }
1796
-    }
1797
-
1798
-
1799
-    /**
1800
-     * _get_REG_IDs_to_apply_payment_to
1801
-     * returns a list of registration IDs that the payment will apply to
1802
-     *
1803
-     * @param \EE_Payment $payment
1804
-     * @return array
1805
-     * @throws EE_Error
1806
-     */
1807
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1808
-    {
1809
-        $REG_IDs = array();
1810
-        // grab array of IDs for specific registrations to apply changes to
1811
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1812
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1813
-        }
1814
-        //nothing specified ? then get all reg IDs
1815
-        if (empty($REG_IDs)) {
1816
-            $registrations = $payment->transaction()->registrations();
1817
-            $REG_IDs       = ! empty($registrations)
1818
-                ? array_keys($registrations)
1819
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1820
-        }
1821
-
1822
-        // ensure that REG_IDs are integers and NOT strings
1823
-        return array_map('intval', $REG_IDs);
1824
-    }
1825
-
1826
-
1827
-    /**
1828
-     * @return array
1829
-     */
1830
-    public function existing_reg_payment_REG_IDs()
1831
-    {
1832
-        return $this->_existing_reg_payment_REG_IDs;
1833
-    }
1834
-
1835
-
1836
-    /**
1837
-     * @param array $existing_reg_payment_REG_IDs
1838
-     */
1839
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1840
-    {
1841
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1842
-    }
1843
-
1844
-
1845
-    /**
1846
-     * _get_existing_reg_payment_REG_IDs
1847
-     * returns a list of registration IDs that the payment is currently related to
1848
-     * as recorded in the database
1849
-     *
1850
-     * @param \EE_Payment $payment
1851
-     * @return array
1852
-     * @throws EE_Error
1853
-     */
1854
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1855
-    {
1856
-        if ($this->existing_reg_payment_REG_IDs() === null) {
1857
-            // let's get any existing reg payment records for this payment
1858
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1859
-            // but we only want the REG IDs, so grab the array keys
1860
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1861
-                ? array_keys($existing_reg_payment_REG_IDs)
1862
-                : array();
1863
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1864
-        }
1865
-
1866
-        return $this->existing_reg_payment_REG_IDs();
1867
-    }
1868
-
1869
-
1870
-    /**
1871
-     * _remove_existing_registration_payments
1872
-     * this calculates the difference between existing relations
1873
-     * to the supplied payment and the new list registration IDs,
1874
-     * removes any related registrations that no longer apply,
1875
-     * and then updates the registration paid fields
1876
-     *
1877
-     * @param \EE_Payment $payment
1878
-     * @param int         $PAY_ID
1879
-     * @return bool;
1880
-     * @throws EE_Error
1881
-     * @throws InvalidArgumentException
1882
-     * @throws ReflectionException
1883
-     * @throws InvalidDataTypeException
1884
-     * @throws InvalidInterfaceException
1885
-     */
1886
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1887
-    {
1888
-        // newly created payments will have nothing recorded for $PAY_ID
1889
-        if ($PAY_ID == 0) {
1890
-            return false;
1891
-        }
1892
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1893
-        if (empty($existing_reg_payment_REG_IDs)) {
1894
-            return false;
1895
-        }
1896
-        /** @type EE_Transaction_Payments $transaction_payments */
1897
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1898
-
1899
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
1900
-            $payment,
1901
-            array(
1902
-                array(
1903
-                    'PAY_ID' => $payment->ID(),
1904
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1905
-                ),
1906
-            )
1907
-        );
1908
-    }
1909
-
1910
-
1911
-    /**
1912
-     * _update_registration_payments
1913
-     * this applies the payments to the selected registrations
1914
-     * but only if they have not already been paid for
1915
-     *
1916
-     * @param  EE_Transaction $transaction
1917
-     * @param \EE_Payment     $payment
1918
-     * @param array           $REG_IDs
1919
-     * @return void
1920
-     * @throws EE_Error
1921
-     * @throws InvalidArgumentException
1922
-     * @throws ReflectionException
1923
-     * @throws RuntimeException
1924
-     * @throws InvalidDataTypeException
1925
-     * @throws InvalidInterfaceException
1926
-     */
1927
-    protected function _update_registration_payments(
1928
-        EE_Transaction $transaction,
1929
-        EE_Payment $payment,
1930
-        $REG_IDs = array()
1931
-    ) {
1932
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1933
-        // so let's do that using our set of REG_IDs from the form
1934
-        $registration_query_where_params = array(
1935
-            'REG_ID' => array('IN', $REG_IDs),
1936
-        );
1937
-        // but add in some conditions regarding payment,
1938
-        // so that we don't apply payments to registrations that are free or have already been paid for
1939
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1940
-        if (! $payment->is_a_refund()) {
1941
-            $registration_query_where_params['REG_final_price']  = array('!=', 0);
1942
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1943
-        }
1944
-        $registrations = $transaction->registrations(array($registration_query_where_params));
1945
-        if (! empty($registrations)) {
1946
-            /** @type EE_Payment_Processor $payment_processor */
1947
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1948
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
1949
-        }
1950
-    }
1951
-
1952
-
1953
-    /**
1954
-     * _process_registration_status_change
1955
-     * This processes requested registration status changes for all the registrations
1956
-     * on a given transaction and (optionally) sends out notifications for the changes.
1957
-     *
1958
-     * @param  EE_Transaction $transaction
1959
-     * @param array           $REG_IDs
1960
-     * @return bool
1961
-     * @throws EE_Error
1962
-     * @throws InvalidArgumentException
1963
-     * @throws ReflectionException
1964
-     * @throws InvalidDataTypeException
1965
-     * @throws InvalidInterfaceException
1966
-     */
1967
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1968
-    {
1969
-        // first if there is no change in status then we get out.
1970
-        if (
1971
-            ! isset($this->_req_data['txn_reg_status_change']['reg_status'])
1972
-            || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
1973
-        ) {
1974
-            //no error message, no change requested, just nothing to do man.
1975
-            return false;
1976
-        }
1977
-        /** @type EE_Transaction_Processor $transaction_processor */
1978
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1979
-
1980
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1981
-        return $transaction_processor->manually_update_registration_statuses(
1982
-            $transaction,
1983
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1984
-            array(array('REG_ID' => array('IN', $REG_IDs)))
1985
-        );
1986
-    }
1987
-
1988
-
1989
-    /**
1990
-     * _build_payment_json_response
1991
-     *
1992
-     * @access public
1993
-     * @param \EE_Payment $payment
1994
-     * @param array       $REG_IDs
1995
-     * @param bool | null $delete_txn_reg_status_change
1996
-     * @return array
1997
-     * @throws EE_Error
1998
-     * @throws InvalidArgumentException
1999
-     * @throws InvalidDataTypeException
2000
-     * @throws InvalidInterfaceException
2001
-     */
2002
-    protected function _build_payment_json_response(
2003
-        EE_Payment $payment,
2004
-        $REG_IDs = array(),
2005
-        $delete_txn_reg_status_change = null
2006
-    ) {
2007
-        // was the payment deleted ?
2008
-        if (is_bool($delete_txn_reg_status_change)) {
2009
-            return array(
2010
-                'PAY_ID'                       => $payment->ID(),
2011
-                'amount'                       => $payment->amount(),
2012
-                'total_paid'                   => $payment->transaction()->paid(),
2013
-                'txn_status'                   => $payment->transaction()->status_ID(),
2014
-                'pay_status'                   => $payment->STS_ID(),
2015
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2016
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2017
-            );
2018
-        } else {
2019
-            $this->_get_payment_status_array();
2020
-
2021
-            return array(
2022
-                'amount'           => $payment->amount(),
2023
-                'total_paid'       => $payment->transaction()->paid(),
2024
-                'txn_status'       => $payment->transaction()->status_ID(),
2025
-                'pay_status'       => $payment->STS_ID(),
2026
-                'PAY_ID'           => $payment->ID(),
2027
-                'STS_ID'           => $payment->STS_ID(),
2028
-                'status'           => self::$_pay_status[$payment->STS_ID()],
2029
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2030
-                'method'           => strtoupper($payment->source()),
2031
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2032
-                'gateway'          => $payment->payment_method()
2033
-                    ? $payment->payment_method()->admin_name()
2034
-                    : esc_html__("Unknown", 'event_espresso'),
2035
-                'gateway_response' => $payment->gateway_response(),
2036
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2037
-                'po_number'        => $payment->po_number(),
2038
-                'extra_accntng'    => $payment->extra_accntng(),
2039
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2040
-            );
2041
-        }
2042
-    }
2043
-
2044
-
2045
-    /**
2046
-     * delete_payment
2047
-     *    delete a payment or refund made towards a transaction
2048
-     *
2049
-     * @access public
2050
-     * @return void
2051
-     * @throws EE_Error
2052
-     * @throws InvalidArgumentException
2053
-     * @throws ReflectionException
2054
-     * @throws InvalidDataTypeException
2055
-     * @throws InvalidInterfaceException
2056
-     */
2057
-    public function delete_payment()
2058
-    {
2059
-        $json_response_data = array('return_data' => false);
2060
-        $PAY_ID             = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2061
-            ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2062
-            : 0;
2063
-        $can_delete = EE_Registry::instance()->CAP->current_user_can(
2064
-            'ee_delete_payments',
2065
-            'delete_payment_from_registration_details'
2066
-        );
2067
-        if ($PAY_ID && $can_delete) {
2068
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2069
-                ? $this->_req_data['delete_txn_reg_status_change']
2070
-                : false;
2071
-            $payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2072
-            if ($payment instanceof EE_Payment) {
2073
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2074
-                /** @type EE_Transaction_Payments $transaction_payments */
2075
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2076
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2077
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2078
-                        $payment,
2079
-                        $REG_IDs,
2080
-                        $delete_txn_reg_status_change
2081
-                    );
2082
-                    if ($delete_txn_reg_status_change) {
2083
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2084
-                        //MAKE sure we also add the delete_txn_req_status_change to the
2085
-                        //$_REQUEST global because that's how messages will be looking for it.
2086
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2087
-                        $this->_maybe_send_notifications();
2088
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2089
-                    }
2090
-                }
2091
-            } else {
2092
-                EE_Error::add_error(
2093
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2094
-                    __FILE__, __FUNCTION__, __LINE__
2095
-                );
2096
-            }
2097
-        } else {
2098
-            if ($can_delete) {
2099
-                EE_Error::add_error(
2100
-                    esc_html__(
2101
-                        'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2102
-                        'event_espresso'
2103
-                    ),
2104
-                    __FILE__, __FUNCTION__, __LINE__
2105
-                );
2106
-            } else {
2107
-                EE_Error::add_error(
2108
-                    esc_html__(
2109
-                        'You do not have access to delete a payment.',
2110
-                        'event_espresso'
2111
-                    ),
2112
-                    __FILE__,
2113
-                    __FUNCTION__,
2114
-                    __LINE__
2115
-                );
2116
-            }
2117
-        }
2118
-        $notices              = EE_Error::get_notices(false, false, false);
2119
-        $this->_template_args = array(
2120
-            'data'      => $json_response_data,
2121
-            'success'   => $notices['success'],
2122
-            'error'     => $notices['errors'],
2123
-            'attention' => $notices['attention'],
2124
-        );
2125
-        $this->_return_json();
2126
-    }
2127
-
2128
-
2129
-    /**
2130
-     * _registration_payment_data_array
2131
-     * adds info for 'owing' and 'paid' for each registration to the json response
2132
-     *
2133
-     * @access protected
2134
-     * @param array $REG_IDs
2135
-     * @return array
2136
-     * @throws EE_Error
2137
-     * @throws InvalidArgumentException
2138
-     * @throws InvalidDataTypeException
2139
-     * @throws InvalidInterfaceException
2140
-     */
2141
-    protected function _registration_payment_data_array($REG_IDs)
2142
-    {
2143
-        $registration_payment_data = array();
2144
-        //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2145
-        if (! empty($REG_IDs)) {
2146
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2147
-            foreach ($registrations as $registration) {
2148
-                if ($registration instanceof EE_Registration) {
2149
-                    $registration_payment_data[$registration->ID()] = array(
2150
-                        'paid'  => $registration->pretty_paid(),
2151
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2152
-                    );
2153
-                }
2154
-            }
2155
-        }
2156
-
2157
-        return $registration_payment_data;
2158
-    }
2159
-
2160
-
2161
-    /**
2162
-     * _maybe_send_notifications
2163
-     * determines whether or not the admin has indicated that notifications should be sent.
2164
-     * If so, will toggle a filter switch for delivering registration notices.
2165
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2166
-     *
2167
-     * @access protected
2168
-     * @param \EE_Payment | null $payment
2169
-     */
2170
-    protected function _maybe_send_notifications($payment = null)
2171
-    {
2172
-        switch ($payment instanceof EE_Payment) {
2173
-            // payment notifications
2174
-            case true :
2175
-                if (
2176
-                    isset(
2177
-                        $this->_req_data['txn_payments'],
2178
-                        $this->_req_data['txn_payments']['send_notifications']
2179
-                    ) &&
2180
-                    filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2181
-                ) {
2182
-                    $this->_process_payment_notification($payment);
2183
-                }
2184
-                break;
2185
-            // registration notifications
2186
-            case false :
2187
-                if (
2188
-                    isset(
2189
-                        $this->_req_data['txn_reg_status_change'],
2190
-                        $this->_req_data['txn_reg_status_change']['send_notifications']
2191
-                    ) &&
2192
-                    filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2193
-                ) {
2194
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2195
-                }
2196
-                break;
2197
-        }
2198
-    }
2199
-
2200
-
2201
-    /**
2202
-     * _send_payment_reminder
2203
-     *    generates HTML for the View Transaction Details Admin page
2204
-     *
2205
-     * @access protected
2206
-     * @return void
2207
-     * @throws EE_Error
2208
-     * @throws InvalidArgumentException
2209
-     * @throws InvalidDataTypeException
2210
-     * @throws InvalidInterfaceException
2211
-     */
2212
-    protected function _send_payment_reminder()
2213
-    {
2214
-        $TXN_ID      = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2215
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2216
-        $query_args  = isset($this->_req_data['redirect_to']) ? array(
2217
-            'action' => $this->_req_data['redirect_to'],
2218
-            'TXN_ID' => $this->_req_data['TXN_ID'],
2219
-        ) : array();
2220
-        do_action(
2221
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2222
-            $transaction
2223
-        );
2224
-        $this->_redirect_after_action(
2225
-            false,
2226
-            esc_html__('payment reminder', 'event_espresso'),
2227
-            esc_html__('sent', 'event_espresso'),
2228
-            $query_args,
2229
-            true
2230
-        );
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     *  get_transactions
2236
-     *    get transactions for given parameters (used by list table)
2237
-     *
2238
-     * @param  int     $perpage how many transactions displayed per page
2239
-     * @param  boolean $count   return the count or objects
2240
-     * @param string   $view
2241
-     * @return mixed int = count || array of transaction objects
2242
-     * @throws EE_Error
2243
-     * @throws InvalidArgumentException
2244
-     * @throws InvalidDataTypeException
2245
-     * @throws InvalidInterfaceException
2246
-     */
2247
-    public function get_transactions($perpage, $count = false, $view = '')
2248
-    {
2249
-
2250
-        $TXN = EEM_Transaction::instance();
2251
-
2252
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
2253
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2254
-            : date(
2255
-                'm/d/Y',
2256
-                strtotime('-10 year')
2257
-            );
2258
-        $end_date   = isset($this->_req_data['txn-filter-end-date'])
2259
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2260
-            : date('m/d/Y');
2261
-
2262
-        //make sure our timestamps start and end right at the boundaries for each day
2263
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2264
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2265
-
2266
-
2267
-        //convert to timestamps
2268
-        $start_date = strtotime($start_date);
2269
-        $end_date   = strtotime($end_date);
2270
-
2271
-        //makes sure start date is the lowest value and vice versa
2272
-        $start_date = min($start_date, $end_date);
2273
-        $end_date   = max($start_date, $end_date);
2274
-
2275
-        //convert to correct format for query
2276
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2277
-            'TXN_timestamp',
2278
-            date('Y-m-d H:i:s', $start_date),
2279
-            'Y-m-d H:i:s'
2280
-        );
2281
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2282
-            'TXN_timestamp',
2283
-            date('Y-m-d H:i:s', $end_date),
2284
-            'Y-m-d H:i:s'
2285
-        );
2286
-
2287
-
2288
-        //set orderby
2289
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2290
-
2291
-        switch ($this->_req_data['orderby']) {
2292
-            case 'TXN_ID':
2293
-                $orderby = 'TXN_ID';
2294
-                break;
2295
-            case 'ATT_fname':
2296
-                $orderby = 'Registration.Attendee.ATT_fname';
2297
-                break;
2298
-            case 'event_name':
2299
-                $orderby = 'Registration.Event.EVT_name';
2300
-                break;
2301
-            default: //'TXN_timestamp'
2302
-                $orderby = 'TXN_timestamp';
2303
-        }
2304
-
2305
-        $sort         = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2306
-        $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2307
-        $per_page     = ! empty($perpage) ? $perpage : 10;
2308
-        $per_page     = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2309
-
2310
-        $offset = ($current_page - 1) * $per_page;
2311
-        $limit  = array($offset, $per_page);
2312
-
2313
-        $_where = array(
2314
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2315
-            'Registration.REG_count' => 1,
2316
-        );
2317
-
2318
-        if (isset($this->_req_data['EVT_ID'])) {
2319
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2320
-        }
2321
-
2322
-        if (isset($this->_req_data['s'])) {
2323
-            $search_string = '%' . $this->_req_data['s'] . '%';
2324
-            $_where['OR']  = array(
2325
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2326
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2327
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2328
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2329
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2330
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2331
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2332
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2333
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2334
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2335
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2336
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
2337
-                'Registration.REG_code'               => array('LIKE', $search_string),
2338
-                'Registration.REG_count'              => array('LIKE', $search_string),
2339
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
2340
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2341
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2342
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
2343
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2344
-                'TXN_session_data'                    => array('LIKE', $search_string),
2345
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2346
-            );
2347
-        }
2348
-
2349
-        //failed transactions
2350
-        $failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2351
-                     || ($count && $view === 'failed');
2352
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2353
-                     || ($count && $view === 'abandoned');
2354
-
2355
-        if ($failed) {
2356
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2357
-        } else if ($abandoned) {
2358
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2359
-        } else {
2360
-            $_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
2361
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2362
-        }
2363
-
2364
-        $query_params = array(
2365
-            $_where,
2366
-            'order_by'                 => array($orderby => $sort),
2367
-            'limit'                    => $limit,
2368
-            'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2369
-        );
2370
-
2371
-        $transactions = $count
2372
-            ? $TXN->count(array($_where), 'TXN_ID', true)
2373
-            : $TXN->get_all($query_params);
2374
-
2375
-        return $transactions;
2376
-    }
19
+	/**
20
+	 * @var EE_Transaction
21
+	 */
22
+	private $_transaction;
23
+
24
+	/**
25
+	 * @var EE_Session
26
+	 */
27
+	private $_session;
28
+
29
+	/**
30
+	 * @var array $_txn_status
31
+	 */
32
+	private static $_txn_status;
33
+
34
+	/**
35
+	 * @var array $_pay_status
36
+	 */
37
+	private static $_pay_status;
38
+
39
+	/**
40
+	 * @var array $_existing_reg_payment_REG_IDs
41
+	 */
42
+	protected $_existing_reg_payment_REG_IDs = null;
43
+
44
+
45
+	/**
46
+	 * @Constructor
47
+	 * @access public
48
+	 * @param bool $routing
49
+	 * @throws EE_Error
50
+	 * @throws InvalidArgumentException
51
+	 * @throws ReflectionException
52
+	 * @throws InvalidDataTypeException
53
+	 * @throws InvalidInterfaceException
54
+	 */
55
+	public function __construct($routing = true)
56
+	{
57
+		parent::__construct($routing);
58
+	}
59
+
60
+
61
+	/**
62
+	 *    _init_page_props
63
+	 *
64
+	 * @return void
65
+	 */
66
+	protected function _init_page_props()
67
+	{
68
+		$this->page_slug        = TXN_PG_SLUG;
69
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
70
+		$this->_admin_base_url  = TXN_ADMIN_URL;
71
+		$this->_admin_base_path = TXN_ADMIN;
72
+	}
73
+
74
+
75
+	/**
76
+	 *    _ajax_hooks
77
+	 *
78
+	 * @return void
79
+	 */
80
+	protected function _ajax_hooks()
81
+	{
82
+		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
83
+		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
84
+		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
85
+	}
86
+
87
+
88
+	/**
89
+	 *    _define_page_props
90
+	 *
91
+	 * @return void
92
+	 */
93
+	protected function _define_page_props()
94
+	{
95
+		$this->_admin_page_title = $this->page_label;
96
+		$this->_labels           = array(
97
+			'buttons' => array(
98
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
99
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
100
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
101
+			),
102
+		);
103
+	}
104
+
105
+
106
+	/**
107
+	 *        grab url requests and route them
108
+	 *
109
+	 * @access private
110
+	 * @return void
111
+	 * @throws EE_Error
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 */
116
+	public function _set_page_routes()
117
+	{
118
+
119
+		$this->_set_transaction_status_array();
120
+
121
+		$txn_id = ! empty($this->_req_data['TXN_ID'])
122
+				  && ! is_array($this->_req_data['TXN_ID'])
123
+			? $this->_req_data['TXN_ID']
124
+			: 0;
125
+
126
+		$this->_page_routes = array(
127
+
128
+			'default' => array(
129
+				'func'       => '_transactions_overview_list_table',
130
+				'capability' => 'ee_read_transactions',
131
+			),
132
+
133
+			'view_transaction' => array(
134
+				'func'       => '_transaction_details',
135
+				'capability' => 'ee_read_transaction',
136
+				'obj_id'     => $txn_id,
137
+			),
138
+
139
+			'send_payment_reminder' => array(
140
+				'func'       => '_send_payment_reminder',
141
+				'noheader'   => true,
142
+				'capability' => 'ee_send_message',
143
+			),
144
+
145
+			'espresso_apply_payment' => array(
146
+				'func'       => 'apply_payments_or_refunds',
147
+				'noheader'   => true,
148
+				'capability' => 'ee_edit_payments',
149
+			),
150
+
151
+			'espresso_apply_refund' => array(
152
+				'func'       => 'apply_payments_or_refunds',
153
+				'noheader'   => true,
154
+				'capability' => 'ee_edit_payments',
155
+			),
156
+
157
+			'espresso_delete_payment' => array(
158
+				'func'       => 'delete_payment',
159
+				'noheader'   => true,
160
+				'capability' => 'ee_delete_payments',
161
+			),
162
+
163
+		);
164
+	}
165
+
166
+
167
+	protected function _set_page_config()
168
+	{
169
+		$this->_page_config = array(
170
+			'default'          => array(
171
+				'nav'           => array(
172
+					'label' => esc_html__('Overview', 'event_espresso'),
173
+					'order' => 10,
174
+				),
175
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
176
+				'help_tabs'     => array(
177
+					'transactions_overview_help_tab'                       => array(
178
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
179
+						'filename' => 'transactions_overview',
180
+					),
181
+					'transactions_overview_table_column_headings_help_tab' => array(
182
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
183
+						'filename' => 'transactions_overview_table_column_headings',
184
+					),
185
+					'transactions_overview_views_filters_help_tab'         => array(
186
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
187
+						'filename' => 'transactions_overview_views_filters_search',
188
+					),
189
+				),
190
+				'help_tour'     => array('Transactions_Overview_Help_Tour'),
191
+				/**
192
+				 * commented out because currently we are not displaying tips for transaction list table status but this
193
+				 * may change in a later iteration so want to keep the code for then.
194
+				 */
195
+				//'qtips' => array( 'Transactions_List_Table_Tips' ),
196
+				'require_nonce' => false,
197
+			),
198
+			'view_transaction' => array(
199
+				'nav'       => array(
200
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
201
+					'order'      => 5,
202
+					'url'        => isset($this->_req_data['TXN_ID'])
203
+						? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
204
+						: $this->_admin_base_url,
205
+					'persistent' => false,
206
+				),
207
+				'help_tabs' => array(
208
+					'transactions_view_transaction_help_tab'                                              => array(
209
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
210
+						'filename' => 'transactions_view_transaction',
211
+					),
212
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
213
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
214
+						'filename' => 'transactions_view_transaction_transaction_details_table',
215
+					),
216
+					'transactions_view_transaction_attendees_registered_help_tab'                         => array(
217
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
218
+						'filename' => 'transactions_view_transaction_attendees_registered',
219
+					),
220
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
221
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
222
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
223
+					),
224
+				),
225
+				'qtips'     => array('Transaction_Details_Tips'),
226
+				'help_tour' => array('Transaction_Details_Help_Tour'),
227
+				'metaboxes' => array('_transaction_details_metaboxes'),
228
+
229
+				'require_nonce' => false,
230
+			),
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * The below methods aren't used by this class currently
237
+	 */
238
+	protected function _add_screen_options()
239
+	{
240
+		//noop
241
+	}
242
+
243
+	protected function _add_feature_pointers()
244
+	{
245
+		//noop
246
+	}
247
+
248
+	public function admin_init()
249
+	{
250
+		// IF a registration was JUST added via the admin...
251
+		if (isset(
252
+			$this->_req_data['redirect_from'],
253
+			$this->_req_data['EVT_ID'],
254
+			$this->_req_data['event_name']
255
+		)) {
256
+			// then set a cookie so that we can block any attempts to use
257
+			// the back button as a way to enter another registration.
258
+			setcookie(
259
+				'ee_registration_added',
260
+				$this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'
261
+			);
262
+			// and update the global
263
+			$_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
264
+		}
265
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
266
+			'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.',
267
+			'event_espresso'
268
+		);
269
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
270
+			'An error occurred! Please refresh the page and try again.',
271
+			'event_espresso'
272
+		);
273
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
274
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
275
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
276
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
277
+			'This transaction has been overpaid ! Payments Total',
278
+			'event_espresso'
279
+		);
280
+	}
281
+
282
+	public function admin_notices()
283
+	{
284
+		//noop
285
+	}
286
+
287
+	public function admin_footer_scripts()
288
+	{
289
+		//noop
290
+	}
291
+
292
+
293
+	/**
294
+	 * _set_transaction_status_array
295
+	 * sets list of transaction statuses
296
+	 *
297
+	 * @access private
298
+	 * @return void
299
+	 * @throws EE_Error
300
+	 * @throws InvalidArgumentException
301
+	 * @throws InvalidDataTypeException
302
+	 * @throws InvalidInterfaceException
303
+	 */
304
+	private function _set_transaction_status_array()
305
+	{
306
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
307
+	}
308
+
309
+
310
+	/**
311
+	 * get_transaction_status_array
312
+	 * return the transaction status array for wp_list_table
313
+	 *
314
+	 * @access public
315
+	 * @return array
316
+	 */
317
+	public function get_transaction_status_array()
318
+	{
319
+		return self::$_txn_status;
320
+	}
321
+
322
+
323
+	/**
324
+	 *    get list of payment statuses
325
+	 *
326
+	 * @access private
327
+	 * @return void
328
+	 * @throws EE_Error
329
+	 * @throws InvalidArgumentException
330
+	 * @throws InvalidDataTypeException
331
+	 * @throws InvalidInterfaceException
332
+	 */
333
+	private function _get_payment_status_array()
334
+	{
335
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
336
+		$this->_template_args['payment_status'] = self::$_pay_status;
337
+
338
+	}
339
+
340
+
341
+	/**
342
+	 *    _add_screen_options_default
343
+	 *
344
+	 * @access protected
345
+	 * @return void
346
+	 * @throws InvalidArgumentException
347
+	 * @throws InvalidDataTypeException
348
+	 * @throws InvalidInterfaceException
349
+	 */
350
+	protected function _add_screen_options_default()
351
+	{
352
+		$this->_per_page_screen_option();
353
+	}
354
+
355
+
356
+	/**
357
+	 * load_scripts_styles
358
+	 *
359
+	 * @access public
360
+	 * @return void
361
+	 */
362
+	public function load_scripts_styles()
363
+	{
364
+		//enqueue style
365
+		wp_register_style(
366
+			'espresso_txn',
367
+			TXN_ASSETS_URL . 'espresso_transactions_admin.css',
368
+			array(),
369
+			EVENT_ESPRESSO_VERSION
370
+		);
371
+		wp_enqueue_style('espresso_txn');
372
+		//scripts
373
+		wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
374
+			'ee_admin_js',
375
+			'ee-datepicker',
376
+			'jquery-ui-datepicker',
377
+			'jquery-ui-draggable',
378
+			'ee-dialog',
379
+			'ee-accounting',
380
+			'ee-serialize-full-array',
381
+		), EVENT_ESPRESSO_VERSION, true);
382
+		wp_enqueue_script('espresso_txn');
383
+	}
384
+
385
+
386
+	/**
387
+	 *    load_scripts_styles_view_transaction
388
+	 *
389
+	 * @access public
390
+	 * @return void
391
+	 */
392
+	public function load_scripts_styles_view_transaction()
393
+	{
394
+		//styles
395
+		wp_enqueue_style('espresso-ui-theme');
396
+	}
397
+
398
+
399
+	/**
400
+	 *    load_scripts_styles_default
401
+	 *
402
+	 * @access public
403
+	 * @return void
404
+	 */
405
+	public function load_scripts_styles_default()
406
+	{
407
+		//styles
408
+		wp_enqueue_style('espresso-ui-theme');
409
+	}
410
+
411
+
412
+	/**
413
+	 *    _set_list_table_views_default
414
+	 *
415
+	 * @access protected
416
+	 * @return void
417
+	 */
418
+	protected function _set_list_table_views_default()
419
+	{
420
+		$this->_views = array(
421
+			'all'       => array(
422
+				'slug'  => 'all',
423
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
424
+				'count' => 0,
425
+			),
426
+			'abandoned' => array(
427
+				'slug'  => 'abandoned',
428
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
429
+				'count' => 0,
430
+			),
431
+			'failed'    => array(
432
+				'slug'  => 'failed',
433
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
434
+				'count' => 0,
435
+			),
436
+		);
437
+	}
438
+
439
+
440
+	/**
441
+	 * _set_transaction_object
442
+	 * This sets the _transaction property for the transaction details screen
443
+	 *
444
+	 * @access private
445
+	 * @return void
446
+	 * @throws EE_Error
447
+	 * @throws InvalidArgumentException
448
+	 * @throws RuntimeException
449
+	 * @throws InvalidDataTypeException
450
+	 * @throws InvalidInterfaceException
451
+	 */
452
+	private function _set_transaction_object()
453
+	{
454
+		if ($this->_transaction instanceof EE_Transaction) {
455
+			return;
456
+		} //get out we've already set the object
457
+
458
+		$TXN_ID = ! empty($this->_req_data['TXN_ID'])
459
+			? absint($this->_req_data['TXN_ID'])
460
+			: false;
461
+
462
+		//get transaction object
463
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
464
+		$this->_session     = $this->_transaction instanceof EE_Transaction
465
+			? $this->_transaction->get('TXN_session_data')
466
+			: null;
467
+		$this->_transaction->verify_abandoned_transaction_status();
468
+
469
+		if (! $this->_transaction instanceof EE_Transaction) {
470
+			$error_msg = sprintf(
471
+				esc_html__(
472
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
473
+					'event_espresso'
474
+				),
475
+				$TXN_ID
476
+			);
477
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
478
+		}
479
+	}
480
+
481
+
482
+	/**
483
+	 *    _transaction_legend_items
484
+	 *
485
+	 * @access protected
486
+	 * @return array
487
+	 * @throws EE_Error
488
+	 * @throws InvalidArgumentException
489
+	 * @throws ReflectionException
490
+	 * @throws InvalidDataTypeException
491
+	 * @throws InvalidInterfaceException
492
+	 */
493
+	protected function _transaction_legend_items()
494
+	{
495
+		EE_Registry::instance()->load_helper('MSG_Template');
496
+		$items = array();
497
+
498
+		if (EE_Registry::instance()->CAP->current_user_can(
499
+			'ee_read_global_messages',
500
+			'view_filtered_messages'
501
+		)) {
502
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
503
+			if (is_array($related_for_icon)
504
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
505
+			) {
506
+				$items['view_related_messages'] = array(
507
+					'class' => $related_for_icon['css_class'],
508
+					'desc'  => $related_for_icon['label'],
509
+				);
510
+			}
511
+		}
512
+
513
+		$items = apply_filters(
514
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
515
+			array_merge(
516
+				$items,
517
+				array(
518
+					'view_details'          => array(
519
+						'class' => 'dashicons dashicons-cart',
520
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
521
+					),
522
+					'view_invoice'          => array(
523
+						'class' => 'dashicons dashicons-media-spreadsheet',
524
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
525
+					),
526
+					'view_receipt'          => array(
527
+						'class' => 'dashicons dashicons-media-default',
528
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
529
+					),
530
+					'view_registration'     => array(
531
+						'class' => 'dashicons dashicons-clipboard',
532
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
533
+					),
534
+					'payment_overview_link' => array(
535
+						'class' => 'dashicons dashicons-money',
536
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
537
+					),
538
+				)
539
+			)
540
+		);
541
+
542
+		if (EE_Registry::instance()->CAP->current_user_can(
543
+			'ee_send_message',
544
+			'espresso_transactions_send_payment_reminder'
545
+		)) {
546
+			if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
547
+				$items['send_payment_reminder'] = array(
548
+					'class' => 'dashicons dashicons-email-alt',
549
+					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
550
+				);
551
+			} else {
552
+				$items['blank*'] = array(
553
+					'class' => '',
554
+					'desc'  => '',
555
+				);
556
+			}
557
+		} else {
558
+			$items['blank*'] = array(
559
+				'class' => '',
560
+				'desc'  => '',
561
+			);
562
+		}
563
+		$more_items = apply_filters(
564
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
565
+			array(
566
+				'overpaid'   => array(
567
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
568
+					'desc'  => EEH_Template::pretty_status(
569
+						EEM_Transaction::overpaid_status_code,
570
+						false,
571
+						'sentence'
572
+					),
573
+				),
574
+				'complete'   => array(
575
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
576
+					'desc'  => EEH_Template::pretty_status(
577
+						EEM_Transaction::complete_status_code,
578
+						false,
579
+						'sentence'
580
+					),
581
+				),
582
+				'incomplete' => array(
583
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
584
+					'desc'  => EEH_Template::pretty_status(
585
+						EEM_Transaction::incomplete_status_code,
586
+						false,
587
+						'sentence'
588
+					),
589
+				),
590
+				'abandoned'  => array(
591
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
592
+					'desc'  => EEH_Template::pretty_status(
593
+						EEM_Transaction::abandoned_status_code,
594
+						false,
595
+						'sentence'
596
+					),
597
+				),
598
+				'failed'     => array(
599
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
600
+					'desc'  => EEH_Template::pretty_status(
601
+						EEM_Transaction::failed_status_code,
602
+						false,
603
+						'sentence'
604
+					),
605
+				),
606
+			)
607
+		);
608
+
609
+		return array_merge($items, $more_items);
610
+	}
611
+
612
+
613
+	/**
614
+	 *    _transactions_overview_list_table
615
+	 *
616
+	 * @access protected
617
+	 * @return void
618
+	 * @throws DomainException
619
+	 * @throws EE_Error
620
+	 * @throws InvalidArgumentException
621
+	 * @throws InvalidDataTypeException
622
+	 * @throws InvalidInterfaceException
623
+	 * @throws ReflectionException
624
+	 */
625
+	protected function _transactions_overview_list_table()
626
+	{
627
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
628
+		$event = isset($this->_req_data['EVT_ID'])
629
+			? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
630
+			: null;
631
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
632
+			? sprintf(
633
+				esc_html__(
634
+					'%sViewing Transactions for the Event: %s%s',
635
+					'event_espresso'
636
+				),
637
+				'<h3>',
638
+				'<a href="'
639
+				. EE_Admin_Page::add_query_args_and_nonce(
640
+					array('action' => 'edit', 'post' => $event->ID()),
641
+					EVENTS_ADMIN_URL
642
+				)
643
+				. '" title="'
644
+				. esc_attr__(
645
+					'Click to Edit event',
646
+					'event_espresso'
647
+				)
648
+				. '">' . $event->get('EVT_name') . '</a>',
649
+				'</h3>'
650
+			)
651
+			: '';
652
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
653
+		$this->display_admin_list_table_page_with_no_sidebar();
654
+	}
655
+
656
+
657
+	/**
658
+	 *    _transaction_details
659
+	 * generates HTML for the View Transaction Details Admin page
660
+	 *
661
+	 * @access protected
662
+	 * @return void
663
+	 * @throws DomainException
664
+	 * @throws EE_Error
665
+	 * @throws InvalidArgumentException
666
+	 * @throws InvalidDataTypeException
667
+	 * @throws InvalidInterfaceException
668
+	 * @throws RuntimeException
669
+	 */
670
+	protected function _transaction_details()
671
+	{
672
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
673
+
674
+		$this->_set_transaction_status_array();
675
+
676
+		$this->_template_args                      = array();
677
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
678
+
679
+		$this->_set_transaction_object();
680
+
681
+		$primary_registration = $this->_transaction->primary_registration();
682
+		$attendee = $primary_registration instanceof EE_Registration
683
+			? $primary_registration->attendee()
684
+			: null;
685
+
686
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
687
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
688
+
689
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
690
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
691
+
692
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
693
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
694
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
695
+
696
+		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
697
+		$this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
698
+
699
+		if ($attendee instanceof EE_Attendee
700
+			&& EE_Registry::instance()->CAP->current_user_can(
701
+				'ee_send_message',
702
+				'espresso_transactions_send_payment_reminder'
703
+			)
704
+		) {
705
+			$this->_template_args['send_payment_reminder_button'] =
706
+				EEH_MSG_Template::is_mt_active('payment_reminder')
707
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
708
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
709
+					? EEH_Template::get_button_or_link(
710
+						EE_Admin_Page::add_query_args_and_nonce(
711
+							array(
712
+								'action'      => 'send_payment_reminder',
713
+								'TXN_ID'      => $this->_transaction->ID(),
714
+								'redirect_to' => 'view_transaction',
715
+							),
716
+							TXN_ADMIN_URL
717
+						),
718
+						__(' Send Payment Reminder', 'event_espresso'),
719
+						'button secondary-button right',
720
+						'dashicons dashicons-email-alt'
721
+					)
722
+					: '';
723
+		} else {
724
+			$this->_template_args['send_payment_reminder_button'] = '';
725
+		}
726
+
727
+		$amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
728
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
729
+			$amount_due,
730
+			true
731
+		);
732
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
733
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
734
+												  . $this->_template_args['amount_due'];
735
+		} else {
736
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
737
+		}
738
+		$this->_template_args['amount_due_class'] = '';
739
+
740
+		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
741
+			// paid in full
742
+			$this->_template_args['amount_due'] = false;
743
+		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
744
+			// overpaid
745
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
746
+		} elseif ($this->_transaction->get('TXN_total') > 0
747
+				  && $this->_transaction->get('TXN_paid') > 0
748
+		) {
749
+			// monies owing
750
+			$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
751
+		} elseif ($this->_transaction->get('TXN_total') > 0
752
+				  && $this->_transaction->get('TXN_paid') == 0
753
+		) {
754
+			// no payments made yet
755
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
756
+		} elseif ($this->_transaction->get('TXN_total') == 0) {
757
+			// free event
758
+			$this->_template_args['amount_due'] = false;
759
+		}
760
+
761
+		$payment_method = $this->_transaction->payment_method();
762
+
763
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
764
+			? $payment_method->admin_name()
765
+			: esc_html__('Unknown', 'event_espresso');
766
+
767
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
768
+		// link back to overview
769
+		$this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
770
+			? $_SERVER['HTTP_REFERER']
771
+			: TXN_ADMIN_URL;
772
+
773
+
774
+		// next link
775
+		$next_txn                                 = $this->_transaction->next(
776
+			null,
777
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
778
+			'TXN_ID'
779
+		);
780
+		$this->_template_args['next_transaction'] = $next_txn
781
+			? $this->_next_link(
782
+				EE_Admin_Page::add_query_args_and_nonce(
783
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
784
+					TXN_ADMIN_URL
785
+				),
786
+				'dashicons dashicons-arrow-right ee-icon-size-22'
787
+			)
788
+			: '';
789
+		// previous link
790
+		$previous_txn                                 = $this->_transaction->previous(
791
+			null,
792
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
793
+			'TXN_ID'
794
+		);
795
+		$this->_template_args['previous_transaction'] = $previous_txn
796
+			? $this->_previous_link(
797
+				EE_Admin_Page::add_query_args_and_nonce(
798
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
799
+					TXN_ADMIN_URL
800
+				),
801
+				'dashicons dashicons-arrow-left ee-icon-size-22'
802
+			)
803
+			: '';
804
+
805
+		// were we just redirected here after adding a new registration ???
806
+		if (isset(
807
+			$this->_req_data['redirect_from'],
808
+			$this->_req_data['EVT_ID'],
809
+			$this->_req_data['event_name']
810
+		)) {
811
+			if (EE_Registry::instance()->CAP->current_user_can(
812
+				'ee_edit_registrations',
813
+				'espresso_registrations_new_registration',
814
+				$this->_req_data['EVT_ID']
815
+			)) {
816
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
817
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
818
+					array(
819
+						'page'     => 'espresso_registrations',
820
+						'action'   => 'new_registration',
821
+						'return'   => 'default',
822
+						'TXN_ID'   => $this->_transaction->ID(),
823
+						'event_id' => $this->_req_data['EVT_ID'],
824
+					),
825
+					REG_ADMIN_URL
826
+				);
827
+				$this->_admin_page_title .= '">';
828
+
829
+				$this->_admin_page_title .= sprintf(
830
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
831
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
832
+				);
833
+				$this->_admin_page_title .= '</a>';
834
+			}
835
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
836
+		}
837
+		// grab messages at the last second
838
+		$this->_template_args['notices'] = EE_Error::get_notices();
839
+		// path to template
840
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
841
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
842
+			$template_path,
843
+			$this->_template_args,
844
+			true
845
+		);
846
+
847
+		// the details template wrapper
848
+		$this->display_admin_page_with_sidebar();
849
+
850
+	}
851
+
852
+
853
+	/**
854
+	 *        _transaction_details_metaboxes
855
+	 *
856
+	 * @access protected
857
+	 * @return void
858
+	 * @throws EE_Error
859
+	 * @throws InvalidArgumentException
860
+	 * @throws InvalidDataTypeException
861
+	 * @throws InvalidInterfaceException
862
+	 * @throws RuntimeException
863
+	 */
864
+	protected function _transaction_details_metaboxes()
865
+	{
866
+
867
+		$this->_set_transaction_object();
868
+
869
+		add_meta_box(
870
+			'edit-txn-details-mbox',
871
+			esc_html__('Transaction Details', 'event_espresso'),
872
+			array($this, 'txn_details_meta_box'),
873
+			$this->_wp_page_slug,
874
+			'normal',
875
+			'high'
876
+		);
877
+		add_meta_box(
878
+			'edit-txn-attendees-mbox',
879
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
880
+			array($this, 'txn_attendees_meta_box'),
881
+			$this->_wp_page_slug,
882
+			'normal',
883
+			'high',
884
+			array('TXN_ID' => $this->_transaction->ID())
885
+		);
886
+		add_meta_box(
887
+			'edit-txn-registrant-mbox',
888
+			esc_html__('Primary Contact', 'event_espresso'),
889
+			array($this, 'txn_registrant_side_meta_box'),
890
+			$this->_wp_page_slug,
891
+			'side',
892
+			'high'
893
+		);
894
+		add_meta_box(
895
+			'edit-txn-billing-info-mbox',
896
+			esc_html__('Billing Information', 'event_espresso'),
897
+			array($this, 'txn_billing_info_side_meta_box'),
898
+			$this->_wp_page_slug,
899
+			'side',
900
+			'high'
901
+		);
902
+	}
903
+
904
+
905
+	/**
906
+	 * txn_details_meta_box
907
+	 * generates HTML for the Transaction main meta box
908
+	 *
909
+	 * @access public
910
+	 * @return void
911
+	 * @throws DomainException
912
+	 * @throws EE_Error
913
+	 * @throws InvalidArgumentException
914
+	 * @throws InvalidDataTypeException
915
+	 * @throws InvalidInterfaceException
916
+	 * @throws RuntimeException
917
+	 */
918
+	public function txn_details_meta_box()
919
+	{
920
+
921
+		$this->_set_transaction_object();
922
+		$this->_template_args['TXN_ID']   = $this->_transaction->ID();
923
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
924
+			? $this->_transaction->primary_registration()->attendee()
925
+			: null;
926
+
927
+		//get line table
928
+		EEH_Autoloader::register_line_item_display_autoloaders();
929
+		$Line_Item_Display                       = new EE_Line_Item_Display(
930
+			'admin_table',
931
+			'EE_Admin_Table_Line_Item_Display_Strategy'
932
+		);
933
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
934
+			$this->_transaction->total_line_item()
935
+		);
936
+		$this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')
937
+																	  ->get('REG_code');
938
+
939
+		// process taxes
940
+		$taxes                         = $this->_transaction->get_many_related(
941
+			'Line_Item',
942
+			array(array('LIN_type' => EEM_Line_Item::type_tax))
943
+		);
944
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
945
+
946
+		$this->_template_args['grand_total']     = EEH_Template::format_currency(
947
+			$this->_transaction->get('TXN_total'),
948
+			false,
949
+			false
950
+		);
951
+		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
952
+		$this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
953
+
954
+		// process payment details
955
+		$payments = $this->_transaction->get_many_related('Payment');
956
+		if (! empty($payments)) {
957
+			$this->_template_args['payments']              = $payments;
958
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
959
+		} else {
960
+			$this->_template_args['payments']              = false;
961
+			$this->_template_args['existing_reg_payments'] = array();
962
+		}
963
+
964
+		$this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
965
+		$this->_template_args['delete_payment_url'] = add_query_arg(
966
+			array('action' => 'espresso_delete_payment'),
967
+			TXN_ADMIN_URL
968
+		);
969
+
970
+		if (isset($txn_details['invoice_number'])) {
971
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
972
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
973
+				'Invoice Number',
974
+				'event_espresso'
975
+			);
976
+		}
977
+
978
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
979
+			->get_first_related('Registration')
980
+			->get('REG_session');
981
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
982
+			'Registration Session',
983
+			'event_espresso'
984
+		);
985
+
986
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
987
+			? $this->_session['ip_address']
988
+			: '';
989
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
990
+			'Transaction placed from IP',
991
+			'event_espresso'
992
+		);
993
+
994
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
995
+			? $this->_session['user_agent']
996
+			: '';
997
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
998
+			'Registrant User Agent',
999
+			'event_espresso'
1000
+		);
1001
+
1002
+		$reg_steps = '<ul>';
1003
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1004
+			if ($reg_step_status === true) {
1005
+				$reg_steps .= '<li style="color:#70cc50">'
1006
+							  . sprintf(
1007
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1008
+								  ucwords(str_replace('_', ' ', $reg_step))
1009
+							  )
1010
+							  . '</li>';
1011
+			} elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1012
+				$reg_steps .= '<li style="color:#2EA2CC">'
1013
+							  . sprintf(
1014
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1015
+								  ucwords(str_replace('_', ' ', $reg_step)),
1016
+								  date(
1017
+									  get_option('date_format') . ' ' . get_option('time_format'),
1018
+									  ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1019
+								  )
1020
+							  )
1021
+							  . '</li>';
1022
+			} else {
1023
+				$reg_steps .= '<li style="color:#E76700">'
1024
+							  . sprintf(
1025
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1026
+								  ucwords(str_replace('_', ' ', $reg_step))
1027
+							  )
1028
+							  . '</li>';
1029
+			}
1030
+		}
1031
+		$reg_steps                                                 .= '</ul>';
1032
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1033
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1034
+			'Registration Step Progress',
1035
+			'event_espresso'
1036
+		);
1037
+
1038
+
1039
+		$this->_get_registrations_to_apply_payment_to();
1040
+		$this->_get_payment_methods($payments);
1041
+		$this->_get_payment_status_array();
1042
+		$this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1043
+
1044
+		$this->_template_args['transaction_form_url']    = add_query_arg(array(
1045
+			'action'  => 'edit_transaction',
1046
+			'process' => 'transaction',
1047
+		), TXN_ADMIN_URL);
1048
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1049
+			'page'   => 'espresso_transactions',
1050
+			'action' => 'espresso_apply_payment',
1051
+		), WP_AJAX_URL);
1052
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(array(
1053
+			'page'   => 'espresso_transactions',
1054
+			'action' => 'espresso_delete_payment',
1055
+		), WP_AJAX_URL);
1056
+
1057
+		// 'espresso_delete_payment_nonce'
1058
+
1059
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1060
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1061
+	}
1062
+
1063
+
1064
+	/**
1065
+	 * _get_registration_payment_IDs
1066
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1067
+	 *
1068
+	 * @access protected
1069
+	 * @param EE_Payment[] $payments
1070
+	 * @return array
1071
+	 * @throws EE_Error
1072
+	 * @throws InvalidArgumentException
1073
+	 * @throws InvalidDataTypeException
1074
+	 * @throws InvalidInterfaceException
1075
+	 */
1076
+	protected function _get_registration_payment_IDs($payments = array())
1077
+	{
1078
+		$existing_reg_payments = array();
1079
+		// get all reg payments for these payments
1080
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(array(
1081
+			array(
1082
+				'PAY_ID' => array(
1083
+					'IN',
1084
+					array_keys($payments),
1085
+				),
1086
+			),
1087
+		));
1088
+		if (! empty($reg_payments)) {
1089
+			foreach ($payments as $payment) {
1090
+				if (! $payment instanceof EE_Payment) {
1091
+					continue;
1092
+				} elseif (! isset($existing_reg_payments[$payment->ID()])) {
1093
+					$existing_reg_payments[$payment->ID()] = array();
1094
+				}
1095
+				foreach ($reg_payments as $reg_payment) {
1096
+					if ($reg_payment instanceof EE_Registration_Payment
1097
+						&& $reg_payment->payment_ID() === $payment->ID()
1098
+					) {
1099
+						$existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1100
+					}
1101
+				}
1102
+			}
1103
+		}
1104
+
1105
+		return $existing_reg_payments;
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * _get_registrations_to_apply_payment_to
1111
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1112
+	 * which allows the admin to only apply the payment to the specific registrations
1113
+	 *
1114
+	 * @access protected
1115
+	 * @return void
1116
+	 * @throws \EE_Error
1117
+	 */
1118
+	protected function _get_registrations_to_apply_payment_to()
1119
+	{
1120
+		// we want any registration with an active status (ie: not deleted or cancelled)
1121
+		$query_params                      = array(
1122
+			array(
1123
+				'STS_ID' => array(
1124
+					'IN',
1125
+					array(
1126
+						EEM_Registration::status_id_approved,
1127
+						EEM_Registration::status_id_pending_payment,
1128
+						EEM_Registration::status_id_not_approved,
1129
+					),
1130
+				),
1131
+			),
1132
+		);
1133
+		$registrations_to_apply_payment_to = EEH_HTML::br()
1134
+											 . EEH_HTML::div(
1135
+												 '',
1136
+												 'txn-admin-apply-payment-to-registrations-dv',
1137
+												 '',
1138
+												 'clear: both; margin: 1.5em 0 0; display: none;'
1139
+											 );
1140
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1141
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1142
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1143
+			EEH_HTML::tr(
1144
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1145
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1146
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1147
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1148
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1149
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1150
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1151
+			)
1152
+		);
1153
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1154
+		// get registrations for TXN
1155
+		$registrations = $this->_transaction->registrations($query_params);
1156
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1157
+		foreach ($registrations as $registration) {
1158
+			if ($registration instanceof EE_Registration) {
1159
+				$attendee_name                     = $registration->attendee() instanceof EE_Attendee
1160
+					? $registration->attendee()->full_name()
1161
+					: esc_html__('Unknown Attendee', 'event_espresso');
1162
+				$owing                             = $registration->final_price() - $registration->paid();
1163
+				$taxable                           = $registration->ticket()->taxable()
1164
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1165
+					: '';
1166
+				$checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1167
+					? ' checked="checked"'
1168
+					: '';
1169
+				$disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1170
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1171
+					EEH_HTML::td($registration->ID()) .
1172
+					EEH_HTML::td($attendee_name) .
1173
+					EEH_HTML::td(
1174
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1175
+					) .
1176
+					EEH_HTML::td($registration->event_name()) .
1177
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1178
+					EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1179
+					EEH_HTML::td(
1180
+						'<input type="checkbox" value="' . $registration->ID()
1181
+						. '" name="txn_admin_payment[registrations]"'
1182
+						. $checked . $disabled . '>',
1183
+						'',
1184
+						'jst-cntr'
1185
+					),
1186
+					'apply-payment-registration-row-' . $registration->ID()
1187
+				);
1188
+			}
1189
+		}
1190
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1191
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1192
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1193
+		$registrations_to_apply_payment_to                         .= EEH_HTML::p(
1194
+			esc_html__(
1195
+				'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.',
1196
+				'event_espresso'
1197
+			),
1198
+			'',
1199
+			'clear description'
1200
+		);
1201
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1202
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1203
+	}
1204
+
1205
+
1206
+	/**
1207
+	 * _get_reg_status_selection
1208
+	 *
1209
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1210
+	 *         instead of events.
1211
+	 * @access protected
1212
+	 * @return void
1213
+	 * @throws EE_Error
1214
+	 */
1215
+	protected function _get_reg_status_selection()
1216
+	{
1217
+		//first get all possible statuses
1218
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1219
+		//let's add a "don't change" option.
1220
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1221
+		$status_array                                        = array_merge($status_array, $statuses);
1222
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1223
+			'txn_reg_status_change[reg_status]',
1224
+			$status_array,
1225
+			'NAN',
1226
+			'id="txn-admin-payment-reg-status-inp"',
1227
+			'txn-reg-status-change-reg-status'
1228
+		);
1229
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1230
+			'delete_txn_reg_status_change[reg_status]',
1231
+			$status_array,
1232
+			'NAN',
1233
+			'delete-txn-admin-payment-reg-status-inp',
1234
+			'delete-txn-reg-status-change-reg-status'
1235
+		);
1236
+	}
1237
+
1238
+
1239
+	/**
1240
+	 *    _get_payment_methods
1241
+	 * Gets all the payment methods available generally, or the ones that are already
1242
+	 * selected on these payments (in case their payment methods are no longer active).
1243
+	 * Has the side-effect of updating the template args' payment_methods item
1244
+	 *
1245
+	 * @access private
1246
+	 * @param EE_Payment[] to show on this page
1247
+	 * @return void
1248
+	 * @throws EE_Error
1249
+	 * @throws InvalidArgumentException
1250
+	 * @throws InvalidDataTypeException
1251
+	 * @throws InvalidInterfaceException
1252
+	 */
1253
+	private function _get_payment_methods($payments = array())
1254
+	{
1255
+		$payment_methods_of_payments = array();
1256
+		foreach ($payments as $payment) {
1257
+			if ($payment instanceof EE_Payment) {
1258
+				$payment_methods_of_payments[] = $payment->get('PMD_ID');
1259
+			}
1260
+		}
1261
+		if ($payment_methods_of_payments) {
1262
+			$query_args = array(
1263
+				array(
1264
+					'OR*payment_method_for_payment' => array(
1265
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1266
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1267
+					),
1268
+				),
1269
+			);
1270
+		} else {
1271
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1272
+		}
1273
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * txn_attendees_meta_box
1279
+	 *    generates HTML for the Attendees Transaction main meta box
1280
+	 *
1281
+	 * @access public
1282
+	 * @param WP_Post $post
1283
+	 * @param array   $metabox
1284
+	 * @return void
1285
+	 * @throws DomainException
1286
+	 * @throws EE_Error
1287
+	 */
1288
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1289
+	{
1290
+
1291
+		/** @noinspection NonSecureExtractUsageInspection */
1292
+		extract($metabox['args']);
1293
+		$this->_template_args['post']            = $post;
1294
+		$this->_template_args['event_attendees'] = array();
1295
+		// process items in cart
1296
+		$line_items = $this->_transaction->get_many_related(
1297
+			'Line_Item',
1298
+			array(array('LIN_type' => 'line-item'))
1299
+		);
1300
+		if (! empty($line_items)) {
1301
+			foreach ($line_items as $item) {
1302
+				if ($item instanceof EE_Line_Item) {
1303
+					switch ($item->OBJ_type()) {
1304
+						case 'Event':
1305
+							break;
1306
+						case 'Ticket':
1307
+							$ticket = $item->ticket();
1308
+							//right now we're only handling tickets here.
1309
+							//Cause its expected that only tickets will have attendees right?
1310
+							if (! $ticket instanceof EE_Ticket) {
1311
+								continue;
1312
+							}
1313
+							try {
1314
+								$event_name = $ticket->get_event_name();
1315
+							} catch (Exception $e) {
1316
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1317
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1318
+							}
1319
+							$event_name   .= ' - ' . $item->get('LIN_name');
1320
+							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1321
+							// now get all of the registrations for this transaction that use this ticket
1322
+							$registrations = $ticket->get_many_related(
1323
+								'Registration',
1324
+								array(array('TXN_ID' => $this->_transaction->ID()))
1325
+							);
1326
+							foreach ($registrations as $registration) {
1327
+								if (! $registration instanceof EE_Registration) {
1328
+									continue;
1329
+								}
1330
+								$this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1331
+									= $registration->status_ID();
1332
+								$this->_template_args['event_attendees'][$registration->ID()]['att_num']
1333
+									= $registration->count();
1334
+								$this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1335
+									= $event_name;
1336
+								$this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1337
+									= $ticket_price;
1338
+								// attendee info
1339
+								$attendee = $registration->get_first_related('Attendee');
1340
+								if ($attendee instanceof EE_Attendee) {
1341
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']
1342
+										= $attendee->ID();
1343
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee']
1344
+										= $attendee->full_name();
1345
+									$this->_template_args['event_attendees'][$registration->ID()]['email']
1346
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1347
+										  . esc_html__(
1348
+											  ' Event',
1349
+											  'event_espresso'
1350
+										  )
1351
+										  . '">' . $attendee->email() . '</a>';
1352
+									$this->_template_args['event_attendees'][$registration->ID()]['address']
1353
+										= EEH_Address::format($attendee, 'inline', false, false);
1354
+								} else {
1355
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1356
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1357
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1358
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1359
+								}
1360
+							}
1361
+							break;
1362
+
1363
+					}
1364
+				}
1365
+			}
1366
+
1367
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1368
+				array(
1369
+					'action'  => 'edit_transaction',
1370
+					'process' => 'attendees',
1371
+				),
1372
+				TXN_ADMIN_URL
1373
+			);
1374
+			echo EEH_Template::display_template(
1375
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1376
+				$this->_template_args,
1377
+				true
1378
+			);
1379
+
1380
+		} else {
1381
+			echo sprintf(
1382
+				esc_html__(
1383
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1384
+					'event_espresso'
1385
+				),
1386
+				'<p class="important-notice">',
1387
+				'</p>'
1388
+			);
1389
+		}
1390
+	}
1391
+
1392
+
1393
+	/**
1394
+	 * txn_registrant_side_meta_box
1395
+	 * generates HTML for the Edit Transaction side meta box
1396
+	 *
1397
+	 * @access public
1398
+	 * @return void
1399
+	 * @throws DomainException
1400
+	 * @throws EE_Error
1401
+	 * @throws InvalidArgumentException
1402
+	 * @throws InvalidDataTypeException
1403
+	 * @throws InvalidInterfaceException
1404
+	 */
1405
+	public function txn_registrant_side_meta_box()
1406
+	{
1407
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1408
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1409
+			: null;
1410
+		if (! $primary_att instanceof EE_Attendee) {
1411
+			$this->_template_args['no_attendee_message'] = esc_html__(
1412
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1413
+				'event_espresso'
1414
+			);
1415
+			$primary_att                                 = EEM_Attendee::instance()->create_default_object();
1416
+		}
1417
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1418
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1419
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1420
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1421
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1422
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1423
+			'action' => 'edit_attendee',
1424
+			'post'   => $primary_att->ID(),
1425
+		), REG_ADMIN_URL);
1426
+		// get formatted address for registrant
1427
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1428
+		echo EEH_Template::display_template(
1429
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1430
+			$this->_template_args,
1431
+			true
1432
+		);
1433
+	}
1434
+
1435
+
1436
+	/**
1437
+	 * txn_billing_info_side_meta_box
1438
+	 *    generates HTML for the Edit Transaction side meta box
1439
+	 *
1440
+	 * @access public
1441
+	 * @return void
1442
+	 * @throws DomainException
1443
+	 * @throws EE_Error
1444
+	 */
1445
+	public function txn_billing_info_side_meta_box()
1446
+	{
1447
+
1448
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1449
+		$this->_template_args['billing_form_url'] = add_query_arg(
1450
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1451
+			TXN_ADMIN_URL
1452
+		);
1453
+
1454
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1455
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1456
+	}
1457
+
1458
+
1459
+	/**
1460
+	 * apply_payments_or_refunds
1461
+	 *    registers a payment or refund made towards a transaction
1462
+	 *
1463
+	 * @access public
1464
+	 * @return void
1465
+	 * @throws EE_Error
1466
+	 * @throws InvalidArgumentException
1467
+	 * @throws ReflectionException
1468
+	 * @throws RuntimeException
1469
+	 * @throws InvalidDataTypeException
1470
+	 * @throws InvalidInterfaceException
1471
+	 */
1472
+	public function apply_payments_or_refunds()
1473
+	{
1474
+		$json_response_data = array('return_data' => false);
1475
+		$valid_data         = $this->_validate_payment_request_data();
1476
+		$has_access = EE_Registry::instance()->CAP->current_user_can(
1477
+			'ee_edit_payments',
1478
+			'apply_payment_or_refund_from_registration_details'
1479
+		);
1480
+		if (! empty($valid_data) && $has_access) {
1481
+			$PAY_ID = $valid_data['PAY_ID'];
1482
+			//save  the new payment
1483
+			$payment = $this->_create_payment_from_request_data($valid_data);
1484
+			// get the TXN for this payment
1485
+			$transaction = $payment->transaction();
1486
+			// verify transaction
1487
+			if ($transaction instanceof EE_Transaction) {
1488
+				// calculate_total_payments_and_update_status
1489
+				$this->_process_transaction_payments($transaction);
1490
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1491
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1492
+				// apply payment to registrations (if applicable)
1493
+				if (! empty($REG_IDs)) {
1494
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1495
+					$this->_maybe_send_notifications();
1496
+					// now process status changes for the same registrations
1497
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1498
+				}
1499
+				$this->_maybe_send_notifications($payment);
1500
+				//prepare to render page
1501
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1502
+				do_action(
1503
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1504
+					$transaction,
1505
+					$payment
1506
+				);
1507
+			} else {
1508
+				EE_Error::add_error(
1509
+					esc_html__(
1510
+						'A valid Transaction for this payment could not be retrieved.',
1511
+						'event_espresso'
1512
+					),
1513
+					__FILE__,
1514
+					__FUNCTION__,
1515
+					__LINE__
1516
+				);
1517
+			}
1518
+		} else {
1519
+			if ($has_access) {
1520
+				EE_Error::add_error(
1521
+					esc_html__(
1522
+						'The payment form data could not be processed. Please try again.',
1523
+						'event_espresso'
1524
+					),
1525
+					__FILE__,
1526
+					__FUNCTION__,
1527
+					__LINE__
1528
+				);
1529
+			} else {
1530
+				EE_Error::add_error(
1531
+					esc_html__(
1532
+						'You do not have access to apply payments or refunds to a registration.',
1533
+						'event_espresso'
1534
+					),
1535
+					__FILE__,
1536
+					__FUNCTION__,
1537
+					__LINE__
1538
+				);
1539
+			}
1540
+		}
1541
+		$notices              = EE_Error::get_notices(
1542
+			false,
1543
+			false,
1544
+			false
1545
+		);
1546
+		$this->_template_args = array(
1547
+			'data'    => $json_response_data,
1548
+			'error'   => $notices['errors'],
1549
+			'success' => $notices['success'],
1550
+		);
1551
+		$this->_return_json();
1552
+	}
1553
+
1554
+
1555
+	/**
1556
+	 * _validate_payment_request_data
1557
+	 *
1558
+	 * @return array
1559
+	 */
1560
+	protected function _validate_payment_request_data()
1561
+	{
1562
+		if (! isset($this->_req_data['txn_admin_payment'])) {
1563
+			return false;
1564
+		}
1565
+		$payment_form = $this->_generate_payment_form_section();
1566
+		try {
1567
+			if ($payment_form->was_submitted()) {
1568
+				$payment_form->receive_form_submission();
1569
+				if (! $payment_form->is_valid()) {
1570
+					$submission_error_messages = array();
1571
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1572
+						if ($validation_error instanceof EE_Validation_Error) {
1573
+							$submission_error_messages[] = sprintf(
1574
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1575
+								$validation_error->get_form_section()->html_label_text(),
1576
+								$validation_error->getMessage()
1577
+							);
1578
+						}
1579
+					}
1580
+					EE_Error::add_error(
1581
+						implode('<br />', $submission_error_messages),
1582
+						__FILE__,
1583
+						__FUNCTION__,
1584
+						__LINE__
1585
+					);
1586
+
1587
+					return array();
1588
+				}
1589
+			}
1590
+		} catch (EE_Error $e) {
1591
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1592
+
1593
+			return array();
1594
+		}
1595
+
1596
+		return $payment_form->valid_data();
1597
+	}
1598
+
1599
+
1600
+	/**
1601
+	 * _generate_payment_form_section
1602
+	 *
1603
+	 * @return EE_Form_Section_Proper
1604
+	 */
1605
+	protected function _generate_payment_form_section()
1606
+	{
1607
+		return new EE_Form_Section_Proper(
1608
+			array(
1609
+				'name'        => 'txn_admin_payment',
1610
+				'subsections' => array(
1611
+					'PAY_ID'          => new EE_Text_Input(
1612
+						array(
1613
+							'default'               => 0,
1614
+							'required'              => false,
1615
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1616
+							'validation_strategies' => array(new EE_Int_Normalization()),
1617
+						)
1618
+					),
1619
+					'TXN_ID'          => new EE_Text_Input(
1620
+						array(
1621
+							'default'               => 0,
1622
+							'required'              => true,
1623
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1624
+							'validation_strategies' => array(new EE_Int_Normalization()),
1625
+						)
1626
+					),
1627
+					'type'            => new EE_Text_Input(
1628
+						array(
1629
+							'default'               => 1,
1630
+							'required'              => true,
1631
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1632
+							'validation_strategies' => array(new EE_Int_Normalization()),
1633
+						)
1634
+					),
1635
+					'amount'          => new EE_Text_Input(
1636
+						array(
1637
+							'default'               => 0,
1638
+							'required'              => true,
1639
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1640
+							'validation_strategies' => array(new EE_Float_Normalization()),
1641
+						)
1642
+					),
1643
+					'status'          => new EE_Text_Input(
1644
+						array(
1645
+							'default'         => EEM_Payment::status_id_approved,
1646
+							'required'        => true,
1647
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1648
+						)
1649
+					),
1650
+					'PMD_ID'          => new EE_Text_Input(
1651
+						array(
1652
+							'default'               => 2,
1653
+							'required'              => true,
1654
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1655
+							'validation_strategies' => array(new EE_Int_Normalization()),
1656
+						)
1657
+					),
1658
+					'date'            => new EE_Text_Input(
1659
+						array(
1660
+							'default'         => time(),
1661
+							'required'        => true,
1662
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1663
+						)
1664
+					),
1665
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1666
+						array(
1667
+							'default'               => '',
1668
+							'required'              => false,
1669
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1670
+							'validation_strategies' => array(
1671
+								new EE_Max_Length_Validation_Strategy(
1672
+									esc_html__('Input too long', 'event_espresso'),
1673
+									100
1674
+								),
1675
+							),
1676
+						)
1677
+					),
1678
+					'po_number'       => new EE_Text_Input(
1679
+						array(
1680
+							'default'               => '',
1681
+							'required'              => false,
1682
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1683
+							'validation_strategies' => array(
1684
+								new EE_Max_Length_Validation_Strategy(
1685
+									esc_html__('Input too long', 'event_espresso'),
1686
+									100
1687
+								),
1688
+							),
1689
+						)
1690
+					),
1691
+					'accounting'      => new EE_Text_Input(
1692
+						array(
1693
+							'default'               => '',
1694
+							'required'              => false,
1695
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1696
+							'validation_strategies' => array(
1697
+								new EE_Max_Length_Validation_Strategy(
1698
+									esc_html__('Input too long', 'event_espresso'),
1699
+									100
1700
+								),
1701
+							),
1702
+						)
1703
+					),
1704
+				),
1705
+			)
1706
+		);
1707
+	}
1708
+
1709
+
1710
+	/**
1711
+	 * _create_payment_from_request_data
1712
+	 *
1713
+	 * @param array $valid_data
1714
+	 * @return EE_Payment
1715
+	 * @throws EE_Error
1716
+	 */
1717
+	protected function _create_payment_from_request_data($valid_data)
1718
+	{
1719
+		$PAY_ID = $valid_data['PAY_ID'];
1720
+		// get payment amount
1721
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1722
+		// payments have a type value of 1 and refunds have a type value of -1
1723
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1724
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1725
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1726
+		$date    = $valid_data['date']
1727
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1728
+			: date('Y-m-d g:i a', current_time('timestamp'));
1729
+		$payment = EE_Payment::new_instance(
1730
+			array(
1731
+				'TXN_ID'              => $valid_data['TXN_ID'],
1732
+				'STS_ID'              => $valid_data['status'],
1733
+				'PAY_timestamp'       => $date,
1734
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1735
+				'PMD_ID'              => $valid_data['PMD_ID'],
1736
+				'PAY_amount'          => $amount,
1737
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1738
+				'PAY_po_number'       => $valid_data['po_number'],
1739
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1740
+				'PAY_details'         => $valid_data,
1741
+				'PAY_ID'              => $PAY_ID,
1742
+			),
1743
+			'',
1744
+			array('Y-m-d', 'g:i a')
1745
+		);
1746
+
1747
+		if (! $payment->save()) {
1748
+			EE_Error::add_error(
1749
+				sprintf(
1750
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1751
+					$payment->ID()
1752
+				),
1753
+				__FILE__, __FUNCTION__, __LINE__
1754
+			);
1755
+		}
1756
+
1757
+		return $payment;
1758
+	}
1759
+
1760
+
1761
+	/**
1762
+	 * _process_transaction_payments
1763
+	 *
1764
+	 * @param \EE_Transaction $transaction
1765
+	 * @return void
1766
+	 * @throws EE_Error
1767
+	 * @throws InvalidArgumentException
1768
+	 * @throws ReflectionException
1769
+	 * @throws InvalidDataTypeException
1770
+	 * @throws InvalidInterfaceException
1771
+	 */
1772
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1773
+	{
1774
+		/** @type EE_Transaction_Payments $transaction_payments */
1775
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1776
+		//update the transaction with this payment
1777
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1778
+			EE_Error::add_success(esc_html__(
1779
+				'The payment has been processed successfully.', 'event_espresso'),
1780
+				__FILE__,
1781
+				__FUNCTION__,
1782
+				__LINE__
1783
+			);
1784
+		} else {
1785
+			EE_Error::add_error(
1786
+				esc_html__(
1787
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1788
+					'event_espresso'
1789
+				)
1790
+				,
1791
+				__FILE__,
1792
+				__FUNCTION__,
1793
+				__LINE__
1794
+			);
1795
+		}
1796
+	}
1797
+
1798
+
1799
+	/**
1800
+	 * _get_REG_IDs_to_apply_payment_to
1801
+	 * returns a list of registration IDs that the payment will apply to
1802
+	 *
1803
+	 * @param \EE_Payment $payment
1804
+	 * @return array
1805
+	 * @throws EE_Error
1806
+	 */
1807
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1808
+	{
1809
+		$REG_IDs = array();
1810
+		// grab array of IDs for specific registrations to apply changes to
1811
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1812
+			$REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1813
+		}
1814
+		//nothing specified ? then get all reg IDs
1815
+		if (empty($REG_IDs)) {
1816
+			$registrations = $payment->transaction()->registrations();
1817
+			$REG_IDs       = ! empty($registrations)
1818
+				? array_keys($registrations)
1819
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1820
+		}
1821
+
1822
+		// ensure that REG_IDs are integers and NOT strings
1823
+		return array_map('intval', $REG_IDs);
1824
+	}
1825
+
1826
+
1827
+	/**
1828
+	 * @return array
1829
+	 */
1830
+	public function existing_reg_payment_REG_IDs()
1831
+	{
1832
+		return $this->_existing_reg_payment_REG_IDs;
1833
+	}
1834
+
1835
+
1836
+	/**
1837
+	 * @param array $existing_reg_payment_REG_IDs
1838
+	 */
1839
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1840
+	{
1841
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1842
+	}
1843
+
1844
+
1845
+	/**
1846
+	 * _get_existing_reg_payment_REG_IDs
1847
+	 * returns a list of registration IDs that the payment is currently related to
1848
+	 * as recorded in the database
1849
+	 *
1850
+	 * @param \EE_Payment $payment
1851
+	 * @return array
1852
+	 * @throws EE_Error
1853
+	 */
1854
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1855
+	{
1856
+		if ($this->existing_reg_payment_REG_IDs() === null) {
1857
+			// let's get any existing reg payment records for this payment
1858
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1859
+			// but we only want the REG IDs, so grab the array keys
1860
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1861
+				? array_keys($existing_reg_payment_REG_IDs)
1862
+				: array();
1863
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1864
+		}
1865
+
1866
+		return $this->existing_reg_payment_REG_IDs();
1867
+	}
1868
+
1869
+
1870
+	/**
1871
+	 * _remove_existing_registration_payments
1872
+	 * this calculates the difference between existing relations
1873
+	 * to the supplied payment and the new list registration IDs,
1874
+	 * removes any related registrations that no longer apply,
1875
+	 * and then updates the registration paid fields
1876
+	 *
1877
+	 * @param \EE_Payment $payment
1878
+	 * @param int         $PAY_ID
1879
+	 * @return bool;
1880
+	 * @throws EE_Error
1881
+	 * @throws InvalidArgumentException
1882
+	 * @throws ReflectionException
1883
+	 * @throws InvalidDataTypeException
1884
+	 * @throws InvalidInterfaceException
1885
+	 */
1886
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1887
+	{
1888
+		// newly created payments will have nothing recorded for $PAY_ID
1889
+		if ($PAY_ID == 0) {
1890
+			return false;
1891
+		}
1892
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1893
+		if (empty($existing_reg_payment_REG_IDs)) {
1894
+			return false;
1895
+		}
1896
+		/** @type EE_Transaction_Payments $transaction_payments */
1897
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1898
+
1899
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
1900
+			$payment,
1901
+			array(
1902
+				array(
1903
+					'PAY_ID' => $payment->ID(),
1904
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1905
+				),
1906
+			)
1907
+		);
1908
+	}
1909
+
1910
+
1911
+	/**
1912
+	 * _update_registration_payments
1913
+	 * this applies the payments to the selected registrations
1914
+	 * but only if they have not already been paid for
1915
+	 *
1916
+	 * @param  EE_Transaction $transaction
1917
+	 * @param \EE_Payment     $payment
1918
+	 * @param array           $REG_IDs
1919
+	 * @return void
1920
+	 * @throws EE_Error
1921
+	 * @throws InvalidArgumentException
1922
+	 * @throws ReflectionException
1923
+	 * @throws RuntimeException
1924
+	 * @throws InvalidDataTypeException
1925
+	 * @throws InvalidInterfaceException
1926
+	 */
1927
+	protected function _update_registration_payments(
1928
+		EE_Transaction $transaction,
1929
+		EE_Payment $payment,
1930
+		$REG_IDs = array()
1931
+	) {
1932
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1933
+		// so let's do that using our set of REG_IDs from the form
1934
+		$registration_query_where_params = array(
1935
+			'REG_ID' => array('IN', $REG_IDs),
1936
+		);
1937
+		// but add in some conditions regarding payment,
1938
+		// so that we don't apply payments to registrations that are free or have already been paid for
1939
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1940
+		if (! $payment->is_a_refund()) {
1941
+			$registration_query_where_params['REG_final_price']  = array('!=', 0);
1942
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1943
+		}
1944
+		$registrations = $transaction->registrations(array($registration_query_where_params));
1945
+		if (! empty($registrations)) {
1946
+			/** @type EE_Payment_Processor $payment_processor */
1947
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1948
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
1949
+		}
1950
+	}
1951
+
1952
+
1953
+	/**
1954
+	 * _process_registration_status_change
1955
+	 * This processes requested registration status changes for all the registrations
1956
+	 * on a given transaction and (optionally) sends out notifications for the changes.
1957
+	 *
1958
+	 * @param  EE_Transaction $transaction
1959
+	 * @param array           $REG_IDs
1960
+	 * @return bool
1961
+	 * @throws EE_Error
1962
+	 * @throws InvalidArgumentException
1963
+	 * @throws ReflectionException
1964
+	 * @throws InvalidDataTypeException
1965
+	 * @throws InvalidInterfaceException
1966
+	 */
1967
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1968
+	{
1969
+		// first if there is no change in status then we get out.
1970
+		if (
1971
+			! isset($this->_req_data['txn_reg_status_change']['reg_status'])
1972
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
1973
+		) {
1974
+			//no error message, no change requested, just nothing to do man.
1975
+			return false;
1976
+		}
1977
+		/** @type EE_Transaction_Processor $transaction_processor */
1978
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1979
+
1980
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1981
+		return $transaction_processor->manually_update_registration_statuses(
1982
+			$transaction,
1983
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1984
+			array(array('REG_ID' => array('IN', $REG_IDs)))
1985
+		);
1986
+	}
1987
+
1988
+
1989
+	/**
1990
+	 * _build_payment_json_response
1991
+	 *
1992
+	 * @access public
1993
+	 * @param \EE_Payment $payment
1994
+	 * @param array       $REG_IDs
1995
+	 * @param bool | null $delete_txn_reg_status_change
1996
+	 * @return array
1997
+	 * @throws EE_Error
1998
+	 * @throws InvalidArgumentException
1999
+	 * @throws InvalidDataTypeException
2000
+	 * @throws InvalidInterfaceException
2001
+	 */
2002
+	protected function _build_payment_json_response(
2003
+		EE_Payment $payment,
2004
+		$REG_IDs = array(),
2005
+		$delete_txn_reg_status_change = null
2006
+	) {
2007
+		// was the payment deleted ?
2008
+		if (is_bool($delete_txn_reg_status_change)) {
2009
+			return array(
2010
+				'PAY_ID'                       => $payment->ID(),
2011
+				'amount'                       => $payment->amount(),
2012
+				'total_paid'                   => $payment->transaction()->paid(),
2013
+				'txn_status'                   => $payment->transaction()->status_ID(),
2014
+				'pay_status'                   => $payment->STS_ID(),
2015
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2016
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2017
+			);
2018
+		} else {
2019
+			$this->_get_payment_status_array();
2020
+
2021
+			return array(
2022
+				'amount'           => $payment->amount(),
2023
+				'total_paid'       => $payment->transaction()->paid(),
2024
+				'txn_status'       => $payment->transaction()->status_ID(),
2025
+				'pay_status'       => $payment->STS_ID(),
2026
+				'PAY_ID'           => $payment->ID(),
2027
+				'STS_ID'           => $payment->STS_ID(),
2028
+				'status'           => self::$_pay_status[$payment->STS_ID()],
2029
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2030
+				'method'           => strtoupper($payment->source()),
2031
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2032
+				'gateway'          => $payment->payment_method()
2033
+					? $payment->payment_method()->admin_name()
2034
+					: esc_html__("Unknown", 'event_espresso'),
2035
+				'gateway_response' => $payment->gateway_response(),
2036
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2037
+				'po_number'        => $payment->po_number(),
2038
+				'extra_accntng'    => $payment->extra_accntng(),
2039
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2040
+			);
2041
+		}
2042
+	}
2043
+
2044
+
2045
+	/**
2046
+	 * delete_payment
2047
+	 *    delete a payment or refund made towards a transaction
2048
+	 *
2049
+	 * @access public
2050
+	 * @return void
2051
+	 * @throws EE_Error
2052
+	 * @throws InvalidArgumentException
2053
+	 * @throws ReflectionException
2054
+	 * @throws InvalidDataTypeException
2055
+	 * @throws InvalidInterfaceException
2056
+	 */
2057
+	public function delete_payment()
2058
+	{
2059
+		$json_response_data = array('return_data' => false);
2060
+		$PAY_ID             = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2061
+			? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2062
+			: 0;
2063
+		$can_delete = EE_Registry::instance()->CAP->current_user_can(
2064
+			'ee_delete_payments',
2065
+			'delete_payment_from_registration_details'
2066
+		);
2067
+		if ($PAY_ID && $can_delete) {
2068
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2069
+				? $this->_req_data['delete_txn_reg_status_change']
2070
+				: false;
2071
+			$payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2072
+			if ($payment instanceof EE_Payment) {
2073
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2074
+				/** @type EE_Transaction_Payments $transaction_payments */
2075
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2076
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2077
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2078
+						$payment,
2079
+						$REG_IDs,
2080
+						$delete_txn_reg_status_change
2081
+					);
2082
+					if ($delete_txn_reg_status_change) {
2083
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2084
+						//MAKE sure we also add the delete_txn_req_status_change to the
2085
+						//$_REQUEST global because that's how messages will be looking for it.
2086
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2087
+						$this->_maybe_send_notifications();
2088
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2089
+					}
2090
+				}
2091
+			} else {
2092
+				EE_Error::add_error(
2093
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2094
+					__FILE__, __FUNCTION__, __LINE__
2095
+				);
2096
+			}
2097
+		} else {
2098
+			if ($can_delete) {
2099
+				EE_Error::add_error(
2100
+					esc_html__(
2101
+						'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2102
+						'event_espresso'
2103
+					),
2104
+					__FILE__, __FUNCTION__, __LINE__
2105
+				);
2106
+			} else {
2107
+				EE_Error::add_error(
2108
+					esc_html__(
2109
+						'You do not have access to delete a payment.',
2110
+						'event_espresso'
2111
+					),
2112
+					__FILE__,
2113
+					__FUNCTION__,
2114
+					__LINE__
2115
+				);
2116
+			}
2117
+		}
2118
+		$notices              = EE_Error::get_notices(false, false, false);
2119
+		$this->_template_args = array(
2120
+			'data'      => $json_response_data,
2121
+			'success'   => $notices['success'],
2122
+			'error'     => $notices['errors'],
2123
+			'attention' => $notices['attention'],
2124
+		);
2125
+		$this->_return_json();
2126
+	}
2127
+
2128
+
2129
+	/**
2130
+	 * _registration_payment_data_array
2131
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2132
+	 *
2133
+	 * @access protected
2134
+	 * @param array $REG_IDs
2135
+	 * @return array
2136
+	 * @throws EE_Error
2137
+	 * @throws InvalidArgumentException
2138
+	 * @throws InvalidDataTypeException
2139
+	 * @throws InvalidInterfaceException
2140
+	 */
2141
+	protected function _registration_payment_data_array($REG_IDs)
2142
+	{
2143
+		$registration_payment_data = array();
2144
+		//if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2145
+		if (! empty($REG_IDs)) {
2146
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2147
+			foreach ($registrations as $registration) {
2148
+				if ($registration instanceof EE_Registration) {
2149
+					$registration_payment_data[$registration->ID()] = array(
2150
+						'paid'  => $registration->pretty_paid(),
2151
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2152
+					);
2153
+				}
2154
+			}
2155
+		}
2156
+
2157
+		return $registration_payment_data;
2158
+	}
2159
+
2160
+
2161
+	/**
2162
+	 * _maybe_send_notifications
2163
+	 * determines whether or not the admin has indicated that notifications should be sent.
2164
+	 * If so, will toggle a filter switch for delivering registration notices.
2165
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2166
+	 *
2167
+	 * @access protected
2168
+	 * @param \EE_Payment | null $payment
2169
+	 */
2170
+	protected function _maybe_send_notifications($payment = null)
2171
+	{
2172
+		switch ($payment instanceof EE_Payment) {
2173
+			// payment notifications
2174
+			case true :
2175
+				if (
2176
+					isset(
2177
+						$this->_req_data['txn_payments'],
2178
+						$this->_req_data['txn_payments']['send_notifications']
2179
+					) &&
2180
+					filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2181
+				) {
2182
+					$this->_process_payment_notification($payment);
2183
+				}
2184
+				break;
2185
+			// registration notifications
2186
+			case false :
2187
+				if (
2188
+					isset(
2189
+						$this->_req_data['txn_reg_status_change'],
2190
+						$this->_req_data['txn_reg_status_change']['send_notifications']
2191
+					) &&
2192
+					filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2193
+				) {
2194
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2195
+				}
2196
+				break;
2197
+		}
2198
+	}
2199
+
2200
+
2201
+	/**
2202
+	 * _send_payment_reminder
2203
+	 *    generates HTML for the View Transaction Details Admin page
2204
+	 *
2205
+	 * @access protected
2206
+	 * @return void
2207
+	 * @throws EE_Error
2208
+	 * @throws InvalidArgumentException
2209
+	 * @throws InvalidDataTypeException
2210
+	 * @throws InvalidInterfaceException
2211
+	 */
2212
+	protected function _send_payment_reminder()
2213
+	{
2214
+		$TXN_ID      = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2215
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2216
+		$query_args  = isset($this->_req_data['redirect_to']) ? array(
2217
+			'action' => $this->_req_data['redirect_to'],
2218
+			'TXN_ID' => $this->_req_data['TXN_ID'],
2219
+		) : array();
2220
+		do_action(
2221
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2222
+			$transaction
2223
+		);
2224
+		$this->_redirect_after_action(
2225
+			false,
2226
+			esc_html__('payment reminder', 'event_espresso'),
2227
+			esc_html__('sent', 'event_espresso'),
2228
+			$query_args,
2229
+			true
2230
+		);
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 *  get_transactions
2236
+	 *    get transactions for given parameters (used by list table)
2237
+	 *
2238
+	 * @param  int     $perpage how many transactions displayed per page
2239
+	 * @param  boolean $count   return the count or objects
2240
+	 * @param string   $view
2241
+	 * @return mixed int = count || array of transaction objects
2242
+	 * @throws EE_Error
2243
+	 * @throws InvalidArgumentException
2244
+	 * @throws InvalidDataTypeException
2245
+	 * @throws InvalidInterfaceException
2246
+	 */
2247
+	public function get_transactions($perpage, $count = false, $view = '')
2248
+	{
2249
+
2250
+		$TXN = EEM_Transaction::instance();
2251
+
2252
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
2253
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2254
+			: date(
2255
+				'm/d/Y',
2256
+				strtotime('-10 year')
2257
+			);
2258
+		$end_date   = isset($this->_req_data['txn-filter-end-date'])
2259
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2260
+			: date('m/d/Y');
2261
+
2262
+		//make sure our timestamps start and end right at the boundaries for each day
2263
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2264
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2265
+
2266
+
2267
+		//convert to timestamps
2268
+		$start_date = strtotime($start_date);
2269
+		$end_date   = strtotime($end_date);
2270
+
2271
+		//makes sure start date is the lowest value and vice versa
2272
+		$start_date = min($start_date, $end_date);
2273
+		$end_date   = max($start_date, $end_date);
2274
+
2275
+		//convert to correct format for query
2276
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2277
+			'TXN_timestamp',
2278
+			date('Y-m-d H:i:s', $start_date),
2279
+			'Y-m-d H:i:s'
2280
+		);
2281
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2282
+			'TXN_timestamp',
2283
+			date('Y-m-d H:i:s', $end_date),
2284
+			'Y-m-d H:i:s'
2285
+		);
2286
+
2287
+
2288
+		//set orderby
2289
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2290
+
2291
+		switch ($this->_req_data['orderby']) {
2292
+			case 'TXN_ID':
2293
+				$orderby = 'TXN_ID';
2294
+				break;
2295
+			case 'ATT_fname':
2296
+				$orderby = 'Registration.Attendee.ATT_fname';
2297
+				break;
2298
+			case 'event_name':
2299
+				$orderby = 'Registration.Event.EVT_name';
2300
+				break;
2301
+			default: //'TXN_timestamp'
2302
+				$orderby = 'TXN_timestamp';
2303
+		}
2304
+
2305
+		$sort         = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2306
+		$current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2307
+		$per_page     = ! empty($perpage) ? $perpage : 10;
2308
+		$per_page     = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2309
+
2310
+		$offset = ($current_page - 1) * $per_page;
2311
+		$limit  = array($offset, $per_page);
2312
+
2313
+		$_where = array(
2314
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2315
+			'Registration.REG_count' => 1,
2316
+		);
2317
+
2318
+		if (isset($this->_req_data['EVT_ID'])) {
2319
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2320
+		}
2321
+
2322
+		if (isset($this->_req_data['s'])) {
2323
+			$search_string = '%' . $this->_req_data['s'] . '%';
2324
+			$_where['OR']  = array(
2325
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2326
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2327
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2328
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2329
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2330
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2331
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2332
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2333
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2334
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2335
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2336
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
2337
+				'Registration.REG_code'               => array('LIKE', $search_string),
2338
+				'Registration.REG_count'              => array('LIKE', $search_string),
2339
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
2340
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2341
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2342
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
2343
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2344
+				'TXN_session_data'                    => array('LIKE', $search_string),
2345
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2346
+			);
2347
+		}
2348
+
2349
+		//failed transactions
2350
+		$failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2351
+					 || ($count && $view === 'failed');
2352
+		$abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2353
+					 || ($count && $view === 'abandoned');
2354
+
2355
+		if ($failed) {
2356
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2357
+		} else if ($abandoned) {
2358
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2359
+		} else {
2360
+			$_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
2361
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2362
+		}
2363
+
2364
+		$query_params = array(
2365
+			$_where,
2366
+			'order_by'                 => array($orderby => $sort),
2367
+			'limit'                    => $limit,
2368
+			'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2369
+		);
2370
+
2371
+		$transactions = $count
2372
+			? $TXN->count(array($_where), 'TXN_ID', true)
2373
+			: $TXN->get_all($query_params);
2374
+
2375
+		return $transactions;
2376
+	}
2377 2377
 }
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
             '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.',
267 267
             'event_espresso'
268 268
         );
269
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
269
+        EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
270 270
             'An error occurred! Please refresh the page and try again.',
271 271
             'event_espresso'
272 272
         );
@@ -364,13 +364,13 @@  discard block
 block discarded – undo
364 364
         //enqueue style
365 365
         wp_register_style(
366 366
             'espresso_txn',
367
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
367
+            TXN_ASSETS_URL.'espresso_transactions_admin.css',
368 368
             array(),
369 369
             EVENT_ESPRESSO_VERSION
370 370
         );
371 371
         wp_enqueue_style('espresso_txn');
372 372
         //scripts
373
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
373
+        wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array(
374 374
             'ee_admin_js',
375 375
             'ee-datepicker',
376 376
             'jquery-ui-datepicker',
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
             : null;
467 467
         $this->_transaction->verify_abandoned_transaction_status();
468 468
 
469
-        if (! $this->_transaction instanceof EE_Transaction) {
469
+        if ( ! $this->_transaction instanceof EE_Transaction) {
470 470
             $error_msg = sprintf(
471 471
                 esc_html__(
472 472
                     'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
             'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
565 565
             array(
566 566
                 'overpaid'   => array(
567
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
567
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code,
568 568
                     'desc'  => EEH_Template::pretty_status(
569 569
                         EEM_Transaction::overpaid_status_code,
570 570
                         false,
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
                     ),
573 573
                 ),
574 574
                 'complete'   => array(
575
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
575
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code,
576 576
                     'desc'  => EEH_Template::pretty_status(
577 577
                         EEM_Transaction::complete_status_code,
578 578
                         false,
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
                     ),
581 581
                 ),
582 582
                 'incomplete' => array(
583
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
583
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code,
584 584
                     'desc'  => EEH_Template::pretty_status(
585 585
                         EEM_Transaction::incomplete_status_code,
586 586
                         false,
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
                     ),
589 589
                 ),
590 590
                 'abandoned'  => array(
591
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
591
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code,
592 592
                     'desc'  => EEH_Template::pretty_status(
593 593
                         EEM_Transaction::abandoned_status_code,
594 594
                         false,
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
                     ),
597 597
                 ),
598 598
                 'failed'     => array(
599
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
599
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code,
600 600
                     'desc'  => EEH_Template::pretty_status(
601 601
                         EEM_Transaction::failed_status_code,
602 602
                         false,
@@ -645,11 +645,11 @@  discard block
 block discarded – undo
645 645
                     'Click to Edit event',
646 646
                     'event_espresso'
647 647
                 )
648
-                . '">' . $event->get('EVT_name') . '</a>',
648
+                . '">'.$event->get('EVT_name').'</a>',
649 649
                 '</h3>'
650 650
             )
651 651
             : '';
652
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
652
+        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
653 653
         $this->display_admin_list_table_page_with_no_sidebar();
654 654
     }
655 655
 
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 
692 692
         $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
693 693
         $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
694
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
694
+        $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID');
695 695
 
696 696
         $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
697 697
         $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 
773 773
 
774 774
         // next link
775
-        $next_txn                                 = $this->_transaction->next(
775
+        $next_txn = $this->_transaction->next(
776 776
             null,
777 777
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
778 778
             'TXN_ID'
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
             )
788 788
             : '';
789 789
         // previous link
790
-        $previous_txn                                 = $this->_transaction->previous(
790
+        $previous_txn = $this->_transaction->previous(
791 791
             null,
792 792
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
793 793
             'TXN_ID'
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
         // grab messages at the last second
838 838
         $this->_template_args['notices'] = EE_Error::get_notices();
839 839
         // path to template
840
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
840
+        $template_path                             = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php';
841 841
         $this->_template_args['admin_page_header'] = EEH_Template::display_template(
842 842
             $template_path,
843 843
             $this->_template_args,
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
 
927 927
         //get line table
928 928
         EEH_Autoloader::register_line_item_display_autoloaders();
929
-        $Line_Item_Display                       = new EE_Line_Item_Display(
929
+        $Line_Item_Display = new EE_Line_Item_Display(
930 930
             'admin_table',
931 931
             'EE_Admin_Table_Line_Item_Display_Strategy'
932 932
         );
@@ -937,13 +937,13 @@  discard block
 block discarded – undo
937 937
                                                                       ->get('REG_code');
938 938
 
939 939
         // process taxes
940
-        $taxes                         = $this->_transaction->get_many_related(
940
+        $taxes = $this->_transaction->get_many_related(
941 941
             'Line_Item',
942 942
             array(array('LIN_type' => EEM_Line_Item::type_tax))
943 943
         );
944 944
         $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
945 945
 
946
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
946
+        $this->_template_args['grand_total'] = EEH_Template::format_currency(
947 947
             $this->_transaction->get('TXN_total'),
948 948
             false,
949 949
             false
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
 
954 954
         // process payment details
955 955
         $payments = $this->_transaction->get_many_related('Payment');
956
-        if (! empty($payments)) {
956
+        if ( ! empty($payments)) {
957 957
             $this->_template_args['payments']              = $payments;
958 958
             $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
959 959
         } else {
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
                                   esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1015 1015
                                   ucwords(str_replace('_', ' ', $reg_step)),
1016 1016
                                   date(
1017
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1017
+                                      get_option('date_format').' '.get_option('time_format'),
1018 1018
                                       ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1019 1019
                                   )
1020 1020
                               )
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
                               . '</li>';
1029 1029
             }
1030 1030
         }
1031
-        $reg_steps                                                 .= '</ul>';
1031
+        $reg_steps .= '</ul>';
1032 1032
         $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1033 1033
         $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1034 1034
             'Registration Step Progress',
@@ -1041,11 +1041,11 @@  discard block
 block discarded – undo
1041 1041
         $this->_get_payment_status_array();
1042 1042
         $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1043 1043
 
1044
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
1044
+        $this->_template_args['transaction_form_url'] = add_query_arg(array(
1045 1045
             'action'  => 'edit_transaction',
1046 1046
             'process' => 'transaction',
1047 1047
         ), TXN_ADMIN_URL);
1048
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1048
+        $this->_template_args['apply_payment_form_url'] = add_query_arg(array(
1049 1049
             'page'   => 'espresso_transactions',
1050 1050
             'action' => 'espresso_apply_payment',
1051 1051
         ), WP_AJAX_URL);
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 
1057 1057
         // 'espresso_delete_payment_nonce'
1058 1058
 
1059
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1059
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php';
1060 1060
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1061 1061
     }
1062 1062
 
@@ -1085,11 +1085,11 @@  discard block
 block discarded – undo
1085 1085
                 ),
1086 1086
             ),
1087 1087
         ));
1088
-        if (! empty($reg_payments)) {
1088
+        if ( ! empty($reg_payments)) {
1089 1089
             foreach ($payments as $payment) {
1090
-                if (! $payment instanceof EE_Payment) {
1090
+                if ( ! $payment instanceof EE_Payment) {
1091 1091
                     continue;
1092
-                } elseif (! isset($existing_reg_payments[$payment->ID()])) {
1092
+                } elseif ( ! isset($existing_reg_payments[$payment->ID()])) {
1093 1093
                     $existing_reg_payments[$payment->ID()] = array();
1094 1094
                 }
1095 1095
                 foreach ($reg_payments as $reg_payment) {
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
     protected function _get_registrations_to_apply_payment_to()
1119 1119
     {
1120 1120
         // we want any registration with an active status (ie: not deleted or cancelled)
1121
-        $query_params                      = array(
1121
+        $query_params = array(
1122 1122
             array(
1123 1123
                 'STS_ID' => array(
1124 1124
                     'IN',
@@ -1137,16 +1137,16 @@  discard block
 block discarded – undo
1137 1137
                                                  '',
1138 1138
                                                  'clear: both; margin: 1.5em 0 0; display: none;'
1139 1139
                                              );
1140
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1140
+        $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1141 1141
         $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1142 1142
         $registrations_to_apply_payment_to .= EEH_HTML::thead(
1143 1143
             EEH_HTML::tr(
1144
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1145
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1146
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1147
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1148
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1149
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1144
+                EEH_HTML::th(esc_html__('ID', 'event_espresso')).
1145
+                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')).
1146
+                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')).
1147
+                EEH_HTML::th(esc_html__('Event', 'event_espresso')).
1148
+                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr').
1149
+                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr').
1150 1150
                 EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1151 1151
             )
1152 1152
         );
@@ -1161,29 +1161,29 @@  discard block
 block discarded – undo
1161 1161
                     : esc_html__('Unknown Attendee', 'event_espresso');
1162 1162
                 $owing                             = $registration->final_price() - $registration->paid();
1163 1163
                 $taxable                           = $registration->ticket()->taxable()
1164
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1164
+                    ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>'
1165 1165
                     : '';
1166 1166
                 $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1167 1167
                     ? ' checked="checked"'
1168 1168
                     : '';
1169
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1169
+                $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1170 1170
                 $registrations_to_apply_payment_to .= EEH_HTML::tr(
1171
-                    EEH_HTML::td($registration->ID()) .
1172
-                    EEH_HTML::td($attendee_name) .
1171
+                    EEH_HTML::td($registration->ID()).
1172
+                    EEH_HTML::td($attendee_name).
1173 1173
                     EEH_HTML::td(
1174
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1175
-                    ) .
1176
-                    EEH_HTML::td($registration->event_name()) .
1177
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1178
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1174
+                        $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable
1175
+                    ).
1176
+                    EEH_HTML::td($registration->event_name()).
1177
+                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr').
1178
+                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr').
1179 1179
                     EEH_HTML::td(
1180
-                        '<input type="checkbox" value="' . $registration->ID()
1180
+                        '<input type="checkbox" value="'.$registration->ID()
1181 1181
                         . '" name="txn_admin_payment[registrations]"'
1182
-                        . $checked . $disabled . '>',
1182
+                        . $checked.$disabled.'>',
1183 1183
                         '',
1184 1184
                         'jst-cntr'
1185 1185
                     ),
1186
-                    'apply-payment-registration-row-' . $registration->ID()
1186
+                    'apply-payment-registration-row-'.$registration->ID()
1187 1187
                 );
1188 1188
             }
1189 1189
         }
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
             '',
1199 1199
             'clear description'
1200 1200
         );
1201
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1201
+        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1202 1202
         $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1203 1203
     }
1204 1204
 
@@ -1263,12 +1263,12 @@  discard block
 block discarded – undo
1263 1263
                 array(
1264 1264
                     'OR*payment_method_for_payment' => array(
1265 1265
                         'PMD_ID'    => array('IN', $payment_methods_of_payments),
1266
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1266
+                        'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'),
1267 1267
                     ),
1268 1268
                 ),
1269 1269
             );
1270 1270
         } else {
1271
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1271
+            $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%')));
1272 1272
         }
1273 1273
         $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1274 1274
     }
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
             'Line_Item',
1298 1298
             array(array('LIN_type' => 'line-item'))
1299 1299
         );
1300
-        if (! empty($line_items)) {
1300
+        if ( ! empty($line_items)) {
1301 1301
             foreach ($line_items as $item) {
1302 1302
                 if ($item instanceof EE_Line_Item) {
1303 1303
                     switch ($item->OBJ_type()) {
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
                             $ticket = $item->ticket();
1308 1308
                             //right now we're only handling tickets here.
1309 1309
                             //Cause its expected that only tickets will have attendees right?
1310
-                            if (! $ticket instanceof EE_Ticket) {
1310
+                            if ( ! $ticket instanceof EE_Ticket) {
1311 1311
                                 continue;
1312 1312
                             }
1313 1313
                             try {
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
                                 EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1317 1317
                                 $event_name = esc_html__('Unknown Event', 'event_espresso');
1318 1318
                             }
1319
-                            $event_name   .= ' - ' . $item->get('LIN_name');
1319
+                            $event_name   .= ' - '.$item->get('LIN_name');
1320 1320
                             $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1321 1321
                             // now get all of the registrations for this transaction that use this ticket
1322 1322
                             $registrations = $ticket->get_many_related(
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
                                 array(array('TXN_ID' => $this->_transaction->ID()))
1325 1325
                             );
1326 1326
                             foreach ($registrations as $registration) {
1327
-                                if (! $registration instanceof EE_Registration) {
1327
+                                if ( ! $registration instanceof EE_Registration) {
1328 1328
                                     continue;
1329 1329
                                 }
1330 1330
                                 $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
@@ -1343,12 +1343,12 @@  discard block
 block discarded – undo
1343 1343
                                     $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1344 1344
                                         = $attendee->full_name();
1345 1345
                                     $this->_template_args['event_attendees'][$registration->ID()]['email']
1346
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1346
+                                        = '<a href="mailto:'.$attendee->email().'?subject='.$event_name
1347 1347
                                           . esc_html__(
1348 1348
                                               ' Event',
1349 1349
                                               'event_espresso'
1350 1350
                                           )
1351
-                                          . '">' . $attendee->email() . '</a>';
1351
+                                          . '">'.$attendee->email().'</a>';
1352 1352
                                     $this->_template_args['event_attendees'][$registration->ID()]['address']
1353 1353
                                         = EEH_Address::format($attendee, 'inline', false, false);
1354 1354
                                 } else {
@@ -1372,7 +1372,7 @@  discard block
 block discarded – undo
1372 1372
                 TXN_ADMIN_URL
1373 1373
             );
1374 1374
             echo EEH_Template::display_template(
1375
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1375
+                TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php',
1376 1376
                 $this->_template_args,
1377 1377
                 true
1378 1378
             );
@@ -1407,12 +1407,12 @@  discard block
 block discarded – undo
1407 1407
         $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1408 1408
             ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1409 1409
             : null;
1410
-        if (! $primary_att instanceof EE_Attendee) {
1410
+        if ( ! $primary_att instanceof EE_Attendee) {
1411 1411
             $this->_template_args['no_attendee_message'] = esc_html__(
1412 1412
                 'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1413 1413
                 'event_espresso'
1414 1414
             );
1415
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1415
+            $primary_att = EEM_Attendee::instance()->create_default_object();
1416 1416
         }
1417 1417
         $this->_template_args['ATT_ID']            = $primary_att->ID();
1418 1418
         $this->_template_args['prime_reg_fname']   = $primary_att->fname();
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
         // get formatted address for registrant
1427 1427
         $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1428 1428
         echo EEH_Template::display_template(
1429
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1429
+            TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php',
1430 1430
             $this->_template_args,
1431 1431
             true
1432 1432
         );
@@ -1451,8 +1451,8 @@  discard block
 block discarded – undo
1451 1451
             TXN_ADMIN_URL
1452 1452
         );
1453 1453
 
1454
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1455
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1454
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php';
1455
+        echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/
1456 1456
     }
1457 1457
 
1458 1458
 
@@ -1477,7 +1477,7 @@  discard block
 block discarded – undo
1477 1477
             'ee_edit_payments',
1478 1478
             'apply_payment_or_refund_from_registration_details'
1479 1479
         );
1480
-        if (! empty($valid_data) && $has_access) {
1480
+        if ( ! empty($valid_data) && $has_access) {
1481 1481
             $PAY_ID = $valid_data['PAY_ID'];
1482 1482
             //save  the new payment
1483 1483
             $payment = $this->_create_payment_from_request_data($valid_data);
@@ -1490,7 +1490,7 @@  discard block
 block discarded – undo
1490 1490
                 $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1491 1491
                 $this->_remove_existing_registration_payments($payment, $PAY_ID);
1492 1492
                 // apply payment to registrations (if applicable)
1493
-                if (! empty($REG_IDs)) {
1493
+                if ( ! empty($REG_IDs)) {
1494 1494
                     $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1495 1495
                     $this->_maybe_send_notifications();
1496 1496
                     // now process status changes for the same registrations
@@ -1538,7 +1538,7 @@  discard block
 block discarded – undo
1538 1538
                 );
1539 1539
             }
1540 1540
         }
1541
-        $notices              = EE_Error::get_notices(
1541
+        $notices = EE_Error::get_notices(
1542 1542
             false,
1543 1543
             false,
1544 1544
             false
@@ -1559,14 +1559,14 @@  discard block
 block discarded – undo
1559 1559
      */
1560 1560
     protected function _validate_payment_request_data()
1561 1561
     {
1562
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1562
+        if ( ! isset($this->_req_data['txn_admin_payment'])) {
1563 1563
             return false;
1564 1564
         }
1565 1565
         $payment_form = $this->_generate_payment_form_section();
1566 1566
         try {
1567 1567
             if ($payment_form->was_submitted()) {
1568 1568
                 $payment_form->receive_form_submission();
1569
-                if (! $payment_form->is_valid()) {
1569
+                if ( ! $payment_form->is_valid()) {
1570 1570
                     $submission_error_messages = array();
1571 1571
                     foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1572 1572
                         if ($validation_error instanceof EE_Validation_Error) {
@@ -1744,7 +1744,7 @@  discard block
 block discarded – undo
1744 1744
             array('Y-m-d', 'g:i a')
1745 1745
         );
1746 1746
 
1747
-        if (! $payment->save()) {
1747
+        if ( ! $payment->save()) {
1748 1748
             EE_Error::add_error(
1749 1749
                 sprintf(
1750 1750
                     esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
@@ -1809,7 +1809,7 @@  discard block
 block discarded – undo
1809 1809
         $REG_IDs = array();
1810 1810
         // grab array of IDs for specific registrations to apply changes to
1811 1811
         if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1812
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1812
+            $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1813 1813
         }
1814 1814
         //nothing specified ? then get all reg IDs
1815 1815
         if (empty($REG_IDs)) {
@@ -1937,12 +1937,12 @@  discard block
 block discarded – undo
1937 1937
         // but add in some conditions regarding payment,
1938 1938
         // so that we don't apply payments to registrations that are free or have already been paid for
1939 1939
         // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1940
-        if (! $payment->is_a_refund()) {
1940
+        if ( ! $payment->is_a_refund()) {
1941 1941
             $registration_query_where_params['REG_final_price']  = array('!=', 0);
1942 1942
             $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1943 1943
         }
1944 1944
         $registrations = $transaction->registrations(array($registration_query_where_params));
1945
-        if (! empty($registrations)) {
1945
+        if ( ! empty($registrations)) {
1946 1946
             /** @type EE_Payment_Processor $payment_processor */
1947 1947
             $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1948 1948
             $payment_processor->process_registration_payments($transaction, $payment, $registrations);
@@ -2142,7 +2142,7 @@  discard block
 block discarded – undo
2142 2142
     {
2143 2143
         $registration_payment_data = array();
2144 2144
         //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2145
-        if (! empty($REG_IDs)) {
2145
+        if ( ! empty($REG_IDs)) {
2146 2146
             $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2147 2147
             foreach ($registrations as $registration) {
2148 2148
                 if ($registration instanceof EE_Registration) {
@@ -2255,13 +2255,13 @@  discard block
 block discarded – undo
2255 2255
                 'm/d/Y',
2256 2256
                 strtotime('-10 year')
2257 2257
             );
2258
-        $end_date   = isset($this->_req_data['txn-filter-end-date'])
2258
+        $end_date = isset($this->_req_data['txn-filter-end-date'])
2259 2259
             ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2260 2260
             : date('m/d/Y');
2261 2261
 
2262 2262
         //make sure our timestamps start and end right at the boundaries for each day
2263
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2264
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2263
+        $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
2264
+        $end_date   = date('Y-m-d', strtotime($end_date)).' 23:59:59';
2265 2265
 
2266 2266
 
2267 2267
         //convert to timestamps
@@ -2278,7 +2278,7 @@  discard block
 block discarded – undo
2278 2278
             date('Y-m-d H:i:s', $start_date),
2279 2279
             'Y-m-d H:i:s'
2280 2280
         );
2281
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2281
+        $end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2282 2282
             'TXN_timestamp',
2283 2283
             date('Y-m-d H:i:s', $end_date),
2284 2284
             'Y-m-d H:i:s'
@@ -2320,7 +2320,7 @@  discard block
 block discarded – undo
2320 2320
         }
2321 2321
 
2322 2322
         if (isset($this->_req_data['s'])) {
2323
-            $search_string = '%' . $this->_req_data['s'] . '%';
2323
+            $search_string = '%'.$this->_req_data['s'].'%';
2324 2324
             $_where['OR']  = array(
2325 2325
                 'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2326 2326
                 'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
@@ -2347,9 +2347,9 @@  discard block
 block discarded – undo
2347 2347
         }
2348 2348
 
2349 2349
         //failed transactions
2350
-        $failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2350
+        $failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2351 2351
                      || ($count && $view === 'failed');
2352
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2352
+        $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2353 2353
                      || ($count && $view === 'abandoned');
2354 2354
 
2355 2355
         if ($failed) {
Please login to merge, or discard this patch.
templates/txn_admin_details_main_meta_box_txn_details.template.php 3 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     <a id="display-additional-transaction-session-info" class="display-the-hidden smaller-text"
13 13
        rel="additional-transaction-session-info">
14 14
         <span class="dashicons dashicons-plus-alt"></span><?php esc_html_e('view additional transaction session details',
15
-            'event_espresso'); ?>
15
+			'event_espresso'); ?>
16 16
     </a>
17 17
 
18 18
     <div id="additional-transaction-session-info-dv" class="hidden">
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
         <a id="hide-additional-transaction-session-info" class="hide-the-displayed hidden smaller-text"
21 21
            rel="additional-transaction-session-info">
22 22
             <span class="dashicons dashicons-dismiss"></span><?php esc_html_e('hide additional transaction session details',
23
-                'event_espresso'); ?>
23
+				'event_espresso'); ?>
24 24
         </a>
25 25
         <br class="clear"/>
26 26
 
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
 
46 46
 
47 47
     <?php if ($attendee instanceof EE_Attendee && ($grand_raw_total > 0 || $TXN_status != 'TCM' || ! empty($payments))) :
48
-        $no_payment_text = EE_Registry::instance()->CAP->current_user_can(
49
-            'ee_edit_payments',
50
-            'apply_payment_or_refund_from_registration_details'
51
-        )
52
-            ? esc_html__(
53
-                'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.',
54
-                'event_espresso'
55
-            )
56
-            : esc_html__(
57
-                'No payments have been applied to this transaction yet.',
58
-                'event_espresso'
59
-            );
60
-        ?>
48
+		$no_payment_text = EE_Registry::instance()->CAP->current_user_can(
49
+			'ee_edit_payments',
50
+			'apply_payment_or_refund_from_registration_details'
51
+		)
52
+			? esc_html__(
53
+				'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.',
54
+				'event_espresso'
55
+			)
56
+			: esc_html__(
57
+				'No payments have been applied to this transaction yet.',
58
+				'event_espresso'
59
+			);
60
+		?>
61 61
 
62 62
         <h3 class="admin-primary-mbox-h4 hdr-has-icon">
63 63
             <span class="ee-icon ee-icon-cash"></span><?php esc_html_e('Payment Details', 'event_espresso'); ?>
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
                 <?php if ($payments) : ?>
86 86
                     <?php $payment_total = 0; ?>
87 87
                     <?php foreach ($payments as $PAY_ID => $payment) :
88
-                        $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID])
89
-                            ? wp_json_encode($existing_reg_payments[$PAY_ID])
90
-                            : '{}';
91
-                        ?>
88
+						$existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID])
89
+							? wp_json_encode($existing_reg_payments[$PAY_ID])
90
+							: '{}';
91
+						?>
92 92
                         <tr id="txn-admin-payment-tr-<?php echo $PAY_ID; ?>">
93 93
                             <td>
94 94
                                 <span id="payment-status-<?php echo $PAY_ID; ?>"
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
                                 <ul class="txn-overview-actions-ul">
103 103
                                     <li>
104 104
                                         <?php if (EE_Registry::instance()->CAP->current_user_can(
105
-                                            'ee_edit_payments',
106
-                                            'apply_payment_or_refund_from_registration_details'
107
-                                        )) : ?>
105
+											'ee_edit_payments',
106
+											'apply_payment_or_refund_from_registration_details'
107
+										)) : ?>
108 108
                                         <a class="txn-admin-payment-action-edit-lnk"
109 109
                                            title="<?php esc_attr_e('Edit Payment', 'event_espresso'); ?>"
110 110
                                            data-payment-id="<?php echo $PAY_ID; ?>">
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
                                     </li>
115 115
                                     <li>
116 116
                                         <?php if (EE_Registry::instance()->CAP->current_user_can(
117
-                                            'ee_delete_payments',
118
-                                            'delete_payment_from_registration_details'
119
-                                        )) : ?>
117
+											'ee_delete_payments',
118
+											'delete_payment_from_registration_details'
119
+										)) : ?>
120 120
                                         <a class="txn-admin-payment-action-delete-lnk"
121 121
                                            title="<?php esc_attr_e('Delete Payment', 'event_espresso'); ?>"
122 122
                                            data-payment-id="<?php echo $PAY_ID; ?>">
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
                             <td class=" jst-left">
142 142
                                 <div id="payment-gateway-<?php echo $PAY_ID; ?>">
143 143
                                     <?php echo $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown",
144
-                                        'event_espresso'); ?>
144
+										'event_espresso'); ?>
145 145
                                 </div>
146 146
                                 <div id="payment-gateway-id-<?php echo $PAY_ID; ?>"
147 147
                                      class="hidden"><?php echo $payment->payment_method() ? $payment->payment_method()->ID() : 0; ?></div>
@@ -163,19 +163,19 @@  discard block
 block discarded – undo
163 163
                                 <span class="<?php echo $payment_class; ?>">
164 164
 							<div id="payment-amount-<?php echo $PAY_ID; ?>"
165 165
                                  style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(),
166
-                                    false, false); ?></div>
166
+									false, false); ?></div>
167 167
 						</span>
168 168
                             </td>
169 169
                         </tr>
170 170
                         <?php
171
-                        $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0;
172
-                        ?>
171
+						$payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0;
172
+						?>
173 173
                     <?php endforeach; // $payment?>
174 174
                     <?php
175
-                    $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : '';
176
-                    $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ',
177
-                            'event_espresso') . '</span>' : '';
178
-                    ?>
175
+					$pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : '';
176
+					$overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ',
177
+							'event_espresso') . '</span>' : '';
178
+					?>
179 179
                     <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden">
180 180
                         <td class=" jst-rght" colspan="11">
181 181
                             <span class="important-notice"><?php echo $no_payment_text; ?></span>
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
                         class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>">
186 186
                         <th class=" jst-rght" colspan="10"><span
187 187
                                     id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s',
188
-                                        'event_espresso'),
189
-                                        '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th>
188
+										'event_espresso'),
189
+										'(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th>
190 190
                         <th class=" jst-rght"><span
191 191
                                     id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total,
192
-                                    false, false); ?></span></th>
192
+									false, false); ?></span></th>
193 193
                     </tr>
194 194
                 <?php else : ?>
195 195
                     <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr">
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
                     <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden">
201 201
                         <th class=" jst-rght" colspan="10"><span
202 202
                                     id="payments-total-spn"><?php echo esc_html__('Payments Total',
203
-                                    'event_espresso'); ?></span></th>
203
+									'event_espresso'); ?></span></th>
204 204
                         <th class=" jst-rght"><span id="txn-admin-payment-total"></span></th>
205 205
                     </tr>
206 206
                 <?php endif; // $payments
207
-                ?>
207
+				?>
208 208
 
209 209
                 <tr id="txn-admin-payment-empty-row-tr" class="hidden">
210 210
                     <td>
@@ -269,10 +269,10 @@  discard block
 block discarded – undo
269 269
 
270 270
         <ul id="txn-admin-payment-options-ul">
271 271
             <?php if (EE_Registry::instance()->CAP->current_user_can(
272
-                'ee_edit_payments',
273
-                'apply_payment_or_refund_from_registration_details'
274
-            )) :
275
-                ?>
272
+				'ee_edit_payments',
273
+				'apply_payment_or_refund_from_registration_details'
274
+			)) :
275
+				?>
276 276
                 <li>
277 277
                     <a id="display-txn-admin-apply-payment" class="button-primary no-icon no-hide"
278 278
                        rel="txn-admin-apply-payment"> <!--display-the-hidden -->
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
             <?php else : ?>
289 289
                 <li>
290 290
                     <p><?php esc_html__('You do not have access to apply payments or refunds.',
291
-                            'event_espresso'); ?></p>
291
+							'event_espresso'); ?></p>
292 292
                 </li>
293 293
             <?php endif; ?>
294 294
         </ul>
@@ -306,23 +306,23 @@  discard block
 block discarded – undo
306 306
                 style="display:none;">
307 307
                 <div class="ee-icon ee-icon-cash-edit float-left"></div>
308 308
                 <?php
309
-                echo sprintf(
310
-                    __('Edit Payment #%s for Transaction #%s', 'event_espresso'),
311
-                    '<span></span>',
312
-                    $txn_nmbr['value']
313
-                );
314
-                ?>
309
+				echo sprintf(
310
+					__('Edit Payment #%s for Transaction #%s', 'event_espresso'),
311
+					'<span></span>',
312
+					$txn_nmbr['value']
313
+				);
314
+				?>
315 315
             </h2>
316 316
 
317 317
             <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;">
318 318
                 <div class="ee-icon ee-icon-cash-edit float-left"></div>
319 319
                 <?php
320
-                echo sprintf(
321
-                    __('Edit Refund #%s for Transaction #%s', 'event_espresso'),
322
-                    '<span></span>',
323
-                    $txn_nmbr['value']
324
-                );
325
-                ?>
320
+				echo sprintf(
321
+					__('Edit Refund #%s for Transaction #%s', 'event_espresso'),
322
+					'<span></span>',
323
+					$txn_nmbr['value']
324
+				);
325
+				?>
326 326
             </h2>
327 327
 
328 328
             <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon"
@@ -355,55 +355,55 @@  discard block
 block discarded – undo
355 355
 
356 356
                         <div class="txn-admin-apply-payment-date-dv admin-modal-dialog-row">
357 357
                             <div class="validation-notice-dv"><?php esc_html_e('The following is  a required field',
358
-                                    'event_espresso'); ?></div>
358
+									'event_espresso'); ?></div>
359 359
                             <label for="txn-admin-payment-date-inp" class=""><?php esc_html_e('Payment Date',
360
-                                    'event_espresso'); ?></label>
360
+									'event_espresso'); ?></label>
361 361
                             <input name="txn_admin_payment[date]" id="txn-admin-payment-date-inp"
362 362
                                    class="txn-admin-apply-payment-inp required" type="text"
363 363
                                    value="<?php echo date('Y-m-d g:i a', current_time('timestamp')); ?>"/>
364 364
                             <p class="description"><?php esc_html_e('The date the payment was actually made on',
365
-                                    'event_espresso'); ?></p>
365
+									'event_espresso'); ?></p>
366 366
                         </div>
367 367
 
368 368
                         <div class="txn-admin-apply-payment-amount-dv admin-modal-dialog-row">
369 369
                             <div class="validation-notice-dv"><?php esc_html_e('The following is  a required field',
370
-                                    'event_espresso'); ?></div>
370
+									'event_espresso'); ?></div>
371 371
                             <label for="txn-admin-payment-amount-inp" class=""><?php esc_html_e('Amount',
372
-                                    'event_espresso'); ?></label>
372
+									'event_espresso'); ?></label>
373 373
                             <input name="txn_admin_payment[amount]" id="txn-admin-payment-amount-inp"
374 374
                                    class="txn-admin-apply-payment-inp required" type="text" value=""/>
375 375
                             <p class="description"><?php esc_html_e('The amount of the payment',
376
-                                    'event_espresso'); ?></p>
376
+									'event_espresso'); ?></p>
377 377
                         </div>
378 378
 
379 379
                         <div class="txn-admin-apply-payment-method-dv admin-modal-dialog-row">
380 380
                             <div class="validation-notice-dv"><?php esc_html_e('The following is  a required field',
381
-                                    'event_espresso'); ?></div>
381
+									'event_espresso'); ?></div>
382 382
                             <label for="txn-admin-payment-method-inp" class=""><?php esc_html_e('Method of Payment',
383
-                                    'event_espresso'); ?></label>
383
+									'event_espresso'); ?></label>
384 384
                             <select name="txn_admin_payment[PMD_ID]" id="txn-admin-payment-method-slct"
385 385
                                     class="txn-admin-apply-payment-slct required" type="text">
386 386
                                 <?php foreach ($payment_methods as $method) : ?>
387 387
                                     <?php $selected = $method->slug() == 'cash' ? ' selected="selected"' : ''; ?>
388 388
                                     <option id="payment-method-opt-<?php echo $method->slug(); ?>"
389 389
                                             value="<?php echo $method->ID(); ?>"<?php echo $selected; ?>><?php echo sanitize_key($method->admin_desc()) ? substr($method->admin_desc(),
390
-                                            0, 128) : $method->admin_name(); ?>&nbsp;&nbsp;
390
+											0, 128) : $method->admin_name(); ?>&nbsp;&nbsp;
391 391
                                     </option>
392 392
                                 <?php endforeach; ?>
393 393
                             </select>
394 394
                             <p class="description"><?php esc_html_e('Whether the payment was made via PayPal, Credit Card, Cheque, or Cash',
395
-                                    'event_espresso'); ?></p>
395
+									'event_espresso'); ?></p>
396 396
                         </div>
397 397
 
398 398
                         <div class="mop-PP mop-CC mop-CHQ mop">
399 399
                             <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row">
400 400
                                 <label for="txn-admin-payment-txn-id-inp" class=""><?php esc_html_e('TXN ID / CHQ #',
401
-                                        'event_espresso'); ?></label>
401
+										'event_espresso'); ?></label>
402 402
                                 <input name="txn_admin_payment[txn_id_chq_nmbr]"
403 403
                                        id="txn-admin-payment-txn-id-chq-nmbr-inp" class="txn-admin-apply-payment-inp"
404 404
                                        type="text" maxlength="100"/>
405 405
                                 <p class="description"><?php esc_html_e('The Transaction ID sent back from the payment gateway, or the Cheque #',
406
-                                        'event_espresso'); ?></p>
406
+										'event_espresso'); ?></p>
407 407
                             </div>
408 408
                         </div>
409 409
 
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
                                        id="txn-admin-payment-gateway-response-inp" class="txn-admin-apply-payment-inp"
416 416
                                        type="text"/>
417 417
                                 <p class="description"><?php esc_html_e('The gateway response string (optional)',
418
-                                        'event_espresso'); ?></p>
418
+										'event_espresso'); ?></p>
419 419
                             </div>
420 420
                         </div>
421 421
 
422 422
                         <div class="mop-PP mop-CC mop">
423 423
                             <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row">
424 424
                                 <label for="txn-admin-payment-status-inp" class=""><?php esc_html_e('Payment Status',
425
-                                        'event_espresso'); ?></label>
425
+										'event_espresso'); ?></label>
426 426
                                 <select name="txn_admin_payment[status]" id="txn-admin-payment-status-slct"
427 427
                                         class="txn-admin-apply-payment-slct" type="text">
428 428
                                     <?php foreach ($payment_status as $STS_ID => $STS_code) : ?>
@@ -434,35 +434,35 @@  discard block
 block discarded – undo
434 434
                                     <?php endforeach; ?>
435 435
                                 </select>
436 436
                                 <p class="description"><?php esc_html_e('Whether the payment was approved, cancelled, declined or failed after submission to the gateway',
437
-                                        'event_espresso'); ?></p>
437
+										'event_espresso'); ?></p>
438 438
                             </div>
439 439
                         </div>
440 440
 
441 441
                         <div class="txn-admin-apply-payment-po-nmbr-dv admin-modal-dialog-row">
442 442
                             <label for="txn-admin-payment-po-nmbr-inp" class=""><?php esc_html_e('P.O. / S.O. #',
443
-                                    'event_espresso'); ?></label>
443
+									'event_espresso'); ?></label>
444 444
                             <input name="txn_admin_payment[po_number]" id="txn-admin-payment-po-nmbr-inp"
445 445
                                    class="txn-admin-apply-payment-inp" type="text" maxlength="100"/>
446 446
                             <p class="description"><?php esc_html_e('The Purchase or Sales Order Number if any (optional)',
447
-                                    'event_espresso'); ?></p>
447
+									'event_espresso'); ?></p>
448 448
                         </div>
449 449
 
450 450
                         <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row">
451 451
                             <label for="txn-admin-payment-accounting-inp"
452 452
                                    class="last"><?php esc_html_e('Notes / Extra Accounting',
453
-                                    'event_espresso'); ?></label>
453
+									'event_espresso'); ?></label>
454 454
                             <input name="txn_admin_payment[accounting]" id="txn-admin-payment-accounting-inp"
455 455
                                    class="txn-admin-apply-payment-inp" type="text" value="<?php echo $REG_code; ?>"
456 456
                                    maxlength="100"/> <input type="hidden" id="txn-admin-reg-code-inp"
457 457
                                                             value="<?php echo $REG_code; ?>"/>
458 458
                             <p class="description"><?php esc_html_e('An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.',
459
-                                    'event_espresso'); ?></p>
459
+									'event_espresso'); ?></p>
460 460
                         </div>
461 461
 
462 462
                         <div class="txn-admin-apply-payment-registrations-dv admin-modal-dialog-row">
463 463
                             <label for="txn-admin-payment-registrations-inp"
464 464
                                    class="last"><?php esc_html_e('Registrations to Apply Payment to:',
465
-                                    'event_espresso'); ?></label>
465
+									'event_espresso'); ?></label>
466 466
                             <label class="txn-admin-apply-payment-to-registrations-lbl">
467 467
                                 <input type="radio" value="1" id="txn-admin-apply-payment-to-all-registrations-inp"
468 468
                                        name="txn_admin_payment[apply_to_all_registrations]" checked="checked"/>
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
                         <div class="txn-admin-payment-reg-status-dv admin-modal-dialog-row">
480 480
                             <label for="txn-admin-payment-reg-status-inp"
481 481
                                    class="last"><?php esc_html_e('Change Registration Status?',
482
-                                    'event_espresso'); ?></label>
482
+									'event_espresso'); ?></label>
483 483
                             <?php echo $status_change_select; ?>
484 484
                             <p class="description"><?php esc_html_e('If you wish to change the status for the registrations selected above, then select which status from this dropdown.',
485
-                                    'event_espresso'); ?></p>
485
+									'event_espresso'); ?></p>
486 486
                             <br/>
487 487
                         </div>
488 488
 
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
                             </label>
503 503
                             <br class="clear-float"/>
504 504
                             <p class="description"><?php printf(esc_html__('By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.',
505
-                                    'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p>
505
+									'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p>
506 506
                             <label></label>
507 507
                         </div>
508 508
                         <div class="clear"></div>
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
                     </li>
543 543
                     <li>
544 544
                         <span id="ee-ajax-processing-text" style="display:none;"><?php esc_html_e('Processing...',
545
-                                'event_espresso'); ?></span>
545
+								'event_espresso'); ?></span>
546 546
                     </li>
547 547
                 </ul>
548 548
 
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
                 style="display:none;">
558 558
                 <span class="ee-icon ee-icon-cash-add"></span>
559 559
                 <?php echo esc_html__('Delete Payment/Refund for Transaction #',
560
-                        'event_espresso') . $txn_nmbr['value']; ?>
560
+						'event_espresso') . $txn_nmbr['value']; ?>
561 561
             </h2>
562 562
 
563 563
             <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm"
@@ -578,10 +578,10 @@  discard block
 block discarded – undo
578 578
                         <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row">
579 579
                             <label for="delete-txn-admin-payment-reg-status-inp"
580 580
                                    class="last"><?php esc_html_e('Change Registration Status?',
581
-                                    'event_espresso'); ?></label>
581
+									'event_espresso'); ?></label>
582 582
                             <?php echo $delete_status_change_select; ?>
583 583
                             <p class="description"><?php printf(esc_html__('If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s',
584
-                                    'event_espresso'), '<strong>', '</strong>'); ?></p>
584
+									'event_espresso'), '<strong>', '</strong>'); ?></p>
585 585
                         </div>
586 586
 
587 587
                         <div class="ee-attention txn-admin-apply-payment-accounting-dv admin-modal-dialog-row">
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
                                    class="last"><?php esc_html_e('Send Related Messages?', 'event_espresso'); ?></label>
590 590
                             <input type="checkbox" value="1" name="delete_txn_reg_status_change[send_notifications]">
591 591
                             <p class="description"><?php esc_html_e('If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.',
592
-                                    'event_espresso'); ?></p>
592
+									'event_espresso'); ?></p>
593 593
                         </div>
594 594
                         <div class="clear"></div>
595 595
 
@@ -621,13 +621,13 @@  discard block
 block discarded – undo
621 621
     <?php endif; // $grand_raw_total > 0?>
622 622
 
623 623
     <?php
624
-    if (WP_DEBUG) {
625
-        $delivered_messages = get_option('EED_Messages__payment', array());
626
-        if (isset($delivered_messages[$TXN_ID])) {
627
-            ?>
624
+	if (WP_DEBUG) {
625
+		$delivered_messages = get_option('EED_Messages__payment', array());
626
+		if (isset($delivered_messages[$TXN_ID])) {
627
+			?>
628 628
             <h4 class="admin-primary-mbox-h4 hdr-has-icon"><span
629 629
                         class="dashicons dashicons-email-alt"></span><?php esc_html_e('Messages Sent to Primary Registrant',
630
-                    'event_espresso'); ?></h4>
630
+					'event_espresso'); ?></h4>
631 631
 
632 632
             <div class="admin-primary-mbox-tbl-wrap">
633 633
                 <table class="admin-primary-mbox-tbl">
@@ -641,10 +641,10 @@  discard block
 block discarded – undo
641 641
                     </thead>
642 642
                     <tbody>
643 643
                     <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) :
644
-                        ?>
644
+						?>
645 645
                         <tr>
646 646
                             <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'),
647
-                                    ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td>
647
+									($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td>
648 648
                             <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td>
649 649
                             <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td>
650 650
                             <td class="jst-left"><?php echo isset($delivered_message['txn_status']) ? $delivered_message['txn_status'] : ''; ?></td>
@@ -654,9 +654,9 @@  discard block
 block discarded – undo
654 654
                 </table>
655 655
             </div>
656 656
             <?php
657
-        }
658
-    }
659
-    ?>
657
+		}
658
+	}
659
+	?>
660 660
 
661 661
 
662 662
 </div>
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                                 <div id="payment-accntng-<?php echo $PAY_ID; ?>"><?php echo $payment->extra_accntng(); ?></div>
160 160
                             </td>
161 161
                             <td class=" jst-rght">
162
-                                <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-' . $payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?>
162
+                                <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-'.$payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?>
163 163
                                 <span class="<?php echo $payment_class; ?>">
164 164
 							<div id="payment-amount-<?php echo $PAY_ID; ?>"
165 165
                                  style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(),
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
                     <?php endforeach; // $payment?>
174 174
                     <?php
175 175
                     $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : '';
176
-                    $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ',
177
-                            'event_espresso') . '</span>' : '';
176
+                    $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">'.esc_html__('This transaction has been overpaid ! ',
177
+                            'event_espresso').'</span>' : '';
178 178
                     ?>
179 179
                     <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden">
180 180
                         <td class=" jst-rght" colspan="11">
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
                     <tr id="txn-admin-payments-total-tr"
185 185
                         class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>">
186 186
                         <th class=" jst-rght" colspan="10"><span
187
-                                    id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s',
187
+                                    id="payments-total-spn"><?php echo $overpaid.sprintf(esc_html__('Payments Total %s',
188 188
                                         'event_espresso'),
189
-                                        '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th>
189
+                                        '('.EE_Registry::instance()->CFG->currency->code.')'); ?></span></th>
190 190
                         <th class=" jst-rght"><span
191 191
                                     id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total,
192 192
                                     false, false); ?></span></th>
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             <h2 id="admin-modal-dialog-apply-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon"
300 300
                 style="display:none;">
301 301
                 <div class="ee-icon ee-icon-cash-add float-left"></div>
302
-                <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?>
302
+                <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso').$txn_nmbr['value']; ?>
303 303
             </h2>
304 304
 
305 305
             <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon"
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
             <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon"
329 329
                 style="display:none;">
330 330
                 <div class="ee-icon ee-icon-cash-remove float-left"></div>
331
-                <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?>
331
+                <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso').$txn_nmbr['value']; ?>
332 332
             </h2>
333 333
 
334 334
             <form name="txn-admin-apply-payment-frm" id="txn-admin-apply-payment-frm"
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
                 style="display:none;">
558 558
                 <span class="ee-icon ee-icon-cash-add"></span>
559 559
                 <?php echo esc_html__('Delete Payment/Refund for Transaction #',
560
-                        'event_espresso') . $txn_nmbr['value']; ?>
560
+                        'event_espresso').$txn_nmbr['value']; ?>
561 561
             </h2>
562 562
 
563 563
             <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm"
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
                     <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) :
644 644
                         ?>
645 645
                         <tr>
646
-                            <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'),
646
+                            <td class="jst-left"><?php echo date(get_option('date_format').' '.get_option('time_format'),
647 647
                                     ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td>
648 648
                             <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td>
649 649
                             <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td>
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -191,10 +191,13 @@  discard block
 block discarded – undo
191 191
                                     id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total,
192 192
                                     false, false); ?></span></th>
193 193
                     </tr>
194
-                <?php else : ?>
194
+                <?php else {
195
+	: ?>
195 196
                     <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr">
196 197
                         <td class=" jst-rght" colspan="11">
197
-                            <span class="important-notice"><?php echo $no_payment_text; ?></span>
198
+                            <span class="important-notice"><?php echo $no_payment_text;
199
+}
200
+?></span>
198 201
                         </td>
199 202
                     </tr>
200 203
                     <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden">
@@ -285,10 +288,13 @@  discard block
 block discarded – undo
285 288
                         <?php esc_html_e('Apply Refund', 'event_espresso'); ?>
286 289
                     </a>
287 290
                 </li>
288
-            <?php else : ?>
291
+            <?php else {
292
+	: ?>
289 293
                 <li>
290 294
                     <p><?php esc_html__('You do not have access to apply payments or refunds.',
291
-                            'event_espresso'); ?></p>
295
+                            'event_espresso');
296
+}
297
+?></p>
292 298
                 </li>
293 299
             <?php endif; ?>
294 300
         </ul>
Please login to merge, or discard this patch.