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