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