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