Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
core/libraries/plugin_api/EE_Register_Module.lib.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         }
49 49
 
50 50
         // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
51
+        if (isset(self::$_settings[$identifier])) {
52 52
             return;
53 53
         }
54 54
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             );
68 68
         }
69 69
         // setup $_settings array from incoming values.
70
-        self::$_settings[ $identifier ] = [
70
+        self::$_settings[$identifier] = [
71 71
             // array of full server paths to any EED_Modules used by the module
72 72
             'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
73 73
         ];
@@ -105,6 +105,6 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public static function deregister($identifier = '')
107 107
     {
108
-        unset(self::$_settings[ $identifier ]);
108
+        unset(self::$_settings[$identifier]);
109 109
     }
110 110
 }
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -14,96 +14,96 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Register_Module implements EEI_Plugin_API
16 16
 {
17
-    /**
18
-     * Holds values for registered modules
19
-     *
20
-     * @var array
21
-     */
22
-    protected static $_settings = [];
17
+	/**
18
+	 * Holds values for registered modules
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected static $_settings = [];
23 23
 
24 24
 
25
-    /**
26
-     *    Method for registering new EED_Modules
27
-     *
28
-     * @param string $identifier a unique identifier for this set of modules Required.
29
-     * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
30
-     *                           EED_Module files themselves Required.
31
-     * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
32
-     *                           EED_Module files themselves
33
-     * @return void
34
-     * @throws EE_Error
35
-     * @since    4.3.0
36
-     */
37
-    public static function register($identifier = '', array $setup_args = [])
38
-    {
39
-        // required fields MUST be present, so let's make sure they are.
40
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
41
-            throw new EE_Error(
42
-                esc_html__(
43
-                    'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
44
-                    'event_espresso'
45
-                )
46
-            );
47
-        }
25
+	/**
26
+	 *    Method for registering new EED_Modules
27
+	 *
28
+	 * @param string $identifier a unique identifier for this set of modules Required.
29
+	 * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
30
+	 *                           EED_Module files themselves Required.
31
+	 * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
32
+	 *                           EED_Module files themselves
33
+	 * @return void
34
+	 * @throws EE_Error
35
+	 * @since    4.3.0
36
+	 */
37
+	public static function register($identifier = '', array $setup_args = [])
38
+	{
39
+		// required fields MUST be present, so let's make sure they are.
40
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
41
+			throw new EE_Error(
42
+				esc_html__(
43
+					'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
44
+					'event_espresso'
45
+				)
46
+			);
47
+		}
48 48
 
49
-        // make sure we don't register twice
50
-        if (isset(self::$_settings[ $identifier ])) {
51
-            return;
52
-        }
49
+		// make sure we don't register twice
50
+		if (isset(self::$_settings[ $identifier ])) {
51
+			return;
52
+		}
53 53
 
54
-        // make sure this was called in the right place!
55
-        if (
56
-            ! did_action('AHEE__EE_System__load_espresso_addons')
57
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58
-        ) {
59
-            EE_Error::doing_it_wrong(
60
-                __METHOD__,
61
-                esc_html__(
62
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
63
-                    'event_espresso'
64
-                ),
65
-                '4.3.0'
66
-            );
67
-        }
68
-        // setup $_settings array from incoming values.
69
-        self::$_settings[ $identifier ] = [
70
-            // array of full server paths to any EED_Modules used by the module
71
-            'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72
-        ];
73
-        // add to list of modules to be registered
74
-        add_filter(
75
-            'FHEE__EE_Config__register_modules__modules_to_register',
76
-            ['EE_Register_Module', 'add_modules']
77
-        );
78
-    }
54
+		// make sure this was called in the right place!
55
+		if (
56
+			! did_action('AHEE__EE_System__load_espresso_addons')
57
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58
+		) {
59
+			EE_Error::doing_it_wrong(
60
+				__METHOD__,
61
+				esc_html__(
62
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
63
+					'event_espresso'
64
+				),
65
+				'4.3.0'
66
+			);
67
+		}
68
+		// setup $_settings array from incoming values.
69
+		self::$_settings[ $identifier ] = [
70
+			// array of full server paths to any EED_Modules used by the module
71
+			'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72
+		];
73
+		// add to list of modules to be registered
74
+		add_filter(
75
+			'FHEE__EE_Config__register_modules__modules_to_register',
76
+			['EE_Register_Module', 'add_modules']
77
+		);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * Filters the list of modules to add ours.
83
-     * and they're just full filepaths to FOLDERS containing a module class file. Eg.
84
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
85
-     *
86
-     * @param array $modules_to_register array of paths to all modules that require registering
87
-     * @return array
88
-     */
89
-    public static function add_modules(array $modules_to_register)
90
-    {
91
-        foreach (self::$_settings as $settings) {
92
-            $modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
93
-        }
94
-        return $modules_to_register;
95
-    }
81
+	/**
82
+	 * Filters the list of modules to add ours.
83
+	 * and they're just full filepaths to FOLDERS containing a module class file. Eg.
84
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
85
+	 *
86
+	 * @param array $modules_to_register array of paths to all modules that require registering
87
+	 * @return array
88
+	 */
89
+	public static function add_modules(array $modules_to_register)
90
+	{
91
+		foreach (self::$_settings as $settings) {
92
+			$modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
93
+		}
94
+		return $modules_to_register;
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * This deregisters a module that was previously registered with a specific $identifier.
100
-     *
101
-     * @param string $identifier the name for the module that was previously registered
102
-     * @return void
103
-     * @since    4.3.0
104
-     */
105
-    public static function deregister($identifier = '')
106
-    {
107
-        unset(self::$_settings[ $identifier ]);
108
-    }
98
+	/**
99
+	 * This deregisters a module that was previously registered with a specific $identifier.
100
+	 *
101
+	 * @param string $identifier the name for the module that was previously registered
102
+	 * @return void
103
+	 * @since    4.3.0
104
+	 */
105
+	public static function deregister($identifier = '')
106
+	{
107
+		unset(self::$_settings[ $identifier ]);
108
+	}
109 109
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model.lib.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         }
59 59
 
60 60
         // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
61
+        if (isset(self::$_model_registry[$identifier])) {
62 62
             return;
63 63
         }
64 64
 
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
                 '4.5'
80 80
             );
81 81
         }
82
-        self::$_model_registry[ $identifier ] = $setup_args;
82
+        self::$_model_registry[$identifier] = $setup_args;
83 83
 
84 84
         if (
85 85
             (isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
86
+            || ( ! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87 87
         ) {
88 88
             throw new EE_Error(
89 89
                 sprintf(
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         }
98 98
         if (isset($setup_args['model_paths'])) {
99 99
             // make sure they passed in an array
100
-            if (! is_array($setup_args['model_paths'])) {
100
+            if ( ! is_array($setup_args['model_paths'])) {
101 101
                 $setup_args['model_paths'] = [$setup_args['model_paths']];
102 102
             }
103 103
             // we want to add this as a model folder
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
107 107
             $model_name_to_classname_map = [];
108 108
             foreach (array_keys($class_to_filepath_map) as $classname) {
109
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
109
+                $model_name_to_classname_map[str_replace("EEM_", "", $classname)] = $classname;
110 110
             }
111
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
111
+            self::$_model_name_to_classname_map[$identifier] = $model_name_to_classname_map;
112 112
             add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113 113
             add_filter(
114 114
                 'FHEE__EE_System__parse_implemented_model_names',
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         }
120 120
         if (isset($setup_args['class_paths'])) {
121 121
             // make sure they passed in an array
122
-            if (! is_array($setup_args['class_paths'])) {
122
+            if ( ! is_array($setup_args['class_paths'])) {
123 123
                 $setup_args['class_paths'] = [$setup_args['class_paths']];
124 124
             }
125 125
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
@@ -192,6 +192,6 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public static function deregister($identifier = '')
194 194
     {
195
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
195
+        unset(self::$_model_registry[$identifier], self::$_model_name_to_classname_map[$identifier]);
196 196
     }
197 197
 }
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -11,187 +11,187 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Register_Model implements EEI_Plugin_API
13 13
 {
14
-    /**
15
-     *
16
-     * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
-     *      like EE_Register_Model::register()'s 2nd arg
18
-     */
19
-    protected static $_model_registry;
14
+	/**
15
+	 *
16
+	 * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
+	 *      like EE_Register_Model::register()'s 2nd arg
18
+	 */
19
+	protected static $_model_registry;
20 20
 
21
-    /**
22
-     *
23
-     * @var array keys are model names, values are their class names. Stored on registration and used
24
-     * on a hook
25
-     */
26
-    protected static $_model_name_to_classname_map;
21
+	/**
22
+	 *
23
+	 * @var array keys are model names, values are their class names. Stored on registration and used
24
+	 * on a hook
25
+	 */
26
+	protected static $_model_name_to_classname_map;
27 27
 
28 28
 
29
-    /**
30
-     * @param string $identifier  unique id for it
31
-     * @param array  $setup_args  {
32
-     * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
-     *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
-     *                            EEM_{model_name}. Eg. you could pass
35
-     *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
-     *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
-     *                            contains the class "EEM_Food" and
38
-     *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
-     *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
-     *                            class contained in each file should extend EEM_Base.
41
-     * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
-     *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
-     *                            file should extend EE_Base_Class
44
-     *
45
-     * }
46
-     * @throws EE_Error
47
-     */
48
-    public static function register($identifier = '', array $setup_args = [])
49
-    {
50
-        // required fields MUST be present, so let's make sure they are.
51
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
-            throw new EE_Error(
53
-                esc_html__(
54
-                    'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
29
+	/**
30
+	 * @param string $identifier  unique id for it
31
+	 * @param array  $setup_args  {
32
+	 * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
+	 *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
+	 *                            EEM_{model_name}. Eg. you could pass
35
+	 *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
+	 *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
+	 *                            contains the class "EEM_Food" and
38
+	 *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
+	 *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
+	 *                            class contained in each file should extend EEM_Base.
41
+	 * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
+	 *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
+	 *                            file should extend EE_Base_Class
44
+	 *
45
+	 * }
46
+	 * @throws EE_Error
47
+	 */
48
+	public static function register($identifier = '', array $setup_args = [])
49
+	{
50
+		// required fields MUST be present, so let's make sure they are.
51
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
+			throw new EE_Error(
53
+				esc_html__(
54
+					'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59 59
 
60
-        // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
62
-            return;
63
-        }
60
+		// make sure we don't register twice
61
+		if (isset(self::$_model_registry[ $identifier ])) {
62
+			return;
63
+		}
64 64
 
65
-        if (
66
-            ! did_action('AHEE__EE_System__load_espresso_addons')
67
-            || did_action('FHEE__EE_System__parse_model_names')
68
-            || did_action('FHEE__EE_System__parse_implemented_model_names')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                sprintf(
73
-                    esc_html__(
74
-                        'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
75
-                        'event_espresso'
76
-                    ),
77
-                    $identifier
78
-                ),
79
-                '4.5'
80
-            );
81
-        }
82
-        self::$_model_registry[ $identifier ] = $setup_args;
65
+		if (
66
+			! did_action('AHEE__EE_System__load_espresso_addons')
67
+			|| did_action('FHEE__EE_System__parse_model_names')
68
+			|| did_action('FHEE__EE_System__parse_implemented_model_names')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				sprintf(
73
+					esc_html__(
74
+						'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
75
+						'event_espresso'
76
+					),
77
+					$identifier
78
+				),
79
+				'4.5'
80
+			);
81
+		}
82
+		self::$_model_registry[ $identifier ] = $setup_args;
83 83
 
84
-        if (
85
-            (isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87
-        ) {
88
-            throw new EE_Error(
89
-                sprintf(
90
-                    esc_html__(
91
-                        'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
92
-                        'event_espresso'
93
-                    ),
94
-                    implode(", ", array_keys($setup_args))
95
-                )
96
-            );
97
-        }
98
-        if (isset($setup_args['model_paths'])) {
99
-            // make sure they passed in an array
100
-            if (! is_array($setup_args['model_paths'])) {
101
-                $setup_args['model_paths'] = [$setup_args['model_paths']];
102
-            }
103
-            // we want to add this as a model folder
104
-            // and autoload them all
105
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
106
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
107
-            $model_name_to_classname_map = [];
108
-            foreach (array_keys($class_to_filepath_map) as $classname) {
109
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
110
-            }
111
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
112
-            add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113
-            add_filter(
114
-                'FHEE__EE_System__parse_implemented_model_names',
115
-                ['EE_Register_Model', 'add_addon_models']
116
-            );
117
-            add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
118
-            unset($setup_args['model_paths']);
119
-        }
120
-        if (isset($setup_args['class_paths'])) {
121
-            // make sure they passed in an array
122
-            if (! is_array($setup_args['class_paths'])) {
123
-                $setup_args['class_paths'] = [$setup_args['class_paths']];
124
-            }
125
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
126
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
127
-            add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
128
-            unset($setup_args['class_paths']);
129
-        }
130
-        foreach ($setup_args as $unknown_key => $unknown_config) {
131
-            self::deregister($identifier);
132
-            throw new EE_Error(
133
-                sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
134
-            );
135
-        }
136
-    }
84
+		if (
85
+			(isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
+			|| (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87
+		) {
88
+			throw new EE_Error(
89
+				sprintf(
90
+					esc_html__(
91
+						'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
92
+						'event_espresso'
93
+					),
94
+					implode(", ", array_keys($setup_args))
95
+				)
96
+			);
97
+		}
98
+		if (isset($setup_args['model_paths'])) {
99
+			// make sure they passed in an array
100
+			if (! is_array($setup_args['model_paths'])) {
101
+				$setup_args['model_paths'] = [$setup_args['model_paths']];
102
+			}
103
+			// we want to add this as a model folder
104
+			// and autoload them all
105
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
106
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
107
+			$model_name_to_classname_map = [];
108
+			foreach (array_keys($class_to_filepath_map) as $classname) {
109
+				$model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
110
+			}
111
+			self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
112
+			add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113
+			add_filter(
114
+				'FHEE__EE_System__parse_implemented_model_names',
115
+				['EE_Register_Model', 'add_addon_models']
116
+			);
117
+			add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
118
+			unset($setup_args['model_paths']);
119
+		}
120
+		if (isset($setup_args['class_paths'])) {
121
+			// make sure they passed in an array
122
+			if (! is_array($setup_args['class_paths'])) {
123
+				$setup_args['class_paths'] = [$setup_args['class_paths']];
124
+			}
125
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
126
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
127
+			add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
128
+			unset($setup_args['class_paths']);
129
+		}
130
+		foreach ($setup_args as $unknown_key => $unknown_config) {
131
+			self::deregister($identifier);
132
+			throw new EE_Error(
133
+				sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
134
+			);
135
+		}
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * Filters the core list of models
141
-     *
142
-     * @param array $core_models
143
-     * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
144
-     */
145
-    public static function add_addon_models(array $core_models = [])
146
-    {
147
-        foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
148
-            $core_models = array_merge($core_models, $model_name_to_class_map);
149
-        }
150
-        return $core_models;
151
-    }
139
+	/**
140
+	 * Filters the core list of models
141
+	 *
142
+	 * @param array $core_models
143
+	 * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
144
+	 */
145
+	public static function add_addon_models(array $core_models = [])
146
+	{
147
+		foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
148
+			$core_models = array_merge($core_models, $model_name_to_class_map);
149
+		}
150
+		return $core_models;
151
+	}
152 152
 
153 153
 
154
-    /**
155
-     * Filters the list of model folders
156
-     *
157
-     * @param array $folders
158
-     * @return array of folder paths
159
-     */
160
-    public static function add_model_folders(array $folders = [])
161
-    {
162
-        foreach (self::$_model_registry as $setup_args) {
163
-            if (isset($setup_args['model_paths'])) {
164
-                $folders = array_merge($folders, $setup_args['model_paths']);
165
-            }
166
-        }
167
-        return $folders;
168
-    }
154
+	/**
155
+	 * Filters the list of model folders
156
+	 *
157
+	 * @param array $folders
158
+	 * @return array of folder paths
159
+	 */
160
+	public static function add_model_folders(array $folders = [])
161
+	{
162
+		foreach (self::$_model_registry as $setup_args) {
163
+			if (isset($setup_args['model_paths'])) {
164
+				$folders = array_merge($folders, $setup_args['model_paths']);
165
+			}
166
+		}
167
+		return $folders;
168
+	}
169 169
 
170 170
 
171
-    /**
172
-     * Filters the array of model class paths
173
-     *
174
-     * @param array $folders
175
-     * @return array of folder paths
176
-     */
177
-    public static function add_class_folders(array $folders = [])
178
-    {
179
-        foreach (self::$_model_registry as $setup_args) {
180
-            if (isset($setup_args['class_paths'])) {
181
-                $folders = array_merge($folders, $setup_args['class_paths']);
182
-            }
183
-        }
184
-        return $folders;
185
-    }
171
+	/**
172
+	 * Filters the array of model class paths
173
+	 *
174
+	 * @param array $folders
175
+	 * @return array of folder paths
176
+	 */
177
+	public static function add_class_folders(array $folders = [])
178
+	{
179
+		foreach (self::$_model_registry as $setup_args) {
180
+			if (isset($setup_args['class_paths'])) {
181
+				$folders = array_merge($folders, $setup_args['class_paths']);
182
+			}
183
+		}
184
+		return $folders;
185
+	}
186 186
 
187 187
 
188
-    /**
189
-     * deregister
190
-     *
191
-     * @param string $identifier
192
-     */
193
-    public static function deregister($identifier = '')
194
-    {
195
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
196
-    }
188
+	/**
189
+	 * deregister
190
+	 *
191
+	 * @param string $identifier
192
+	 */
193
+	public static function deregister($identifier = '')
194
+	{
195
+		unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
196
+	}
197 197
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Widget.lib.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         }
49 49
 
50 50
         // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
51
+        if (isset(self::$_settings[$identifier])) {
52 52
             return;
53 53
         }
54 54
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
             );
69 69
         }
70 70
         // setup $_settings array from incoming values.
71
-        self::$_settings[ $identifier ] = [
71
+        self::$_settings[$identifier] = [
72 72
             // array of full server paths to any EED_Widgets used by the widget
73 73
             'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [],
74 74
         ];
@@ -107,6 +107,6 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public static function deregister($identifier = '')
109 109
     {
110
-        unset(self::$_settings[ $identifier ]);
110
+        unset(self::$_settings[$identifier]);
111 111
     }
112 112
 }
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -14,98 +14,98 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Register_Widget implements EEI_Plugin_API
16 16
 {
17
-    /**
18
-     * Holds values for registered widgets
19
-     *
20
-     * @var array
21
-     */
22
-    protected static $_settings = [];
17
+	/**
18
+	 * Holds values for registered widgets
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected static $_settings = [];
23 23
 
24 24
 
25
-    /**
26
-     *    Method for registering new EED_Widgets
27
-     *
28
-     * @param string $identifier a unique identifier for this set of widgets
29
-     * @param array  $setup_args an array of arguments provided for registering widgets
30
-     * @type array widget_paths        an array of full server paths to folders containing any EED_Widgets, or to the
31
-     *                           EED_Widget files themselves
32
-     * @return void
33
-     * @throws EE_Error
34
-     * @since    4.3.0
35
-     */
36
-    public static function register($identifier = '', array $setup_args = [])
37
-    {
25
+	/**
26
+	 *    Method for registering new EED_Widgets
27
+	 *
28
+	 * @param string $identifier a unique identifier for this set of widgets
29
+	 * @param array  $setup_args an array of arguments provided for registering widgets
30
+	 * @type array widget_paths        an array of full server paths to folders containing any EED_Widgets, or to the
31
+	 *                           EED_Widget files themselves
32
+	 * @return void
33
+	 * @throws EE_Error
34
+	 * @since    4.3.0
35
+	 */
36
+	public static function register($identifier = '', array $setup_args = [])
37
+	{
38 38
 
39
-        // required fields MUST be present, so let's make sure they are.
40
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['widget_paths'])) {
41
-            throw new EE_Error(
42
-                esc_html__(
43
-                    'In order to register Widgets with EE_Register_Widget::register(), you must include a "widget_id" (a unique identifier for this set of widgets), and an array containing the following keys: "widget_paths" (an array of full server paths to folders that contain widgets, or to the widget files themselves)',
44
-                    'event_espresso'
45
-                )
46
-            );
47
-        }
39
+		// required fields MUST be present, so let's make sure they are.
40
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['widget_paths'])) {
41
+			throw new EE_Error(
42
+				esc_html__(
43
+					'In order to register Widgets with EE_Register_Widget::register(), you must include a "widget_id" (a unique identifier for this set of widgets), and an array containing the following keys: "widget_paths" (an array of full server paths to folders that contain widgets, or to the widget files themselves)',
44
+					'event_espresso'
45
+				)
46
+			);
47
+		}
48 48
 
49
-        // make sure we don't register twice
50
-        if (isset(self::$_settings[ $identifier ])) {
51
-            return;
52
-        }
49
+		// make sure we don't register twice
50
+		if (isset(self::$_settings[ $identifier ])) {
51
+			return;
52
+		}
53 53
 
54 54
 
55
-        // make sure this was called in the right place!
56
-        if (
57
-            ! did_action('AHEE__EE_System__load_espresso_addons')
58
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
59
-        ) {
60
-            EE_Error::doing_it_wrong(
61
-                __METHOD__,
62
-                esc_html__(
63
-                    'An attempt to register widgets has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register widgets.',
64
-                    'event_espresso'
65
-                ),
66
-                '4.3.0'
67
-            );
68
-        }
69
-        // setup $_settings array from incoming values.
70
-        self::$_settings[ $identifier ] = [
71
-            // array of full server paths to any EED_Widgets used by the widget
72
-            'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [],
73
-        ];
74
-        // add to list of widgets to be registered
75
-        add_filter(
76
-            'FHEE__EE_Config__register_widgets__widgets_to_register',
77
-            ['EE_Register_Widget', 'add_widgets']
78
-        );
79
-    }
55
+		// make sure this was called in the right place!
56
+		if (
57
+			! did_action('AHEE__EE_System__load_espresso_addons')
58
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
59
+		) {
60
+			EE_Error::doing_it_wrong(
61
+				__METHOD__,
62
+				esc_html__(
63
+					'An attempt to register widgets has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register widgets.',
64
+					'event_espresso'
65
+				),
66
+				'4.3.0'
67
+			);
68
+		}
69
+		// setup $_settings array from incoming values.
70
+		self::$_settings[ $identifier ] = [
71
+			// array of full server paths to any EED_Widgets used by the widget
72
+			'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [],
73
+		];
74
+		// add to list of widgets to be registered
75
+		add_filter(
76
+			'FHEE__EE_Config__register_widgets__widgets_to_register',
77
+			['EE_Register_Widget', 'add_widgets']
78
+		);
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * Filters the list of widgets to add ours.
84
-     * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
85
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/widgets/espresso_monkey'...)
86
-     *
87
-     * @param array $widgets_to_register array of paths to all widgets that require registering
88
-     * @return array
89
-     */
90
-    public static function add_widgets(array $widgets_to_register = [])
91
-    {
92
-        foreach (self::$_settings as $settings) {
93
-            $widgets_to_register = array_merge($widgets_to_register, $settings['widget_paths']);
94
-        }
95
-        return $widgets_to_register;
96
-    }
82
+	/**
83
+	 * Filters the list of widgets to add ours.
84
+	 * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
85
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/widgets/espresso_monkey'...)
86
+	 *
87
+	 * @param array $widgets_to_register array of paths to all widgets that require registering
88
+	 * @return array
89
+	 */
90
+	public static function add_widgets(array $widgets_to_register = [])
91
+	{
92
+		foreach (self::$_settings as $settings) {
93
+			$widgets_to_register = array_merge($widgets_to_register, $settings['widget_paths']);
94
+		}
95
+		return $widgets_to_register;
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * This deregisters a widget that was previously registered with a specific $identifier.
101
-     *
102
-     * @param string $identifier the name for the widget that was previously registered
103
-     * @return void
104
-     * @since    4.3.0
105
-     *
106
-     */
107
-    public static function deregister($identifier = '')
108
-    {
109
-        unset(self::$_settings[ $identifier ]);
110
-    }
99
+	/**
100
+	 * This deregisters a widget that was previously registered with a specific $identifier.
101
+	 *
102
+	 * @param string $identifier the name for the widget that was previously registered
103
+	 * @return void
104
+	 * @since    4.3.0
105
+	 *
106
+	 */
107
+	public static function deregister($identifier = '')
108
+	{
109
+		unset(self::$_settings[ $identifier ]);
110
+	}
111 111
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Data_Migration_Scripts.lib.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             );
48 48
         }
49 49
         // make sure we don't register twice
50
-        if (isset(self::$_settings[ $identifier ])) {
50
+        if (isset(self::$_settings[$identifier])) {
51 51
             return;
52 52
         }
53 53
         // make sure this was called in the right place!
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
             );
66 66
         }
67 67
         // setup $_settings array from incoming values.
68
-        self::$_settings[ $identifier ] = array(
68
+        self::$_settings[$identifier] = array(
69 69
             'dms_paths' => (array) $setup_args['dms_paths'],
70 70
         );
71 71
         // setup DMS
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
                 // so if for some reason an addon has multiple dms paths,
91 91
                 // we append one or more * to the classname
92 92
                 // which will get stripped out later on
93
-                $dms_paths[ $identifier . str_repeat('*', $wildcards) ] = $dms_path;
93
+                $dms_paths[$identifier.str_repeat('*', $wildcards)] = $dms_path;
94 94
                 $wildcards++;
95 95
             }
96 96
         }
@@ -107,6 +107,6 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public static function deregister($identifier = '')
109 109
     {
110
-        unset(self::$_settings[ $identifier ]);
110
+        unset(self::$_settings[$identifier]);
111 111
     }
112 112
 }
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -14,98 +14,98 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Register_Data_Migration_Scripts implements EEI_Plugin_API
16 16
 {
17
-    /**
18
-     * Holds values for registered DMSs
19
-     *
20
-     * @var array[][]
21
-     */
22
-    protected static $_settings = array();
17
+	/**
18
+	 * Holds values for registered DMSs
19
+	 *
20
+	 * @var array[][]
21
+	 */
22
+	protected static $_settings = array();
23 23
 
24 24
 
25
-    /**
26
-     * Method for registering new Data Migration Scripts
27
-     *
28
-     * @since 4.3.0
29
-     * @param string $identifier EE_Addon class name that this set of data migration scripts belongs to
30
-     *                           If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
31
-     * @param array  $setup_args {
32
-     * @type string  $dms_paths  an array of full server paths to folders that contain data migration scripts
33
-     *                           }
34
-     * @throws EE_Error
35
-     * @return void
36
-     */
37
-    public static function register($identifier = '', array $setup_args = [])
38
-    {
39
-        // required fields MUST be present, so let's make sure they are.
40
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) {
41
-            throw new EE_Error(
42
-                esc_html__(
43
-                    'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)',
44
-                    'event_espresso'
45
-                )
46
-            );
47
-        }
48
-        // make sure we don't register twice
49
-        if (isset(self::$_settings[ $identifier ])) {
50
-            return;
51
-        }
52
-        // make sure this was called in the right place!
53
-        if (
54
-            ! did_action('AHEE__EE_System__load_espresso_addons')
55
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
56
-        ) {
57
-            EE_Error::doing_it_wrong(
58
-                __METHOD__,
59
-                esc_html__(
60
-                    'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.',
61
-                    'event_espresso'
62
-                ),
63
-                '4.3.0'
64
-            );
65
-        }
66
-        // setup $_settings array from incoming values.
67
-        self::$_settings[ $identifier ] = array(
68
-            'dms_paths' => (array) $setup_args['dms_paths'],
69
-        );
70
-        // setup DMS
71
-        add_filter(
72
-            'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',
73
-            array('EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders')
74
-        );
75
-    }
25
+	/**
26
+	 * Method for registering new Data Migration Scripts
27
+	 *
28
+	 * @since 4.3.0
29
+	 * @param string $identifier EE_Addon class name that this set of data migration scripts belongs to
30
+	 *                           If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
31
+	 * @param array  $setup_args {
32
+	 * @type string  $dms_paths  an array of full server paths to folders that contain data migration scripts
33
+	 *                           }
34
+	 * @throws EE_Error
35
+	 * @return void
36
+	 */
37
+	public static function register($identifier = '', array $setup_args = [])
38
+	{
39
+		// required fields MUST be present, so let's make sure they are.
40
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) {
41
+			throw new EE_Error(
42
+				esc_html__(
43
+					'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)',
44
+					'event_espresso'
45
+				)
46
+			);
47
+		}
48
+		// make sure we don't register twice
49
+		if (isset(self::$_settings[ $identifier ])) {
50
+			return;
51
+		}
52
+		// make sure this was called in the right place!
53
+		if (
54
+			! did_action('AHEE__EE_System__load_espresso_addons')
55
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
56
+		) {
57
+			EE_Error::doing_it_wrong(
58
+				__METHOD__,
59
+				esc_html__(
60
+					'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.',
61
+					'event_espresso'
62
+				),
63
+				'4.3.0'
64
+			);
65
+		}
66
+		// setup $_settings array from incoming values.
67
+		self::$_settings[ $identifier ] = array(
68
+			'dms_paths' => (array) $setup_args['dms_paths'],
69
+		);
70
+		// setup DMS
71
+		add_filter(
72
+			'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',
73
+			array('EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders')
74
+		);
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * @param array $dms_paths
80
-     * @return array
81
-     */
82
-    public static function add_data_migration_script_folders(array $dms_paths = array())
83
-    {
84
-        foreach (self::$_settings as $identifier => $settings) {
85
-            $wildcards = 0;
86
-            foreach ($settings['dms_paths'] as $dms_path) {
87
-                // since we are using the addon name for the array key
88
-                // we need to ensure that the key is unique,
89
-                // so if for some reason an addon has multiple dms paths,
90
-                // we append one or more * to the classname
91
-                // which will get stripped out later on
92
-                $dms_paths[ $identifier . str_repeat('*', $wildcards) ] = $dms_path;
93
-                $wildcards++;
94
-            }
95
-        }
96
-        return $dms_paths;
97
-    }
78
+	/**
79
+	 * @param array $dms_paths
80
+	 * @return array
81
+	 */
82
+	public static function add_data_migration_script_folders(array $dms_paths = array())
83
+	{
84
+		foreach (self::$_settings as $identifier => $settings) {
85
+			$wildcards = 0;
86
+			foreach ($settings['dms_paths'] as $dms_path) {
87
+				// since we are using the addon name for the array key
88
+				// we need to ensure that the key is unique,
89
+				// so if for some reason an addon has multiple dms paths,
90
+				// we append one or more * to the classname
91
+				// which will get stripped out later on
92
+				$dms_paths[ $identifier . str_repeat('*', $wildcards) ] = $dms_path;
93
+				$wildcards++;
94
+			}
95
+		}
96
+		return $dms_paths;
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id
102
-     *
103
-     * @since 4.3.0
104
-     * @param string $identifier EE_Addon class name that this set of data migration scripts belongs to
105
-     * @return void
106
-     */
107
-    public static function deregister($identifier = '')
108
-    {
109
-        unset(self::$_settings[ $identifier ]);
110
-    }
100
+	/**
101
+	 * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id
102
+	 *
103
+	 * @since 4.3.0
104
+	 * @param string $identifier EE_Addon class name that this set of data migration scripts belongs to
105
+	 * @return void
106
+	 */
107
+	public static function deregister($identifier = '')
108
+	{
109
+		unset(self::$_settings[ $identifier ]);
110
+	}
111 111
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Messages_Shortcode_Library.lib.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         }
74 74
 
75 75
         // make sure we don't register twice
76
-        if (isset(self::$_ee_messages_shortcode_registry[ $identifier ])) {
76
+        if (isset(self::$_ee_messages_shortcode_registry[$identifier])) {
77 77
             return;
78 78
         }
79 79
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             );
96 96
         }
97 97
 
98
-        self::$_ee_messages_shortcode_registry[ $identifier ] = [
98
+        self::$_ee_messages_shortcode_registry[$identifier] = [
99 99
             'autoloadpaths'        => (array) $setup_args['autoloadpaths'],
100 100
             'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes'])
101 101
                 ? (array) $setup_args['list_type_shortcodes'] : [],
@@ -109,19 +109,19 @@  discard block
 block discarded – undo
109 109
         );
110 110
 
111 111
         // add below filters if the required callback is provided.
112
-        if (! empty($setup_args['msgr_validator_callback'])) {
112
+        if ( ! empty($setup_args['msgr_validator_callback'])) {
113 113
             add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2);
114 114
         }
115 115
 
116
-        if (! empty($setup_args['msgr_template_fields_callback'])) {
116
+        if ( ! empty($setup_args['msgr_template_fields_callback'])) {
117 117
             add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2);
118 118
         }
119 119
 
120
-        if (! empty($setup_args['valid_shortcodes_callback'])) {
120
+        if ( ! empty($setup_args['valid_shortcodes_callback'])) {
121 121
             add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2);
122 122
         }
123 123
 
124
-        if (! empty($setup_args['list_type_shortcodes'])) {
124
+        if ( ! empty($setup_args['list_type_shortcodes'])) {
125 125
             add_filter(
126 126
                 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes',
127 127
                 ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'],
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     public static function deregister($identifier = '')
142 142
     {
143
-        unset(self::$_ee_messages_shortcode_registry[ $identifier ]);
143
+        unset(self::$_ee_messages_shortcode_registry[$identifier]);
144 144
     }
145 145
 
146 146
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
     public static function register_msgs_autoload_paths(array $paths)
156 156
     {
157 157
 
158
-        if (! empty(self::$_ee_messages_shortcode_registry)) {
158
+        if ( ! empty(self::$_ee_messages_shortcode_registry)) {
159 159
             foreach (self::$_ee_messages_shortcode_registry as $st_reg) {
160 160
                 if (empty($st_reg['autoloadpaths'])) {
161 161
                     continue;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         }
185 185
 
186 186
         foreach (self::$_ee_messages_shortcode_registry as $sc_reg) {
187
-            if (! empty($sc_reg['list_type_shortcodes'])) {
187
+            if ( ! empty($sc_reg['list_type_shortcodes'])) {
188 188
                 $original_shortcodes = array_merge($original_shortcodes, $sc_reg['list_type_shortcodes']);
189 189
             }
190 190
         }
Please login to merge, or discard this patch.
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -10,183 +10,183 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Register_Messages_Shortcode_Library implements EEI_Plugin_API
12 12
 {
13
-    /**
14
-     * holds values for registered messages shortcode libraries
15
-     *
16
-     * @var array
17
-     */
18
-    protected static $_ee_messages_shortcode_registry = [];
19
-
20
-
21
-    /**
22
-     * Helper method for registering a new shortcodes library class for the messages system.
23
-     *
24
-     * Note this is not used for adding shortcodes to existing libraries.  It's for registering anything
25
-     * related to registering a new EE_{shortcode_library_name}_Shortcodes.lib.php class.
26
-     *
27
-     * @param string $identifier                                                    What is the name of this shortcode
28
-     *                                                                              library
29
-     *                                                                              (e.g. 'question_list');
30
-     * @param array  $setup_args                                                    {
31
-     *                                                                              An array of arguments provided for
32
-     *                                                                              registering the new messages
33
-     *                                                                              shortcode library.
34
-     *
35
-     * @type array   $autoloadpaths                                                 An array of paths to add to the
36
-     *       messages autoloader for the new shortcode library class file.
37
-     * @type string  $msgr_validator_callback                                       Callback for a method that will
38
-     *       register the library with the messenger
39
-     *                                                                              _validator_config. Optional.
40
-     * @type string  $msgr_template_fields_callback                                 Callback for changing adding the
41
-     *                                                                              _template_fields property for
42
-     *                                                                              messenger. For example, the
43
-     *                                                                              shortcode library may add a new
44
-     *                                                                              field to the message templates.
45
-     *                                                                              Optional.
46
-     * @type string  $valid_shortcodes_callback                                     Callback for message types
47
-     *                                                                              _valid_shortcodes array setup.
48
-     *                                                                              Optional.
49
-     * @type array   $list_type_shortcodes                                          If there are any specific
50
-     *       shortcodes with this message shortcode library that should be considered "list type" then include them in
51
-     *       an array.  List Type shortcodes are shortcodes that have a corresponding field that indicates how they are
52
-     *       parsed. Optional.
53
-     * }
54
-     * @return void
55
-     * @throws EE_Error
56
-     * @throws EE_Error
57
-     * @since    4.3.0
58
-     *
59
-     */
60
-    public static function register($identifier = '', array $setup_args = [])
61
-    {
62
-
63
-        // required fields MUST be present, so let's make sure they are.
64
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['autoloadpaths'])) {
65
-            throw new EE_Error(
66
-                esc_html__(
67
-                    'In order to register a messages shortcode library with EE_Register_Messages_Shortcode_Library::register, you must include a "name" (a unique identifier for this set of message shortcodes), and an array containing the following keys: : "autoload_paths"',
68
-                    'event_espresso'
69
-                )
70
-            );
71
-        }
72
-
73
-        // make sure we don't register twice
74
-        if (isset(self::$_ee_messages_shortcode_registry[ $identifier ])) {
75
-            return;
76
-        }
77
-
78
-        // make sure this was called in the right place!
79
-        if (
80
-            ! did_action('EE_Brewing_Regular___messages_caf')
81
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
82
-        ) {
83
-            EE_Error::doing_it_wrong(
84
-                __METHOD__,
85
-                sprintf(
86
-                    esc_html__(
87
-                        'Should be only called on the "EE_Brewing_Regular___messages_caf" hook (Trying to register a library named %s).',
88
-                        'event_espresso'
89
-                    ),
90
-                    $identifier
91
-                ),
92
-                '4.3.0'
93
-            );
94
-        }
95
-
96
-        self::$_ee_messages_shortcode_registry[ $identifier ] = [
97
-            'autoloadpaths'        => (array) $setup_args['autoloadpaths'],
98
-            'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes'])
99
-                ? (array) $setup_args['list_type_shortcodes'] : [],
100
-        ];
101
-
102
-        // add filters
103
-        add_filter(
104
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
105
-            ['EE_Register_Messages_Shortcode_Library', 'register_msgs_autoload_paths'],
106
-            10
107
-        );
108
-
109
-        // add below filters if the required callback is provided.
110
-        if (! empty($setup_args['msgr_validator_callback'])) {
111
-            add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2);
112
-        }
113
-
114
-        if (! empty($setup_args['msgr_template_fields_callback'])) {
115
-            add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2);
116
-        }
117
-
118
-        if (! empty($setup_args['valid_shortcodes_callback'])) {
119
-            add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2);
120
-        }
121
-
122
-        if (! empty($setup_args['list_type_shortcodes'])) {
123
-            add_filter(
124
-                'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes',
125
-                ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'],
126
-                10
127
-            );
128
-        }
129
-    }
130
-
131
-
132
-    /**
133
-     * This deregisters any messages shortcode library previously registered with the given name.
134
-     *
135
-     * @param string $identifier name used to register the shortcode library.
136
-     * @return  void
137
-     * @since    4.3.0
138
-     */
139
-    public static function deregister($identifier = '')
140
-    {
141
-        unset(self::$_ee_messages_shortcode_registry[ $identifier ]);
142
-    }
143
-
144
-
145
-    /**
146
-     * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
147
-     *
148
-     * @param array $paths array of paths to be checked by EE_messages autoloader.
149
-     * @return array
150
-     * @since    4.3.0
151
-     *
152
-     */
153
-    public static function register_msgs_autoload_paths(array $paths)
154
-    {
155
-
156
-        if (! empty(self::$_ee_messages_shortcode_registry)) {
157
-            foreach (self::$_ee_messages_shortcode_registry as $st_reg) {
158
-                if (empty($st_reg['autoloadpaths'])) {
159
-                    continue;
160
-                }
161
-                $paths = array_merge($paths, $st_reg['autoloadpaths']);
162
-            }
163
-        }
164
-
165
-        return $paths;
166
-    }
167
-
168
-
169
-    /**
170
-     * This is the callback for the FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes
171
-     * filter which is used to add additional list type shortcodes.
172
-     *
173
-     * @param array $original_shortcodes
174
-     * @return  array                                   Modifications to original shortcodes.
175
-     * @since 4.3.0
176
-     *
177
-     */
178
-    public static function register_list_type_shortcodes(array $original_shortcodes)
179
-    {
180
-        if (empty(self::$_ee_messages_shortcode_registry)) {
181
-            return $original_shortcodes;
182
-        }
183
-
184
-        foreach (self::$_ee_messages_shortcode_registry as $sc_reg) {
185
-            if (! empty($sc_reg['list_type_shortcodes'])) {
186
-                $original_shortcodes = array_merge($original_shortcodes, $sc_reg['list_type_shortcodes']);
187
-            }
188
-        }
189
-
190
-        return $original_shortcodes;
191
-    }
13
+	/**
14
+	 * holds values for registered messages shortcode libraries
15
+	 *
16
+	 * @var array
17
+	 */
18
+	protected static $_ee_messages_shortcode_registry = [];
19
+
20
+
21
+	/**
22
+	 * Helper method for registering a new shortcodes library class for the messages system.
23
+	 *
24
+	 * Note this is not used for adding shortcodes to existing libraries.  It's for registering anything
25
+	 * related to registering a new EE_{shortcode_library_name}_Shortcodes.lib.php class.
26
+	 *
27
+	 * @param string $identifier                                                    What is the name of this shortcode
28
+	 *                                                                              library
29
+	 *                                                                              (e.g. 'question_list');
30
+	 * @param array  $setup_args                                                    {
31
+	 *                                                                              An array of arguments provided for
32
+	 *                                                                              registering the new messages
33
+	 *                                                                              shortcode library.
34
+	 *
35
+	 * @type array   $autoloadpaths                                                 An array of paths to add to the
36
+	 *       messages autoloader for the new shortcode library class file.
37
+	 * @type string  $msgr_validator_callback                                       Callback for a method that will
38
+	 *       register the library with the messenger
39
+	 *                                                                              _validator_config. Optional.
40
+	 * @type string  $msgr_template_fields_callback                                 Callback for changing adding the
41
+	 *                                                                              _template_fields property for
42
+	 *                                                                              messenger. For example, the
43
+	 *                                                                              shortcode library may add a new
44
+	 *                                                                              field to the message templates.
45
+	 *                                                                              Optional.
46
+	 * @type string  $valid_shortcodes_callback                                     Callback for message types
47
+	 *                                                                              _valid_shortcodes array setup.
48
+	 *                                                                              Optional.
49
+	 * @type array   $list_type_shortcodes                                          If there are any specific
50
+	 *       shortcodes with this message shortcode library that should be considered "list type" then include them in
51
+	 *       an array.  List Type shortcodes are shortcodes that have a corresponding field that indicates how they are
52
+	 *       parsed. Optional.
53
+	 * }
54
+	 * @return void
55
+	 * @throws EE_Error
56
+	 * @throws EE_Error
57
+	 * @since    4.3.0
58
+	 *
59
+	 */
60
+	public static function register($identifier = '', array $setup_args = [])
61
+	{
62
+
63
+		// required fields MUST be present, so let's make sure they are.
64
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['autoloadpaths'])) {
65
+			throw new EE_Error(
66
+				esc_html__(
67
+					'In order to register a messages shortcode library with EE_Register_Messages_Shortcode_Library::register, you must include a "name" (a unique identifier for this set of message shortcodes), and an array containing the following keys: : "autoload_paths"',
68
+					'event_espresso'
69
+				)
70
+			);
71
+		}
72
+
73
+		// make sure we don't register twice
74
+		if (isset(self::$_ee_messages_shortcode_registry[ $identifier ])) {
75
+			return;
76
+		}
77
+
78
+		// make sure this was called in the right place!
79
+		if (
80
+			! did_action('EE_Brewing_Regular___messages_caf')
81
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
82
+		) {
83
+			EE_Error::doing_it_wrong(
84
+				__METHOD__,
85
+				sprintf(
86
+					esc_html__(
87
+						'Should be only called on the "EE_Brewing_Regular___messages_caf" hook (Trying to register a library named %s).',
88
+						'event_espresso'
89
+					),
90
+					$identifier
91
+				),
92
+				'4.3.0'
93
+			);
94
+		}
95
+
96
+		self::$_ee_messages_shortcode_registry[ $identifier ] = [
97
+			'autoloadpaths'        => (array) $setup_args['autoloadpaths'],
98
+			'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes'])
99
+				? (array) $setup_args['list_type_shortcodes'] : [],
100
+		];
101
+
102
+		// add filters
103
+		add_filter(
104
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
105
+			['EE_Register_Messages_Shortcode_Library', 'register_msgs_autoload_paths'],
106
+			10
107
+		);
108
+
109
+		// add below filters if the required callback is provided.
110
+		if (! empty($setup_args['msgr_validator_callback'])) {
111
+			add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2);
112
+		}
113
+
114
+		if (! empty($setup_args['msgr_template_fields_callback'])) {
115
+			add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2);
116
+		}
117
+
118
+		if (! empty($setup_args['valid_shortcodes_callback'])) {
119
+			add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2);
120
+		}
121
+
122
+		if (! empty($setup_args['list_type_shortcodes'])) {
123
+			add_filter(
124
+				'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes',
125
+				['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'],
126
+				10
127
+			);
128
+		}
129
+	}
130
+
131
+
132
+	/**
133
+	 * This deregisters any messages shortcode library previously registered with the given name.
134
+	 *
135
+	 * @param string $identifier name used to register the shortcode library.
136
+	 * @return  void
137
+	 * @since    4.3.0
138
+	 */
139
+	public static function deregister($identifier = '')
140
+	{
141
+		unset(self::$_ee_messages_shortcode_registry[ $identifier ]);
142
+	}
143
+
144
+
145
+	/**
146
+	 * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
147
+	 *
148
+	 * @param array $paths array of paths to be checked by EE_messages autoloader.
149
+	 * @return array
150
+	 * @since    4.3.0
151
+	 *
152
+	 */
153
+	public static function register_msgs_autoload_paths(array $paths)
154
+	{
155
+
156
+		if (! empty(self::$_ee_messages_shortcode_registry)) {
157
+			foreach (self::$_ee_messages_shortcode_registry as $st_reg) {
158
+				if (empty($st_reg['autoloadpaths'])) {
159
+					continue;
160
+				}
161
+				$paths = array_merge($paths, $st_reg['autoloadpaths']);
162
+			}
163
+		}
164
+
165
+		return $paths;
166
+	}
167
+
168
+
169
+	/**
170
+	 * This is the callback for the FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes
171
+	 * filter which is used to add additional list type shortcodes.
172
+	 *
173
+	 * @param array $original_shortcodes
174
+	 * @return  array                                   Modifications to original shortcodes.
175
+	 * @since 4.3.0
176
+	 *
177
+	 */
178
+	public static function register_list_type_shortcodes(array $original_shortcodes)
179
+	{
180
+		if (empty(self::$_ee_messages_shortcode_registry)) {
181
+			return $original_shortcodes;
182
+		}
183
+
184
+		foreach (self::$_ee_messages_shortcode_registry as $sc_reg) {
185
+			if (! empty($sc_reg['list_type_shortcodes'])) {
186
+				$original_shortcodes = array_merge($original_shortcodes, $sc_reg['list_type_shortcodes']);
187
+			}
188
+		}
189
+
190
+		return $original_shortcodes;
191
+	}
192 192
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Shortcode.lib.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         }
62 62
 
63 63
         // make sure we don't register twice
64
-        if (isset(self::$_settings[ $identifier ])) {
64
+        if (isset(self::$_settings[$identifier])) {
65 65
             return;
66 66
         }
67 67
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
             );
81 81
         }
82 82
         // setup $_settings array from incoming values.
83
-        self::$_settings[ $identifier ] = [
83
+        self::$_settings[$identifier] = [
84 84
             // array of full server paths to any EES_Shortcodes used by the shortcode
85 85
             'shortcode_paths' => isset($setup_args['shortcode_paths'])
86 86
                 ? (array) $setup_args['shortcode_paths']
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
     public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
135 135
     {
136 136
         foreach (self::$_settings as $settings) {
137
-            if (! empty($settings['shortcode_fqcns'])) {
137
+            if ( ! empty($settings['shortcode_fqcns'])) {
138 138
                 foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
139
-                    if (! class_exists($shortcode_fqcn)) {
139
+                    if ( ! class_exists($shortcode_fqcn)) {
140 140
                         throw new InvalidClassException(
141 141
                             sprintf(
142 142
                                 esc_html__(
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                             )
148 148
                         );
149 149
                     }
150
-                    if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
150
+                    if ( ! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
151 151
                         // register dependencies
152 152
                         EE_Dependency_Map::register_dependencies(
153 153
                             $shortcode_fqcn,
@@ -173,6 +173,6 @@  discard block
 block discarded – undo
173 173
      */
174 174
     public static function deregister($identifier = '')
175 175
     {
176
-        unset(self::$_settings[ $identifier ]);
176
+        unset(self::$_settings[$identifier]);
177 177
     }
178 178
 }
Please login to merge, or discard this patch.
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -19,159 +19,159 @@
 block discarded – undo
19 19
  */
20 20
 class EE_Register_Shortcode implements EEI_Plugin_API
21 21
 {
22
-    /**
23
-     * Holds values for registered shortcodes
24
-     *
25
-     * @var array
26
-     */
27
-    protected static $_settings = [];
22
+	/**
23
+	 * Holds values for registered shortcodes
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected static $_settings = [];
28 28
 
29 29
 
30
-    /**
31
-     *    Method for registering new EE_Shortcodes
32
-     *
33
-     * @param string $identifier    a unique identifier for this set of modules Required.
34
-     * @param array  $setup_args    an array of arguments provided for registering shortcodes Required.
35
-     * @type array shortcode_paths  an array of full server paths to folders containing any EES_Shortcodes
36
-     * @type array shortcode_fqcns  an array of fully qualified class names for any new shortcode classes to register.
37
-     *                              Shortcode classes should extend EspressoShortcode
38
-     *                              and be properly namespaced so they are autoloaded.
39
-     * @return void
40
-     * @throws EE_Error
41
-     * @since    4.3.0
42
-     * @since    4.9.46.rc.025  for the new `shortcode_fqcns` array argument.
43
-     */
44
-    public static function register($identifier = '', array $setup_args = [])
45
-    {
46
-        // required fields MUST be present, so let's make sure they are.
47
-        if (
48
-            empty($identifier)
49
-            || ! is_array($setup_args)
50
-            || (
51
-               empty($setup_args['shortcode_paths']))
52
-               && empty($setup_args['shortcode_fqcns'])
53
-        ) {
54
-            throw new EE_Error(
55
-                esc_html__(
56
-                    'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
57
-                    'event_espresso'
58
-                )
59
-            );
60
-        }
30
+	/**
31
+	 *    Method for registering new EE_Shortcodes
32
+	 *
33
+	 * @param string $identifier    a unique identifier for this set of modules Required.
34
+	 * @param array  $setup_args    an array of arguments provided for registering shortcodes Required.
35
+	 * @type array shortcode_paths  an array of full server paths to folders containing any EES_Shortcodes
36
+	 * @type array shortcode_fqcns  an array of fully qualified class names for any new shortcode classes to register.
37
+	 *                              Shortcode classes should extend EspressoShortcode
38
+	 *                              and be properly namespaced so they are autoloaded.
39
+	 * @return void
40
+	 * @throws EE_Error
41
+	 * @since    4.3.0
42
+	 * @since    4.9.46.rc.025  for the new `shortcode_fqcns` array argument.
43
+	 */
44
+	public static function register($identifier = '', array $setup_args = [])
45
+	{
46
+		// required fields MUST be present, so let's make sure they are.
47
+		if (
48
+			empty($identifier)
49
+			|| ! is_array($setup_args)
50
+			|| (
51
+			   empty($setup_args['shortcode_paths']))
52
+			   && empty($setup_args['shortcode_fqcns'])
53
+		) {
54
+			throw new EE_Error(
55
+				esc_html__(
56
+					'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
57
+					'event_espresso'
58
+				)
59
+			);
60
+		}
61 61
 
62
-        // make sure we don't register twice
63
-        if (isset(self::$_settings[ $identifier ])) {
64
-            return;
65
-        }
62
+		// make sure we don't register twice
63
+		if (isset(self::$_settings[ $identifier ])) {
64
+			return;
65
+		}
66 66
 
67
-        // make sure this was called in the right place!
68
-        if (
69
-            ! did_action('AHEE__EE_System__load_espresso_addons')
70
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
71
-        ) {
72
-            EE_Error::doing_it_wrong(
73
-                __METHOD__,
74
-                esc_html__(
75
-                    'An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
76
-                    'event_espresso'
77
-                ),
78
-                '4.3.0'
79
-            );
80
-        }
81
-        // setup $_settings array from incoming values.
82
-        self::$_settings[ $identifier ] = [
83
-            // array of full server paths to any EES_Shortcodes used by the shortcode
84
-            'shortcode_paths' => isset($setup_args['shortcode_paths'])
85
-                ? (array) $setup_args['shortcode_paths']
86
-                : [],
87
-            'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
88
-                ? (array) $setup_args['shortcode_fqcns']
89
-                : [],
90
-        ];
91
-        // add to list of shortcodes to be registered
92
-        add_filter(
93
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
94
-            ['EE_Register_Shortcode', 'add_shortcodes']
95
-        );
67
+		// make sure this was called in the right place!
68
+		if (
69
+			! did_action('AHEE__EE_System__load_espresso_addons')
70
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
71
+		) {
72
+			EE_Error::doing_it_wrong(
73
+				__METHOD__,
74
+				esc_html__(
75
+					'An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
76
+					'event_espresso'
77
+				),
78
+				'4.3.0'
79
+			);
80
+		}
81
+		// setup $_settings array from incoming values.
82
+		self::$_settings[ $identifier ] = [
83
+			// array of full server paths to any EES_Shortcodes used by the shortcode
84
+			'shortcode_paths' => isset($setup_args['shortcode_paths'])
85
+				? (array) $setup_args['shortcode_paths']
86
+				: [],
87
+			'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
88
+				? (array) $setup_args['shortcode_fqcns']
89
+				: [],
90
+		];
91
+		// add to list of shortcodes to be registered
92
+		add_filter(
93
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
94
+			['EE_Register_Shortcode', 'add_shortcodes']
95
+		);
96 96
 
97
-        add_filter(
98
-            'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
99
-            ['EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection']
100
-        );
101
-    }
97
+		add_filter(
98
+			'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
99
+			['EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection']
100
+		);
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * Filters the list of shortcodes to add ours.
106
-     * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
107
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
108
-     *
109
-     * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
110
-     * @return array
111
-     */
112
-    public static function add_shortcodes(array $shortcodes_to_register)
113
-    {
114
-        foreach (self::$_settings as $settings) {
115
-            $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']);
116
-        }
117
-        return $shortcodes_to_register;
118
-    }
104
+	/**
105
+	 * Filters the list of shortcodes to add ours.
106
+	 * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
107
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
108
+	 *
109
+	 * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
110
+	 * @return array
111
+	 */
112
+	public static function add_shortcodes(array $shortcodes_to_register)
113
+	{
114
+		foreach (self::$_settings as $settings) {
115
+			$shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']);
116
+		}
117
+		return $shortcodes_to_register;
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * Hooks into
123
-     * FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection and
124
-     * registers any provided shortcode fully qualified class names.
125
-     *
126
-     * @param CollectionInterface $shortcodes_collection
127
-     * @return CollectionInterface
128
-     * @throws InvalidArgumentException
129
-     * @throws InvalidClassException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidInterfaceException
132
-     */
133
-    public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
134
-    {
135
-        foreach (self::$_settings as $settings) {
136
-            if (! empty($settings['shortcode_fqcns'])) {
137
-                foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
138
-                    if (! class_exists($shortcode_fqcn)) {
139
-                        throw new InvalidClassException(
140
-                            sprintf(
141
-                                esc_html__(
142
-                                    'Are you sure %s is the right fully qualified class name for the shortcode class?',
143
-                                    'event_espresso'
144
-                                ),
145
-                                $shortcode_fqcn
146
-                            )
147
-                        );
148
-                    }
149
-                    if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
150
-                        // register dependencies
151
-                        EE_Dependency_Map::register_dependencies(
152
-                            $shortcode_fqcn,
153
-                            [
154
-                                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
155
-                            ]
156
-                        );
157
-                    }
158
-                    $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn));
159
-                }
160
-            }
161
-        }
162
-        return $shortcodes_collection;
163
-    }
121
+	/**
122
+	 * Hooks into
123
+	 * FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection and
124
+	 * registers any provided shortcode fully qualified class names.
125
+	 *
126
+	 * @param CollectionInterface $shortcodes_collection
127
+	 * @return CollectionInterface
128
+	 * @throws InvalidArgumentException
129
+	 * @throws InvalidClassException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidInterfaceException
132
+	 */
133
+	public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
134
+	{
135
+		foreach (self::$_settings as $settings) {
136
+			if (! empty($settings['shortcode_fqcns'])) {
137
+				foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
138
+					if (! class_exists($shortcode_fqcn)) {
139
+						throw new InvalidClassException(
140
+							sprintf(
141
+								esc_html__(
142
+									'Are you sure %s is the right fully qualified class name for the shortcode class?',
143
+									'event_espresso'
144
+								),
145
+								$shortcode_fqcn
146
+							)
147
+						);
148
+					}
149
+					if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
150
+						// register dependencies
151
+						EE_Dependency_Map::register_dependencies(
152
+							$shortcode_fqcn,
153
+							[
154
+								'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
155
+							]
156
+						);
157
+					}
158
+					$shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn));
159
+				}
160
+			}
161
+		}
162
+		return $shortcodes_collection;
163
+	}
164 164
 
165 165
 
166
-    /**
167
-     * This deregisters a shortcode that was previously registered with a specific $identifier.
168
-     *
169
-     * @param string $identifier the name for the shortcode that was previously registered
170
-     * @return void
171
-     * @since    4.3.0
172
-     */
173
-    public static function deregister($identifier = '')
174
-    {
175
-        unset(self::$_settings[ $identifier ]);
176
-    }
166
+	/**
167
+	 * This deregisters a shortcode that was previously registered with a specific $identifier.
168
+	 *
169
+	 * @param string $identifier the name for the shortcode that was previously registered
170
+	 * @return void
171
+	 * @since    4.3.0
172
+	 */
173
+	public static function deregister($identifier = '')
174
+	{
175
+		unset(self::$_settings[ $identifier ]);
176
+	}
177 177
 }
Please login to merge, or discard this patch.
core/EED_Module.module.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
     protected static function getRequest()
134 134
     {
135 135
         static $request;
136
-        if (! $request instanceof RequestInterface) {
136
+        if ( ! $request instanceof RequestInterface) {
137 137
             $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
138 138
         }
139 139
         return $request;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     protected static function getResponse()
148 148
     {
149 149
         static $response;
150
-        if (! $response instanceof RequestInterface) {
150
+        if ( ! $response instanceof RequestInterface) {
151 151
             $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
152 152
         }
153 153
         return $response;
Please login to merge, or discard this patch.
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -14,141 +14,141 @@
 block discarded – undo
14 14
  */
15 15
 abstract class EED_Module extends EE_Configurable implements ResettableInterface
16 16
 {
17
-    /**
18
-     * rendered output to be returned to WP
19
-     *
20
-     * @var    string $output
21
-     */
22
-    protected $output = '';
23
-
24
-    /**
25
-     * the current active espresso template theme
26
-     *
27
-     * @var    string $theme
28
-     */
29
-    protected $theme = '';
30
-
31
-
32
-    /**
33
-     * @return void
34
-     */
35
-    public static function reset()
36
-    {
37
-        $module_name = get_called_class();
38
-        new $module_name();
39
-    }
40
-
41
-
42
-    /**
43
-     *    set_hooks - for hooking into EE Core, other modules, etc
44
-     *
45
-     * @access    public
46
-     * @return    void
47
-     */
48
-    public static function set_hooks()
49
-    {
50
-    }
51
-
52
-
53
-    /**
54
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
55
-     *
56
-     * @access    public
57
-     * @return    void
58
-     */
59
-    public static function set_hooks_admin()
60
-    {
61
-    }
62
-
63
-
64
-    /**
65
-     *    run - initial module setup
66
-     *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
67
-     *
68
-     * @access    public
69
-     * @var            WP $WP
70
-     * @return    void
71
-     */
72
-    abstract public function run($WP);
73
-
74
-
75
-    /**
76
-     * EED_Module constructor.
77
-     */
78
-    final public function __construct()
79
-    {
80
-        $this->theme = EE_Config::get_current_theme();
81
-        $module_name = $this->module_name();
82
-        EE_Registry::instance()->modules->{$module_name} = $this;
83
-    }
84
-
85
-
86
-    /**
87
-     * @param string $module_name
88
-     * @return EED_Module|mixed
89
-     * @throws EE_Error
90
-     * @throws ReflectionException
91
-     */
92
-    protected static function get_instance($module_name = '')
93
-    {
94
-        $module_name = ! empty($module_name)
95
-            ? $module_name
96
-            : get_called_class();
97
-        if (
98
-            ! isset(EE_Registry::instance()->modules->{$module_name})
99
-            || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
100
-        ) {
101
-            EE_Registry::instance()->add_module($module_name);
102
-        }
103
-        return EE_Registry::instance()->get_module($module_name);
104
-    }
105
-
106
-
107
-    /**
108
-     *    module_name
109
-     *
110
-     * @access    public
111
-     * @return    string
112
-     */
113
-    public function module_name()
114
-    {
115
-        return get_class($this);
116
-    }
117
-
118
-
119
-    /**
120
-     * @return string
121
-     */
122
-    public function theme()
123
-    {
124
-        return $this->theme;
125
-    }
126
-
127
-
128
-    /**
129
-     * @return RequestInterface
130
-     * @since   4.10.14.p
131
-     */
132
-    protected static function getRequest()
133
-    {
134
-        static $request;
135
-        if (! $request instanceof RequestInterface) {
136
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
137
-        }
138
-        return $request;
139
-    }
140
-
141
-
142
-    /**
143
-     * @return ResponseInterface
144
-     * @since   4.10.14.p
145
-     */
146
-    protected static function getResponse()
147
-    {
148
-        static $response;
149
-        if (! $response instanceof RequestInterface) {
150
-            $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
151
-        }
152
-        return $response;
153
-    }
17
+	/**
18
+	 * rendered output to be returned to WP
19
+	 *
20
+	 * @var    string $output
21
+	 */
22
+	protected $output = '';
23
+
24
+	/**
25
+	 * the current active espresso template theme
26
+	 *
27
+	 * @var    string $theme
28
+	 */
29
+	protected $theme = '';
30
+
31
+
32
+	/**
33
+	 * @return void
34
+	 */
35
+	public static function reset()
36
+	{
37
+		$module_name = get_called_class();
38
+		new $module_name();
39
+	}
40
+
41
+
42
+	/**
43
+	 *    set_hooks - for hooking into EE Core, other modules, etc
44
+	 *
45
+	 * @access    public
46
+	 * @return    void
47
+	 */
48
+	public static function set_hooks()
49
+	{
50
+	}
51
+
52
+
53
+	/**
54
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
55
+	 *
56
+	 * @access    public
57
+	 * @return    void
58
+	 */
59
+	public static function set_hooks_admin()
60
+	{
61
+	}
62
+
63
+
64
+	/**
65
+	 *    run - initial module setup
66
+	 *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
67
+	 *
68
+	 * @access    public
69
+	 * @var            WP $WP
70
+	 * @return    void
71
+	 */
72
+	abstract public function run($WP);
73
+
74
+
75
+	/**
76
+	 * EED_Module constructor.
77
+	 */
78
+	final public function __construct()
79
+	{
80
+		$this->theme = EE_Config::get_current_theme();
81
+		$module_name = $this->module_name();
82
+		EE_Registry::instance()->modules->{$module_name} = $this;
83
+	}
84
+
85
+
86
+	/**
87
+	 * @param string $module_name
88
+	 * @return EED_Module|mixed
89
+	 * @throws EE_Error
90
+	 * @throws ReflectionException
91
+	 */
92
+	protected static function get_instance($module_name = '')
93
+	{
94
+		$module_name = ! empty($module_name)
95
+			? $module_name
96
+			: get_called_class();
97
+		if (
98
+			! isset(EE_Registry::instance()->modules->{$module_name})
99
+			|| ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
100
+		) {
101
+			EE_Registry::instance()->add_module($module_name);
102
+		}
103
+		return EE_Registry::instance()->get_module($module_name);
104
+	}
105
+
106
+
107
+	/**
108
+	 *    module_name
109
+	 *
110
+	 * @access    public
111
+	 * @return    string
112
+	 */
113
+	public function module_name()
114
+	{
115
+		return get_class($this);
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function theme()
123
+	{
124
+		return $this->theme;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @return RequestInterface
130
+	 * @since   4.10.14.p
131
+	 */
132
+	protected static function getRequest()
133
+	{
134
+		static $request;
135
+		if (! $request instanceof RequestInterface) {
136
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
137
+		}
138
+		return $request;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return ResponseInterface
144
+	 * @since   4.10.14.p
145
+	 */
146
+	protected static function getResponse()
147
+	{
148
+		static $response;
149
+		if (! $response instanceof RequestInterface) {
150
+			$response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
151
+		}
152
+		return $response;
153
+	}
154 154
 }
Please login to merge, or discard this patch.
reg_steps/payment_options/EE_SPCO_Reg_Step_Payment_Options.class.php 2 patches
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         $this->request   = EED_Single_Page_Checkout::getRequest();
134 134
         $this->_slug     = 'payment_options';
135 135
         $this->_name     = esc_html__('Payment Options', 'event_espresso');
136
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php';
136
+        $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.'/payment_options_main.template.php';
137 137
         $this->checkout  = $checkout;
138 138
         $this->_reset_success_message();
139 139
         $this->set_instructions(
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
      */
189 189
     public function translate_js_strings()
190 190
     {
191
-        EE_Registry::$i18n_js_strings['no_payment_method']      = esc_html__(
191
+        EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__(
192 192
             'Please select a method of payment in order to continue.',
193 193
             'event_espresso'
194 194
         );
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             'A valid method of payment could not be determined. Please refresh the page and try again.',
197 197
             'event_espresso'
198 198
         );
199
-        EE_Registry::$i18n_js_strings['forwarding_to_offsite']  = esc_html__(
199
+        EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__(
200 200
             'Forwarding to Secure Payment Provider.',
201 201
             'event_espresso'
202 202
         );
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
     {
218 218
         $transaction = $this->checkout->transaction;
219 219
         // if the transaction isn't set or nothing is owed on it, don't enqueue any JS
220
-        if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
220
+        if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
221 221
             return;
222 222
         }
223 223
         foreach (
@@ -312,18 +312,18 @@  discard block
 block discarded – undo
312 312
         foreach ($registrations as $REG_ID => $registration) {
313 313
             /** @var $registration EE_Registration */
314 314
             // has this registration lost it's space ?
315
-            if (isset($ejected_registrations[ $REG_ID ])) {
315
+            if (isset($ejected_registrations[$REG_ID])) {
316 316
                 if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) {
317
-                    $sold_out_events[ $registration->event()->ID() ] = $registration->event();
317
+                    $sold_out_events[$registration->event()->ID()] = $registration->event();
318 318
                 } else {
319
-                    $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
319
+                    $insufficient_spaces_available[$registration->event()->ID()] = $registration->event();
320 320
                 }
321 321
                 continue;
322 322
             }
323 323
             // event requires admin approval
324 324
             if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
325 325
                 // add event to list of events with pre-approval reg status
326
-                $registrations_requiring_pre_approval[ $REG_ID ] = $registration;
326
+                $registrations_requiring_pre_approval[$REG_ID] = $registration;
327 327
                 do_action(
328 328
                     'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
329 329
                     $registration->event(),
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
                 )
341 341
             ) {
342 342
                 // add event to list of events that are sold out
343
-                $sold_out_events[ $registration->event()->ID() ] = $registration->event();
343
+                $sold_out_events[$registration->event()->ID()] = $registration->event();
344 344
                 do_action(
345 345
                     'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
346 346
                     $registration->event(),
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             }
351 351
             // are they allowed to pay now and is there monies owing?
352 352
             if ($registration->owes_monies_and_can_pay()) {
353
-                $registrations_requiring_payment[ $REG_ID ] = $registration;
353
+                $registrations_requiring_payment[$REG_ID] = $registration;
354 354
                 do_action(
355 355
                     'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
356 356
                     $registration->event(),
@@ -361,28 +361,28 @@  discard block
 block discarded – undo
361 361
                       && $registration->status_ID() !== EEM_Registration::status_id_not_approved
362 362
                       && $registration->ticket()->is_free()
363 363
             ) {
364
-                $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration;
364
+                $registrations_for_free_events[$registration->ticket()->ID()] = $registration;
365 365
             }
366 366
         }
367 367
         $subsections = [];
368 368
         // now decide which template to load
369
-        if (! empty($sold_out_events)) {
369
+        if ( ! empty($sold_out_events)) {
370 370
             $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
371 371
         }
372
-        if (! empty($insufficient_spaces_available)) {
372
+        if ( ! empty($insufficient_spaces_available)) {
373 373
             $subsections['insufficient_space'] = $this->_insufficient_spaces_available(
374 374
                 $insufficient_spaces_available
375 375
             );
376 376
         }
377
-        if (! empty($registrations_requiring_pre_approval)) {
377
+        if ( ! empty($registrations_requiring_pre_approval)) {
378 378
             $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
379 379
                 $registrations_requiring_pre_approval
380 380
             );
381 381
         }
382
-        if (! empty($registrations_for_free_events)) {
382
+        if ( ! empty($registrations_for_free_events)) {
383 383
             $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
384 384
         }
385
-        if (! empty($registrations_requiring_payment)) {
385
+        if ( ! empty($registrations_requiring_payment)) {
386 386
             if ($this->checkout->amount_owing > 0) {
387 387
                 // autoload Line_Item_Display classes
388 388
                 EEH_Autoloader::register_line_item_filter_autoloaders();
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
                         ['registrations' => $registrations]
404 404
                     )
405 405
                 );
406
-                $this->checkout->amount_owing   = $filtered_line_item_tree->total();
406
+                $this->checkout->amount_owing = $filtered_line_item_tree->total();
407 407
                 $this->_apply_registration_payments_to_amount_owing($registrations);
408 408
             }
409 409
             $no_payment_required = false;
@@ -447,13 +447,13 @@  discard block
 block discarded – undo
447 447
      */
448 448
     public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection)
449 449
     {
450
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
450
+        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
451 451
             return $line_item_filter_collection;
452 452
         }
453
-        if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
453
+        if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
454 454
             return $line_item_filter_collection;
455 455
         }
456
-        if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
456
+        if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
457 457
             return $line_item_filter_collection;
458 458
         }
459 459
         $line_item_filter_collection->add(
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
         );
494 494
         foreach ($registrations as $REG_ID => $registration) {
495 495
             // has this registration lost it's space ?
496
-            if (isset($ejected_registrations[ $REG_ID ])) {
497
-                unset($registrations[ $REG_ID ]);
496
+            if (isset($ejected_registrations[$REG_ID])) {
497
+                unset($registrations[$REG_ID]);
498 498
             }
499 499
         }
500 500
         return $registrations;
@@ -544,25 +544,25 @@  discard block
 block discarded – undo
544 544
             }
545 545
             $EVT_ID = $registration->event_ID();
546 546
             $ticket = $registration->ticket();
547
-            if (! isset($tickets_remaining[ $ticket->ID() ])) {
548
-                $tickets_remaining[ $ticket->ID() ] = $ticket->remaining();
547
+            if ( ! isset($tickets_remaining[$ticket->ID()])) {
548
+                $tickets_remaining[$ticket->ID()] = $ticket->remaining();
549 549
             }
550
-            if ($tickets_remaining[ $ticket->ID() ] > 0) {
551
-                if (! isset($event_reg_count[ $EVT_ID ])) {
552
-                    $event_reg_count[ $EVT_ID ] = 0;
550
+            if ($tickets_remaining[$ticket->ID()] > 0) {
551
+                if ( ! isset($event_reg_count[$EVT_ID])) {
552
+                    $event_reg_count[$EVT_ID] = 0;
553 553
                 }
554
-                $event_reg_count[ $EVT_ID ]++;
555
-                if (! isset($event_spaces_remaining[ $EVT_ID ])) {
556
-                    $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale();
554
+                $event_reg_count[$EVT_ID]++;
555
+                if ( ! isset($event_spaces_remaining[$EVT_ID])) {
556
+                    $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale();
557 557
                 }
558 558
             }
559 559
             if (
560 560
                 $revisit
561
-                && ($tickets_remaining[ $ticket->ID() ] === 0
562
-                    || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
561
+                && ($tickets_remaining[$ticket->ID()] === 0
562
+                    || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID]
563 563
                 )
564 564
             ) {
565
-                $ejected_registrations[ $REG_ID ] = $registration->event();
565
+                $ejected_registrations[$REG_ID] = $registration->event();
566 566
                 if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
567 567
                     /** @type EE_Registration_Processor $registration_processor */
568 568
                     $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
         foreach ($sold_out_events_array as $sold_out_event) {
623 623
             $sold_out_events .= EEH_HTML::li(
624 624
                 EEH_HTML::span(
625
-                    '  ' . $sold_out_event->name(),
625
+                    '  '.$sold_out_event->name(),
626 626
                     '',
627 627
                     'dashicons dashicons-marker ee-icon-size-16 pink-text'
628 628
                 )
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
         foreach ($insufficient_spaces_events_array as $event) {
679 679
             if ($event instanceof EE_Event) {
680 680
                 $insufficient_space_events .= EEH_HTML::li(
681
-                    EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
681
+                    EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
682 682
                 );
683 683
             }
684 684
         }
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
         $events_requiring_pre_approval = [];
728 728
         foreach ($registrations_requiring_pre_approval as $registration) {
729 729
             if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
730
-                $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
730
+                $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li(
731 731
                     EEH_HTML::span(
732 732
                         '',
733 733
                         '',
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
     {
868 868
         return new EE_Form_Section_Proper(
869 869
             [
870
-                'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
870
+                'html_id'         => 'ee-'.$this->slug().'-extra-hidden-inputs',
871 871
                 'layout_strategy' => new EE_Div_Per_Section_Layout(),
872 872
                 'subsections'     => [
873 873
                     'spco_no_payment_required' => new EE_Hidden_Input(
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
                 $payments += $registration->registration_payments();
907 907
             }
908 908
         }
909
-        if (! empty($payments)) {
909
+        if ( ! empty($payments)) {
910 910
             foreach ($payments as $payment) {
911 911
                 if ($payment instanceof EE_Registration_Payment) {
912 912
                     $this->checkout->amount_owing -= $payment->amount();
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
             );
996 996
         }
997 997
         // switch up header depending on number of available payment methods
998
-        $payment_method_header     = count($this->checkout->available_payment_methods) > 1
998
+        $payment_method_header = count($this->checkout->available_payment_methods) > 1
999 999
             ? apply_filters(
1000 1000
                 'FHEE__registration_page_payment_options__method_of_payment_hdr',
1001 1001
                 esc_html__('Please Select Your Method of Payment', 'event_espresso')
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
                 $payment_method_button = EEH_HTML::img(
1030 1030
                     $payment_method->button_url(),
1031 1031
                     $payment_method->name(),
1032
-                    'spco-payment-method-' . $payment_method->slug() . '-btn-img',
1032
+                    'spco-payment-method-'.$payment_method->slug().'-btn-img',
1033 1033
                     'spco-payment-method-btn-img'
1034 1034
                 );
1035 1035
                 // check if any payment methods are set as default
@@ -1037,15 +1037,15 @@  discard block
 block discarded – undo
1037 1037
                 // open_by_default
1038 1038
                 if (
1039 1039
                     ($this->checkout->selected_method_of_payment === $payment_method->slug())
1040
-                    || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1040
+                    || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1041 1041
                 ) {
1042 1042
                     $this->checkout->selected_method_of_payment = $payment_method->slug();
1043 1043
                     $this->_save_selected_method_of_payment();
1044
-                    $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button;
1044
+                    $default_payment_method_option[$payment_method->slug()] = $payment_method_button;
1045 1045
                 } else {
1046
-                    $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
1046
+                    $available_payment_method_options[$payment_method->slug()] = $payment_method_button;
1047 1047
                 }
1048
-                $payment_methods_billing_info[ $payment_method->slug() . '-info' ] =
1048
+                $payment_methods_billing_info[$payment_method->slug().'-info'] =
1049 1049
                     $this->_payment_method_billing_info(
1050 1050
                         $payment_method
1051 1051
                     );
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
         $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs(
1059 1059
             $available_payment_method_options
1060 1060
         );
1061
-        $available_payment_methods                              += $payment_methods_billing_info;
1061
+        $available_payment_methods += $payment_methods_billing_info;
1062 1062
         // build the available payment methods form
1063 1063
         return new EE_Form_Section_Proper(
1064 1064
             [
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
      */
1082 1082
     protected function _get_available_payment_methods()
1083 1083
     {
1084
-        if (! empty($this->checkout->available_payment_methods)) {
1084
+        if ( ! empty($this->checkout->available_payment_methods)) {
1085 1085
             return $this->checkout->available_payment_methods;
1086 1086
         }
1087 1087
         $available_payment_methods = [];
@@ -1093,7 +1093,7 @@  discard block
 block discarded – undo
1093 1093
         );
1094 1094
         foreach ($payment_methods as $payment_method) {
1095 1095
             if ($payment_method instanceof EE_Payment_Method) {
1096
-                $available_payment_methods[ $payment_method->slug() ] = $payment_method;
1096
+                $available_payment_methods[$payment_method->slug()] = $payment_method;
1097 1097
             }
1098 1098
         }
1099 1099
         return $available_payment_methods;
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
         );
1189 1189
         return new EE_Form_Section_Proper(
1190 1190
             [
1191
-                'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1191
+                'html_id'         => 'spco-payment-method-info-'.$payment_method->slug(),
1192 1192
                 'html_class'      => 'spco-payment-method-info-dv',
1193 1193
                 // only display the selected or default PM
1194 1194
                 'html_style'      => $currently_selected ? '' : 'display:none;',
@@ -1217,7 +1217,7 @@  discard block
 block discarded – undo
1217 1217
         // how have they chosen to pay?
1218 1218
         $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1219 1219
         $this->checkout->payment_method             = $this->_get_payment_method_for_selected_method_of_payment();
1220
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1220
+        if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
1221 1221
             return false;
1222 1222
         }
1223 1223
         if (
@@ -1392,7 +1392,7 @@  discard block
 block discarded – undo
1392 1392
      */
1393 1393
     public function switch_payment_method()
1394 1394
     {
1395
-        if (! $this->_verify_payment_method_is_set()) {
1395
+        if ( ! $this->_verify_payment_method_is_set()) {
1396 1396
             return false;
1397 1397
         }
1398 1398
         if (
@@ -1528,7 +1528,7 @@  discard block
 block discarded – undo
1528 1528
             }
1529 1529
         }
1530 1530
         // verify payment method
1531
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1531
+        if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
1532 1532
             // get payment method for selected method of payment
1533 1533
             $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1534 1534
         }
@@ -1553,7 +1553,7 @@  discard block
 block discarded – undo
1553 1553
      */
1554 1554
     public function save_payer_details_via_ajax()
1555 1555
     {
1556
-        if (! $this->_verify_payment_method_is_set()) {
1556
+        if ( ! $this->_verify_payment_method_is_set()) {
1557 1557
             return;
1558 1558
         }
1559 1559
         // generate billing form for selected method of payment if it hasn't been done already
@@ -1563,7 +1563,7 @@  discard block
 block discarded – undo
1563 1563
             );
1564 1564
         }
1565 1565
         // generate primary attendee from payer info if applicable
1566
-        if (! $this->checkout->transaction_has_primary_registrant()) {
1566
+        if ( ! $this->checkout->transaction_has_primary_registrant()) {
1567 1567
             $attendee = $this->_create_attendee_from_request_data();
1568 1568
             if ($attendee instanceof EE_Attendee) {
1569 1569
                 foreach ($this->checkout->transaction->registrations() as $registration) {
@@ -1594,7 +1594,7 @@  discard block
 block discarded – undo
1594 1594
     {
1595 1595
         // get State ID
1596 1596
         $STA_ID = $this->request->getRequestParam('state');
1597
-        if (! empty($STA_ID)) {
1597
+        if ( ! empty($STA_ID)) {
1598 1598
             // can we get state object from name ?
1599 1599
             EE_Registry::instance()->load_model('State');
1600 1600
             $state  = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID');
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
         }
1603 1603
         // get Country ISO
1604 1604
         $CNT_ISO = $this->request->getRequestParam('country');
1605
-        if (! empty($CNT_ISO)) {
1605
+        if ( ! empty($CNT_ISO)) {
1606 1606
             // can we get country object from name ?
1607 1607
             EE_Registry::instance()->load_model('Country');
1608 1608
             $country = EEM_Country::instance()->get_col(
@@ -1849,7 +1849,7 @@  discard block
 block discarded – undo
1849 1849
     private function _process_payment()
1850 1850
     {
1851 1851
         // basically confirm that the event hasn't sold out since they hit the page
1852
-        if (! $this->_last_second_ticket_verifications()) {
1852
+        if ( ! $this->_last_second_ticket_verifications()) {
1853 1853
             return false;
1854 1854
         }
1855 1855
         // ya gotta make a choice man
@@ -1860,7 +1860,7 @@  discard block
 block discarded – undo
1860 1860
             return false;
1861 1861
         }
1862 1862
         // get EE_Payment_Method object
1863
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1863
+        if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1864 1864
             return false;
1865 1865
         }
1866 1866
         // setup billing form
@@ -1869,12 +1869,12 @@  discard block
 block discarded – undo
1869 1869
                 $this->checkout->payment_method
1870 1870
             );
1871 1871
             // bad billing form ?
1872
-            if (! $this->_billing_form_is_valid()) {
1872
+            if ( ! $this->_billing_form_is_valid()) {
1873 1873
                 return false;
1874 1874
             }
1875 1875
         }
1876 1876
         // ensure primary registrant has been fully processed
1877
-        if (! $this->_setup_primary_registrant_prior_to_payment()) {
1877
+        if ( ! $this->_setup_primary_registrant_prior_to_payment()) {
1878 1878
             return false;
1879 1879
         }
1880 1880
         // if session is close to expiring (under 10 minutes by default)
@@ -1925,7 +1925,7 @@  discard block
 block discarded – undo
1925 1925
     protected function _last_second_ticket_verifications()
1926 1926
     {
1927 1927
         // don't bother re-validating if not a return visit
1928
-        if (! $this->checkout->revisit) {
1928
+        if ( ! $this->checkout->revisit) {
1929 1929
             return true;
1930 1930
         }
1931 1931
         $registrations = $this->checkout->transaction->registrations();
@@ -1975,7 +1975,7 @@  discard block
 block discarded – undo
1975 1975
             $this->_get_payment_method_for_selected_method_of_payment()
1976 1976
         );
1977 1977
         $html                        = $payment_method_billing_info->get_html();
1978
-        $html                        .= $this->checkout->redirect_form;
1978
+        $html .= $this->checkout->redirect_form;
1979 1979
         /** @var ResponseInterface $response */
1980 1980
         $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
1981 1981
         $response->addOutput($html);
@@ -1991,7 +1991,7 @@  discard block
 block discarded – undo
1991 1991
      */
1992 1992
     private function _billing_form_is_valid()
1993 1993
     {
1994
-        if (! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1994
+        if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1995 1995
             return true;
1996 1996
         }
1997 1997
         if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
@@ -2109,7 +2109,7 @@  discard block
 block discarded – undo
2109 2109
     {
2110 2110
         // convert billing form data into an attendee
2111 2111
         $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
2112
-        if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2112
+        if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2113 2113
             EE_Error::add_error(
2114 2114
                 sprintf(
2115 2115
                     esc_html__(
@@ -2126,7 +2126,7 @@  discard block
 block discarded – undo
2126 2126
             return false;
2127 2127
         }
2128 2128
         $primary_registration = $this->checkout->transaction->primary_registration();
2129
-        if (! $primary_registration instanceof EE_Registration) {
2129
+        if ( ! $primary_registration instanceof EE_Registration) {
2130 2130
             EE_Error::add_error(
2131 2131
                 sprintf(
2132 2132
                     esc_html__(
@@ -2188,8 +2188,8 @@  discard block
 block discarded – undo
2188 2188
             return null;
2189 2189
         }
2190 2190
         // get EE_Payment_Method object
2191
-        if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) {
2192
-            $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
2191
+        if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) {
2192
+            $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment];
2193 2193
         } else {
2194 2194
             // load EEM_Payment_Method
2195 2195
             EE_Registry::instance()->load_model('Payment_Method');
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
             $payment_method     = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2198 2198
         }
2199 2199
         // verify $payment_method
2200
-        if (! $payment_method instanceof EE_Payment_Method) {
2200
+        if ( ! $payment_method instanceof EE_Payment_Method) {
2201 2201
             // not a payment
2202 2202
             EE_Error::add_error(
2203 2203
                 sprintf(
@@ -2215,7 +2215,7 @@  discard block
 block discarded – undo
2215 2215
             return null;
2216 2216
         }
2217 2217
         // and verify it has a valid Payment_Method Type object
2218
-        if (! $payment_method->type_obj() instanceof EE_PMT_Base) {
2218
+        if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) {
2219 2219
             // not a payment
2220 2220
             EE_Error::add_error(
2221 2221
                 sprintf(
@@ -2253,7 +2253,7 @@  discard block
 block discarded – undo
2253 2253
         $payment = null;
2254 2254
         $this->checkout->transaction->save();
2255 2255
         $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2256
-        if (! $payment_processor instanceof EE_Payment_Processor) {
2256
+        if ( ! $payment_processor instanceof EE_Payment_Processor) {
2257 2257
             return false;
2258 2258
         }
2259 2259
         try {
@@ -2355,7 +2355,7 @@  discard block
 block discarded – undo
2355 2355
             return true;
2356 2356
         }
2357 2357
         // verify payment object
2358
-        if (! $payment instanceof EE_Payment) {
2358
+        if ( ! $payment instanceof EE_Payment) {
2359 2359
             // not a payment
2360 2360
             EE_Error::add_error(
2361 2361
                 sprintf(
@@ -2395,7 +2395,7 @@  discard block
 block discarded – undo
2395 2395
             return true;
2396 2396
             // On-Site payment?
2397 2397
         } elseif ($this->checkout->payment_method->is_on_site()) {
2398
-            if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2398
+            if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2399 2399
                 // $this->_setup_redirect_for_next_step();
2400 2400
                 $this->checkout->continue_reg = false;
2401 2401
             }
@@ -2423,7 +2423,7 @@  discard block
 block discarded – undo
2423 2423
                     EE_Registry::instance()->CFG->organization->get_pretty('email')
2424 2424
                 );
2425 2425
                 if ($payment instanceof EE_Payment && $payment->gateway_response()) {
2426
-                    $error_message = $error_message . '<br/>' . $payment->gateway_response();
2426
+                    $error_message = $error_message.'<br/>'.$payment->gateway_response();
2427 2427
                 }
2428 2428
                 $this->checkout->continue_reg = false;
2429 2429
                 EE_Error::add_error(
@@ -2510,7 +2510,7 @@  discard block
 block discarded – undo
2510 2510
                     return false;
2511 2511
                 // bad payment
2512 2512
                 case EEM_Payment::status_id_failed:
2513
-                    if (! empty($msg)) {
2513
+                    if ( ! empty($msg)) {
2514 2514
                         EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2515 2515
                         return false;
2516 2516
                     }
@@ -2568,18 +2568,18 @@  discard block
 block discarded – undo
2568 2568
         // how have they chosen to pay?
2569 2569
         $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2570 2570
         // get EE_Payment_Method object
2571
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2571
+        if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2572 2572
             $this->checkout->continue_reg = false;
2573 2573
             return false;
2574 2574
         }
2575
-        if (! $this->checkout->payment_method->is_off_site()) {
2575
+        if ( ! $this->checkout->payment_method->is_off_site()) {
2576 2576
             return false;
2577 2577
         }
2578 2578
         $this->_validate_offsite_return();
2579 2579
         // verify TXN
2580 2580
         if ($this->checkout->transaction instanceof EE_Transaction) {
2581 2581
             $gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2582
-            if (! $gateway instanceof EE_Offsite_Gateway) {
2582
+            if ( ! $gateway instanceof EE_Offsite_Gateway) {
2583 2583
                 $this->checkout->continue_reg = false;
2584 2584
                 return false;
2585 2585
             }
@@ -2593,7 +2593,7 @@  discard block
 block discarded – undo
2593 2593
                 $this->checkout->payment = $payment;
2594 2594
                 // mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2595 2595
                 // because we will complete this step during the IPN processing then
2596
-                if (! $this->handle_IPN_in_this_request()) {
2596
+                if ( ! $this->handle_IPN_in_this_request()) {
2597 2597
                     $this->set_completed();
2598 2598
                 }
2599 2599
                 return true;
@@ -2696,13 +2696,13 @@  discard block
 block discarded – undo
2696 2696
      */
2697 2697
     private function _redirect_wayward_request(EE_Registration $primary_registrant)
2698 2698
     {
2699
-        if (! $primary_registrant instanceof EE_Registration) {
2699
+        if ( ! $primary_registrant instanceof EE_Registration) {
2700 2700
             // try redirecting based on the current TXN
2701 2701
             $primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2702 2702
                 ? $this->checkout->transaction->primary_registration()
2703 2703
                 : null;
2704 2704
         }
2705
-        if (! $primary_registrant instanceof EE_Registration) {
2705
+        if ( ! $primary_registrant instanceof EE_Registration) {
2706 2706
             EE_Error::add_error(
2707 2707
                 sprintf(
2708 2708
                     esc_html__(
@@ -2773,7 +2773,7 @@  discard block
 block discarded – undo
2773 2773
             $payment = $this->checkout->transaction->last_payment();
2774 2774
             // $payment_source = 'last_payment after Exception';
2775 2775
             // but if we STILL don't have a payment object
2776
-            if (! $payment instanceof EE_Payment) {
2776
+            if ( ! $payment instanceof EE_Payment) {
2777 2777
                 // then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2778 2778
                 $this->_handle_payment_processor_exception($e);
2779 2779
             }
Please login to merge, or discard this patch.
Indentation   +2856 added lines, -2856 removed lines patch added patch discarded remove patch
@@ -19,2860 +19,2860 @@
 block discarded – undo
19 19
  */
20 20
 class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step
21 21
 {
22
-    /**
23
-     * @var EE_Line_Item_Display $Line_Item_Display
24
-     */
25
-    protected $line_item_display;
26
-
27
-    /**
28
-     * @var boolean $handle_IPN_in_this_request
29
-     */
30
-    protected $handle_IPN_in_this_request = false;
31
-
32
-
33
-    /**
34
-     *    set_hooks - for hooking into EE Core, other modules, etc
35
-     *
36
-     * @access    public
37
-     * @return    void
38
-     */
39
-    public static function set_hooks()
40
-    {
41
-        add_filter(
42
-            'FHEE__SPCO__EE_Line_Item_Filter_Collection',
43
-            ['EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters']
44
-        );
45
-        add_action(
46
-            'wp_ajax_switch_spco_billing_form',
47
-            ['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form']
48
-        );
49
-        add_action(
50
-            'wp_ajax_nopriv_switch_spco_billing_form',
51
-            ['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form']
52
-        );
53
-        add_action('wp_ajax_save_payer_details', ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']);
54
-        add_action(
55
-            'wp_ajax_nopriv_save_payer_details',
56
-            ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']
57
-        );
58
-        add_action(
59
-            'wp_ajax_get_transaction_details_for_gateways',
60
-            ['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details']
61
-        );
62
-        add_action(
63
-            'wp_ajax_nopriv_get_transaction_details_for_gateways',
64
-            ['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details']
65
-        );
66
-        add_filter(
67
-            'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
68
-            ['EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'],
69
-            10,
70
-            1
71
-        );
72
-    }
73
-
74
-
75
-    /**
76
-     *    ajax switch_spco_billing_form
77
-     *
78
-     */
79
-    public static function switch_spco_billing_form()
80
-    {
81
-        EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
82
-    }
83
-
84
-
85
-    /**
86
-     *    ajax save_payer_details
87
-     *
88
-     */
89
-    public static function save_payer_details()
90
-    {
91
-        EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
92
-    }
93
-
94
-
95
-    /**
96
-     *    ajax get_transaction_details
97
-     *
98
-     */
99
-    public static function get_transaction_details()
100
-    {
101
-        EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
102
-    }
103
-
104
-
105
-    /**
106
-     * bypass_recaptcha_for_load_payment_method
107
-     *
108
-     * @access public
109
-     * @return array
110
-     * @throws InvalidArgumentException
111
-     * @throws InvalidDataTypeException
112
-     * @throws InvalidInterfaceException
113
-     */
114
-    public static function bypass_recaptcha_for_load_payment_method()
115
-    {
116
-        return [
117
-            'EESID'  => EE_Registry::instance()->SSN->id(),
118
-            'step'   => 'payment_options',
119
-            'action' => 'spco_billing_form',
120
-        ];
121
-    }
122
-
123
-
124
-    /**
125
-     *    class constructor
126
-     *
127
-     * @access    public
128
-     * @param EE_Checkout $checkout
129
-     */
130
-    public function __construct(EE_Checkout $checkout)
131
-    {
132
-        $this->request   = EED_Single_Page_Checkout::getRequest();
133
-        $this->_slug     = 'payment_options';
134
-        $this->_name     = esc_html__('Payment Options', 'event_espresso');
135
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php';
136
-        $this->checkout  = $checkout;
137
-        $this->_reset_success_message();
138
-        $this->set_instructions(
139
-            esc_html__(
140
-                'Please select a method of payment and provide any necessary billing information before proceeding.',
141
-                'event_espresso'
142
-            )
143
-        );
144
-    }
145
-
146
-
147
-    /**
148
-     * @return null
149
-     */
150
-    public function line_item_display()
151
-    {
152
-        return $this->line_item_display;
153
-    }
154
-
155
-
156
-    /**
157
-     * @param null $line_item_display
158
-     */
159
-    public function set_line_item_display($line_item_display)
160
-    {
161
-        $this->line_item_display = $line_item_display;
162
-    }
163
-
164
-
165
-    /**
166
-     * @return boolean
167
-     */
168
-    public function handle_IPN_in_this_request()
169
-    {
170
-        return $this->handle_IPN_in_this_request;
171
-    }
172
-
173
-
174
-    /**
175
-     * @param boolean $handle_IPN_in_this_request
176
-     */
177
-    public function set_handle_IPN_in_this_request($handle_IPN_in_this_request)
178
-    {
179
-        $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
180
-    }
181
-
182
-
183
-    /**
184
-     * translate_js_strings
185
-     *
186
-     * @return void
187
-     */
188
-    public function translate_js_strings()
189
-    {
190
-        EE_Registry::$i18n_js_strings['no_payment_method']      = esc_html__(
191
-            'Please select a method of payment in order to continue.',
192
-            'event_espresso'
193
-        );
194
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
195
-            'A valid method of payment could not be determined. Please refresh the page and try again.',
196
-            'event_espresso'
197
-        );
198
-        EE_Registry::$i18n_js_strings['forwarding_to_offsite']  = esc_html__(
199
-            'Forwarding to Secure Payment Provider.',
200
-            'event_espresso'
201
-        );
202
-    }
203
-
204
-
205
-    /**
206
-     * enqueue_styles_and_scripts
207
-     *
208
-     * @return void
209
-     * @throws EE_Error
210
-     * @throws InvalidArgumentException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidInterfaceException
213
-     * @throws ReflectionException
214
-     */
215
-    public function enqueue_styles_and_scripts()
216
-    {
217
-        $transaction = $this->checkout->transaction;
218
-        // if the transaction isn't set or nothing is owed on it, don't enqueue any JS
219
-        if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
220
-            return;
221
-        }
222
-        foreach (
223
-            EEM_Payment_Method::instance()->get_all_for_transaction(
224
-                $transaction,
225
-                EEM_Payment_Method::scope_cart
226
-            ) as $payment_method
227
-        ) {
228
-            $type_obj = $payment_method->type_obj();
229
-            if ($type_obj instanceof EE_PMT_Base) {
230
-                $billing_form = $type_obj->generate_new_billing_form($transaction);
231
-                if ($billing_form instanceof EE_Form_Section_Proper) {
232
-                    $billing_form->enqueue_js();
233
-                }
234
-            }
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * initialize_reg_step
241
-     *
242
-     * @return bool
243
-     * @throws EE_Error
244
-     * @throws InvalidArgumentException
245
-     * @throws ReflectionException
246
-     * @throws InvalidDataTypeException
247
-     * @throws InvalidInterfaceException
248
-     */
249
-    public function initialize_reg_step()
250
-    {
251
-        // TODO: if /when we implement donations, then this will need overriding
252
-        if (
253
-            // don't need payment options for:
254
-            // registrations made via the admin
255
-            // completed transactions
256
-            // overpaid transactions
257
-            // $ 0.00 transactions(no payment required)
258
-            ! $this->checkout->payment_required()
259
-            // but do NOT remove if current action being called belongs to this reg step
260
-            && ! is_callable([$this, $this->checkout->action])
261
-            && ! $this->completed()
262
-        ) {
263
-            // and if so, then we no longer need the Payment Options step
264
-            if ($this->is_current_step()) {
265
-                $this->checkout->generate_reg_form = false;
266
-            }
267
-            $this->checkout->remove_reg_step($this->_slug);
268
-            // DEBUG LOG
269
-            // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
270
-            return false;
271
-        }
272
-        // load EEM_Payment_Method
273
-        EE_Registry::instance()->load_model('Payment_Method');
274
-        // get all active payment methods
275
-        $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
276
-            $this->checkout->transaction,
277
-            EEM_Payment_Method::scope_cart
278
-        );
279
-        return true;
280
-    }
281
-
282
-
283
-    /**
284
-     * @return EE_Form_Section_Proper
285
-     * @throws EE_Error
286
-     * @throws InvalidArgumentException
287
-     * @throws ReflectionException
288
-     * @throws EntityNotFoundException
289
-     * @throws InvalidDataTypeException
290
-     * @throws InvalidInterfaceException
291
-     * @throws InvalidStatusException
292
-     */
293
-    public function generate_reg_form()
294
-    {
295
-        // reset in case someone changes their mind
296
-        $this->_reset_selected_method_of_payment();
297
-        // set some defaults
298
-        $this->checkout->selected_method_of_payment = 'payments_closed';
299
-        $registrations_requiring_payment            = [];
300
-        $registrations_for_free_events              = [];
301
-        $registrations_requiring_pre_approval       = [];
302
-        $sold_out_events                            = [];
303
-        $insufficient_spaces_available              = [];
304
-        $no_payment_required                        = true;
305
-        // loop thru registrations to gather info
306
-        $registrations         = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
307
-        $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
308
-            $registrations,
309
-            $this->checkout->revisit
310
-        );
311
-        foreach ($registrations as $REG_ID => $registration) {
312
-            /** @var $registration EE_Registration */
313
-            // has this registration lost it's space ?
314
-            if (isset($ejected_registrations[ $REG_ID ])) {
315
-                if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) {
316
-                    $sold_out_events[ $registration->event()->ID() ] = $registration->event();
317
-                } else {
318
-                    $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
319
-                }
320
-                continue;
321
-            }
322
-            // event requires admin approval
323
-            if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
324
-                // add event to list of events with pre-approval reg status
325
-                $registrations_requiring_pre_approval[ $REG_ID ] = $registration;
326
-                do_action(
327
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
328
-                    $registration->event(),
329
-                    $this
330
-                );
331
-                continue;
332
-            }
333
-            if (
334
-                $this->checkout->revisit
335
-                && $registration->status_ID() !== EEM_Registration::status_id_approved
336
-                && (
337
-                    $registration->event()->is_sold_out()
338
-                    || $registration->event()->is_sold_out(true)
339
-                )
340
-            ) {
341
-                // add event to list of events that are sold out
342
-                $sold_out_events[ $registration->event()->ID() ] = $registration->event();
343
-                do_action(
344
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
345
-                    $registration->event(),
346
-                    $this
347
-                );
348
-                continue;
349
-            }
350
-            // are they allowed to pay now and is there monies owing?
351
-            if ($registration->owes_monies_and_can_pay()) {
352
-                $registrations_requiring_payment[ $REG_ID ] = $registration;
353
-                do_action(
354
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
355
-                    $registration->event(),
356
-                    $this
357
-                );
358
-            } elseif (
359
-                ! $this->checkout->revisit
360
-                      && $registration->status_ID() !== EEM_Registration::status_id_not_approved
361
-                      && $registration->ticket()->is_free()
362
-            ) {
363
-                $registrations_for_free_events[ $registration->ticket()->ID() ] = $registration;
364
-            }
365
-        }
366
-        $subsections = [];
367
-        // now decide which template to load
368
-        if (! empty($sold_out_events)) {
369
-            $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
370
-        }
371
-        if (! empty($insufficient_spaces_available)) {
372
-            $subsections['insufficient_space'] = $this->_insufficient_spaces_available(
373
-                $insufficient_spaces_available
374
-            );
375
-        }
376
-        if (! empty($registrations_requiring_pre_approval)) {
377
-            $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
378
-                $registrations_requiring_pre_approval
379
-            );
380
-        }
381
-        if (! empty($registrations_for_free_events)) {
382
-            $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
383
-        }
384
-        if (! empty($registrations_requiring_payment)) {
385
-            if ($this->checkout->amount_owing > 0) {
386
-                // autoload Line_Item_Display classes
387
-                EEH_Autoloader::register_line_item_filter_autoloaders();
388
-                $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
389
-                    apply_filters(
390
-                        'FHEE__SPCO__EE_Line_Item_Filter_Collection',
391
-                        new EE_Line_Item_Filter_Collection()
392
-                    ),
393
-                    $this->checkout->cart->get_grand_total()
394
-                );
395
-                /** @var EE_Line_Item $filtered_line_item_tree */
396
-                $filtered_line_item_tree = $line_item_filter_processor->process();
397
-                EEH_Autoloader::register_line_item_display_autoloaders();
398
-                $this->set_line_item_display(new EE_Line_Item_Display('spco'));
399
-                $subsections['payment_options'] = $this->_display_payment_options(
400
-                    $this->line_item_display->display_line_item(
401
-                        $filtered_line_item_tree,
402
-                        ['registrations' => $registrations]
403
-                    )
404
-                );
405
-                $this->checkout->amount_owing   = $filtered_line_item_tree->total();
406
-                $this->_apply_registration_payments_to_amount_owing($registrations);
407
-            }
408
-            $no_payment_required = false;
409
-        } else {
410
-            $this->_hide_reg_step_submit_button_if_revisit();
411
-        }
412
-        $this->_save_selected_method_of_payment();
413
-
414
-        $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
415
-        $subsections['extra_hidden_inputs']   = $this->_extra_hidden_inputs($no_payment_required);
416
-
417
-        return new EE_Form_Section_Proper(
418
-            [
419
-                'name'            => $this->reg_form_name(),
420
-                'html_id'         => $this->reg_form_name(),
421
-                'subsections'     => $subsections,
422
-                'layout_strategy' => new EE_No_Layout(),
423
-            ]
424
-        );
425
-    }
426
-
427
-
428
-    /**
429
-     * add line item filters required for this reg step
430
-     * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks():
431
-     *        add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options',
432
-     *        'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the
433
-     *        payment options reg step, can apply these filters via the following: apply_filters(
434
-     *        'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing
435
-     *        filter collection by passing that instead of instantiating a new collection
436
-     *
437
-     * @param EE_Line_Item_Filter_Collection $line_item_filter_collection
438
-     * @return EE_Line_Item_Filter_Collection
439
-     * @throws EE_Error
440
-     * @throws InvalidArgumentException
441
-     * @throws ReflectionException
442
-     * @throws EntityNotFoundException
443
-     * @throws InvalidDataTypeException
444
-     * @throws InvalidInterfaceException
445
-     * @throws InvalidStatusException
446
-     */
447
-    public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection)
448
-    {
449
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
450
-            return $line_item_filter_collection;
451
-        }
452
-        if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
453
-            return $line_item_filter_collection;
454
-        }
455
-        if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
456
-            return $line_item_filter_collection;
457
-        }
458
-        $line_item_filter_collection->add(
459
-            new EE_Billable_Line_Item_Filter(
460
-                EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations(
461
-                    EE_Registry::instance()->SSN->checkout()->transaction->registrations(
462
-                        EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
463
-                    )
464
-                )
465
-            )
466
-        );
467
-        $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
468
-        return $line_item_filter_collection;
469
-    }
470
-
471
-
472
-    /**
473
-     * remove_ejected_registrations
474
-     * if a registrant has lost their potential space at an event due to lack of payment,
475
-     * then this method removes them from the list of registrations being paid for during this request
476
-     *
477
-     * @param EE_Registration[] $registrations
478
-     * @return EE_Registration[]
479
-     * @throws EE_Error
480
-     * @throws InvalidArgumentException
481
-     * @throws ReflectionException
482
-     * @throws EntityNotFoundException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     * @throws InvalidStatusException
486
-     */
487
-    public static function remove_ejected_registrations(array $registrations)
488
-    {
489
-        $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
490
-            $registrations,
491
-            EE_Registry::instance()->SSN->checkout()->revisit
492
-        );
493
-        foreach ($registrations as $REG_ID => $registration) {
494
-            // has this registration lost it's space ?
495
-            if (isset($ejected_registrations[ $REG_ID ])) {
496
-                unset($registrations[ $REG_ID ]);
497
-            }
498
-        }
499
-        return $registrations;
500
-    }
501
-
502
-
503
-    /**
504
-     * find_registrations_that_lost_their_space
505
-     * If a registrant chooses an offline payment method like Invoice,
506
-     * then no space is reserved for them at the event until they fully pay fo that site
507
-     * (unless the event's default reg status is set to APPROVED)
508
-     * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales,
509
-     * then this method will determine which registrations have lost the ability to complete the reg process.
510
-     *
511
-     * @param EE_Registration[] $registrations
512
-     * @param bool              $revisit
513
-     * @return array
514
-     * @throws EE_Error
515
-     * @throws InvalidArgumentException
516
-     * @throws ReflectionException
517
-     * @throws EntityNotFoundException
518
-     * @throws InvalidDataTypeException
519
-     * @throws InvalidInterfaceException
520
-     * @throws InvalidStatusException
521
-     */
522
-    public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false)
523
-    {
524
-        // registrations per event
525
-        $event_reg_count = [];
526
-        // spaces left per event
527
-        $event_spaces_remaining = [];
528
-        // tickets left sorted by ID
529
-        $tickets_remaining = [];
530
-        // registrations that have lost their space
531
-        $ejected_registrations = [];
532
-        foreach ($registrations as $REG_ID => $registration) {
533
-            if (
534
-                $registration->status_ID() === EEM_Registration::status_id_approved
535
-                || apply_filters(
536
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
537
-                    false,
538
-                    $registration,
539
-                    $revisit
540
-                )
541
-            ) {
542
-                continue;
543
-            }
544
-            $EVT_ID = $registration->event_ID();
545
-            $ticket = $registration->ticket();
546
-            if (! isset($tickets_remaining[ $ticket->ID() ])) {
547
-                $tickets_remaining[ $ticket->ID() ] = $ticket->remaining();
548
-            }
549
-            if ($tickets_remaining[ $ticket->ID() ] > 0) {
550
-                if (! isset($event_reg_count[ $EVT_ID ])) {
551
-                    $event_reg_count[ $EVT_ID ] = 0;
552
-                }
553
-                $event_reg_count[ $EVT_ID ]++;
554
-                if (! isset($event_spaces_remaining[ $EVT_ID ])) {
555
-                    $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale();
556
-                }
557
-            }
558
-            if (
559
-                $revisit
560
-                && ($tickets_remaining[ $ticket->ID() ] === 0
561
-                    || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
562
-                )
563
-            ) {
564
-                $ejected_registrations[ $REG_ID ] = $registration->event();
565
-                if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
566
-                    /** @type EE_Registration_Processor $registration_processor */
567
-                    $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
568
-                    // at this point, we should have enough details about the registrant to consider the registration
569
-                    // NOT incomplete
570
-                    $registration_processor->manually_update_registration_status(
571
-                        $registration,
572
-                        EEM_Registration::status_id_wait_list
573
-                    );
574
-                }
575
-            }
576
-        }
577
-        return $ejected_registrations;
578
-    }
579
-
580
-
581
-    /**
582
-     * _hide_reg_step_submit_button
583
-     * removes the html for the reg step submit button
584
-     * by replacing it with an empty string via filter callback
585
-     *
586
-     * @return void
587
-     */
588
-    protected function _adjust_registration_status_if_event_old_sold()
589
-    {
590
-    }
591
-
592
-
593
-    /**
594
-     * _hide_reg_step_submit_button
595
-     * removes the html for the reg step submit button
596
-     * by replacing it with an empty string via filter callback
597
-     *
598
-     * @return void
599
-     */
600
-    protected function _hide_reg_step_submit_button_if_revisit()
601
-    {
602
-        if ($this->checkout->revisit) {
603
-            add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
604
-        }
605
-    }
606
-
607
-
608
-    /**
609
-     * sold_out_events
610
-     * displays notices regarding events that have sold out since hte registrant first signed up
611
-     *
612
-     * @param EE_Event[] $sold_out_events_array
613
-     * @return EE_Form_Section_Proper
614
-     * @throws EE_Error
615
-     */
616
-    private function _sold_out_events($sold_out_events_array = [])
617
-    {
618
-        // set some defaults
619
-        $this->checkout->selected_method_of_payment = 'events_sold_out';
620
-        $sold_out_events                            = '';
621
-        foreach ($sold_out_events_array as $sold_out_event) {
622
-            $sold_out_events .= EEH_HTML::li(
623
-                EEH_HTML::span(
624
-                    '  ' . $sold_out_event->name(),
625
-                    '',
626
-                    'dashicons dashicons-marker ee-icon-size-16 pink-text'
627
-                )
628
-            );
629
-        }
630
-        return new EE_Form_Section_Proper(
631
-            [
632
-                'layout_strategy' => new EE_Template_Layout(
633
-                    [
634
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
635
-                                                  . $this->_slug
636
-                                                  . '/sold_out_events.template.php',
637
-                        'template_args'        => apply_filters(
638
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
639
-                            [
640
-                                'sold_out_events'     => $sold_out_events,
641
-                                'sold_out_events_msg' => apply_filters(
642
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
643
-                                    sprintf(
644
-                                        esc_html__(
645
-                                            'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s',
646
-                                            'event_espresso'
647
-                                        ),
648
-                                        '<strong>',
649
-                                        '</strong>',
650
-                                        '<br />'
651
-                                    )
652
-                                ),
653
-                            ]
654
-                        ),
655
-                    ]
656
-                ),
657
-            ]
658
-        );
659
-    }
660
-
661
-
662
-    /**
663
-     * _insufficient_spaces_available
664
-     * displays notices regarding events that do not have enough remaining spaces
665
-     * to satisfy the current number of registrations looking to pay
666
-     *
667
-     * @param EE_Event[] $insufficient_spaces_events_array
668
-     * @return EE_Form_Section_Proper
669
-     * @throws EE_Error
670
-     * @throws ReflectionException
671
-     */
672
-    private function _insufficient_spaces_available($insufficient_spaces_events_array = [])
673
-    {
674
-        // set some defaults
675
-        $this->checkout->selected_method_of_payment = 'invoice';
676
-        $insufficient_space_events                  = '';
677
-        foreach ($insufficient_spaces_events_array as $event) {
678
-            if ($event instanceof EE_Event) {
679
-                $insufficient_space_events .= EEH_HTML::li(
680
-                    EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
681
-                );
682
-            }
683
-        }
684
-        return new EE_Form_Section_Proper(
685
-            [
686
-                'subsections'     => [
687
-                    'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
688
-                    'extra_hidden_inputs'   => $this->_extra_hidden_inputs(),
689
-                ],
690
-                'layout_strategy' => new EE_Template_Layout(
691
-                    [
692
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
693
-                                                  . $this->_slug
694
-                                                  . '/sold_out_events.template.php',
695
-                        'template_args'        => apply_filters(
696
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args',
697
-                            [
698
-                                'sold_out_events'     => $insufficient_space_events,
699
-                                'sold_out_events_msg' => apply_filters(
700
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg',
701
-                                    esc_html__(
702
-                                        'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
703
-                                        'event_espresso'
704
-                                    )
705
-                                ),
706
-                            ]
707
-                        ),
708
-                    ]
709
-                ),
710
-            ]
711
-        );
712
-    }
713
-
714
-
715
-    /**
716
-     * registrations_requiring_pre_approval
717
-     *
718
-     * @param array $registrations_requiring_pre_approval
719
-     * @return EE_Form_Section_Proper
720
-     * @throws EE_Error
721
-     * @throws EntityNotFoundException
722
-     * @throws ReflectionException
723
-     */
724
-    private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = [])
725
-    {
726
-        $events_requiring_pre_approval = [];
727
-        foreach ($registrations_requiring_pre_approval as $registration) {
728
-            if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
729
-                $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
730
-                    EEH_HTML::span(
731
-                        '',
732
-                        '',
733
-                        'dashicons dashicons-marker ee-icon-size-16 orange-text'
734
-                    )
735
-                    . EEH_HTML::span($registration->event()->name(), '', 'orange-text')
736
-                );
737
-            }
738
-        }
739
-        return new EE_Form_Section_Proper(
740
-            [
741
-                'layout_strategy' => new EE_Template_Layout(
742
-                    [
743
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
744
-                                                  . $this->_slug
745
-                                                  . '/events_requiring_pre_approval.template.php', // layout_template
746
-                        'template_args'        => apply_filters(
747
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
748
-                            [
749
-                                'events_requiring_pre_approval'     => implode('', $events_requiring_pre_approval),
750
-                                'events_requiring_pre_approval_msg' => apply_filters(
751
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
752
-                                    esc_html__(
753
-                                        'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
754
-                                        'event_espresso'
755
-                                    )
756
-                                ),
757
-                            ]
758
-                        ),
759
-                    ]
760
-                ),
761
-            ]
762
-        );
763
-    }
764
-
765
-
766
-    /**
767
-     * _no_payment_required
768
-     *
769
-     * @param EE_Event[] $registrations_for_free_events
770
-     * @return EE_Form_Section_Proper
771
-     * @throws EE_Error
772
-     */
773
-    private function _no_payment_required($registrations_for_free_events = [])
774
-    {
775
-        // set some defaults
776
-        $this->checkout->selected_method_of_payment = 'no_payment_required';
777
-        // generate no_payment_required form
778
-        return new EE_Form_Section_Proper(
779
-            [
780
-                'layout_strategy' => new EE_Template_Layout(
781
-                    [
782
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
783
-                                                  . $this->_slug
784
-                                                  . '/no_payment_required.template.php', // layout_template
785
-                        'template_args'        => apply_filters(
786
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
787
-                            [
788
-                                'revisit'                       => $this->checkout->revisit,
789
-                                'registrations'                 => [],
790
-                                'ticket_count'                  => [],
791
-                                'registrations_for_free_events' => $registrations_for_free_events,
792
-                                'no_payment_required_msg'       => EEH_HTML::p(
793
-                                    esc_html__('This is a free event, so no billing will occur.', 'event_espresso')
794
-                                ),
795
-                            ]
796
-                        ),
797
-                    ]
798
-                ),
799
-            ]
800
-        );
801
-    }
802
-
803
-
804
-    /**
805
-     * _display_payment_options
806
-     *
807
-     * @param string $transaction_details
808
-     * @return EE_Form_Section_Proper
809
-     * @throws EE_Error
810
-     * @throws InvalidArgumentException
811
-     * @throws InvalidDataTypeException
812
-     * @throws InvalidInterfaceException
813
-     */
814
-    private function _display_payment_options($transaction_details = '')
815
-    {
816
-        // has method_of_payment been set by no-js user?
817
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
818
-        // build payment options form
819
-        return apply_filters(
820
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form',
821
-            new EE_Form_Section_Proper(
822
-                [
823
-                    'subsections'     => [
824
-                        'before_payment_options' => apply_filters(
825
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
826
-                            new EE_Form_Section_Proper(
827
-                                ['layout_strategy' => new EE_Div_Per_Section_Layout()]
828
-                            )
829
-                        ),
830
-                        'payment_options'        => $this->_setup_payment_options(),
831
-                        'after_payment_options'  => apply_filters(
832
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
833
-                            new EE_Form_Section_Proper(
834
-                                ['layout_strategy' => new EE_Div_Per_Section_Layout()]
835
-                            )
836
-                        ),
837
-                    ],
838
-                    'layout_strategy' => new EE_Template_Layout(
839
-                        [
840
-                            'layout_template_file' => $this->_template,
841
-                            'template_args'        => apply_filters(
842
-                                'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args',
843
-                                [
844
-                                    'reg_count'                 => $this->line_item_display->total_items(),
845
-                                    'transaction_details'       => $transaction_details,
846
-                                    'available_payment_methods' => [],
847
-                                ]
848
-                            ),
849
-                        ]
850
-                    ),
851
-                ]
852
-            )
853
-        );
854
-    }
855
-
856
-
857
-    /**
858
-     * _extra_hidden_inputs
859
-     *
860
-     * @param bool $no_payment_required
861
-     * @return EE_Form_Section_Proper
862
-     * @throws EE_Error
863
-     * @throws ReflectionException
864
-     */
865
-    private function _extra_hidden_inputs($no_payment_required = true)
866
-    {
867
-        return new EE_Form_Section_Proper(
868
-            [
869
-                'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
870
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
871
-                'subsections'     => [
872
-                    'spco_no_payment_required' => new EE_Hidden_Input(
873
-                        [
874
-                            'normalization_strategy' => new EE_Boolean_Normalization(),
875
-                            'html_name'              => 'spco_no_payment_required',
876
-                            'html_id'                => 'spco-no-payment-required-payment_options',
877
-                            'default'                => $no_payment_required,
878
-                        ]
879
-                    ),
880
-                    'spco_transaction_id'      => new EE_Fixed_Hidden_Input(
881
-                        [
882
-                            'normalization_strategy' => new EE_Int_Normalization(),
883
-                            'html_name'              => 'spco_transaction_id',
884
-                            'html_id'                => 'spco-transaction-id',
885
-                            'default'                => $this->checkout->transaction->ID(),
886
-                        ]
887
-                    ),
888
-                ],
889
-            ]
890
-        );
891
-    }
892
-
893
-
894
-    /**
895
-     *    _apply_registration_payments_to_amount_owing
896
-     *
897
-     * @param array $registrations
898
-     * @throws EE_Error
899
-     */
900
-    protected function _apply_registration_payments_to_amount_owing(array $registrations)
901
-    {
902
-        $payments = [];
903
-        foreach ($registrations as $registration) {
904
-            if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
905
-                $payments += $registration->registration_payments();
906
-            }
907
-        }
908
-        if (! empty($payments)) {
909
-            foreach ($payments as $payment) {
910
-                if ($payment instanceof EE_Registration_Payment) {
911
-                    $this->checkout->amount_owing -= $payment->amount();
912
-                }
913
-            }
914
-        }
915
-    }
916
-
917
-
918
-    /**
919
-     *    _reset_selected_method_of_payment
920
-     *
921
-     * @access    private
922
-     * @param bool $force_reset
923
-     * @return void
924
-     * @throws InvalidArgumentException
925
-     * @throws InvalidDataTypeException
926
-     * @throws InvalidInterfaceException
927
-     */
928
-    private function _reset_selected_method_of_payment($force_reset = false)
929
-    {
930
-        /** @var RequestInterface $request */
931
-        $request              = LoaderFactory::getLoader()->getShared(RequestInterface::class);
932
-        $reset_payment_method = $request->getRequestParam('reset_payment_method', $force_reset, 'bool');
933
-        if ($reset_payment_method) {
934
-            $this->checkout->selected_method_of_payment = null;
935
-            $this->checkout->payment_method             = null;
936
-            $this->checkout->billing_form               = null;
937
-            $this->_save_selected_method_of_payment();
938
-        }
939
-    }
940
-
941
-
942
-    /**
943
-     * _save_selected_method_of_payment
944
-     * stores the selected_method_of_payment in the session
945
-     * so that it's available for all subsequent requests including AJAX
946
-     *
947
-     * @access        private
948
-     * @param string $selected_method_of_payment
949
-     * @return void
950
-     * @throws InvalidArgumentException
951
-     * @throws InvalidDataTypeException
952
-     * @throws InvalidInterfaceException
953
-     */
954
-    private function _save_selected_method_of_payment($selected_method_of_payment = '')
955
-    {
956
-        $selected_method_of_payment = ! empty($selected_method_of_payment)
957
-            ? $selected_method_of_payment
958
-            : $this->checkout->selected_method_of_payment;
959
-        EE_Registry::instance()->SSN->set_session_data(
960
-            ['selected_method_of_payment' => $selected_method_of_payment]
961
-        );
962
-    }
963
-
964
-
965
-    /**
966
-     * _setup_payment_options
967
-     *
968
-     * @return EE_Form_Section_Proper
969
-     * @throws EE_Error
970
-     * @throws InvalidArgumentException
971
-     * @throws InvalidDataTypeException
972
-     * @throws InvalidInterfaceException
973
-     */
974
-    public function _setup_payment_options()
975
-    {
976
-        // load payment method classes
977
-        $this->checkout->available_payment_methods = $this->_get_available_payment_methods();
978
-        if (empty($this->checkout->available_payment_methods)) {
979
-            EE_Error::add_error(
980
-                apply_filters(
981
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods',
982
-                    sprintf(
983
-                        esc_html__(
984
-                            'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.',
985
-                            'event_espresso'
986
-                        ),
987
-                        '<br>',
988
-                        EE_Registry::instance()->CFG->organization->get_pretty('email')
989
-                    )
990
-                ),
991
-                __FILE__,
992
-                __FUNCTION__,
993
-                __LINE__
994
-            );
995
-        }
996
-        // switch up header depending on number of available payment methods
997
-        $payment_method_header     = count($this->checkout->available_payment_methods) > 1
998
-            ? apply_filters(
999
-                'FHEE__registration_page_payment_options__method_of_payment_hdr',
1000
-                esc_html__('Please Select Your Method of Payment', 'event_espresso')
1001
-            )
1002
-            : apply_filters(
1003
-                'FHEE__registration_page_payment_options__method_of_payment_hdr',
1004
-                esc_html__('Method of Payment', 'event_espresso')
1005
-            );
1006
-        $available_payment_methods = [
1007
-            // display the "Payment Method" header
1008
-            'payment_method_header' => new EE_Form_Section_HTML(
1009
-                apply_filters(
1010
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header',
1011
-                    EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'),
1012
-                    $payment_method_header
1013
-                )
1014
-            ),
1015
-        ];
1016
-        // the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
1017
-        $available_payment_method_options = [];
1018
-        $default_payment_method_option    = [];
1019
-        // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
1020
-        $payment_methods_billing_info = [
1021
-            new EE_Form_Section_HTML(
1022
-                EEH_HTML::div('<br />', '', '', 'clear:both;')
1023
-            ),
1024
-        ];
1025
-        // loop through payment methods
1026
-        foreach ($this->checkout->available_payment_methods as $payment_method) {
1027
-            if ($payment_method instanceof EE_Payment_Method) {
1028
-                $payment_method_button = EEH_HTML::img(
1029
-                    $payment_method->button_url(),
1030
-                    $payment_method->name(),
1031
-                    'spco-payment-method-' . $payment_method->slug() . '-btn-img',
1032
-                    'spco-payment-method-btn-img'
1033
-                );
1034
-                // check if any payment methods are set as default
1035
-                // if payment method is already selected OR nothing is selected and this payment method should be
1036
-                // open_by_default
1037
-                if (
1038
-                    ($this->checkout->selected_method_of_payment === $payment_method->slug())
1039
-                    || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1040
-                ) {
1041
-                    $this->checkout->selected_method_of_payment = $payment_method->slug();
1042
-                    $this->_save_selected_method_of_payment();
1043
-                    $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button;
1044
-                } else {
1045
-                    $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
1046
-                }
1047
-                $payment_methods_billing_info[ $payment_method->slug() . '-info' ] =
1048
-                    $this->_payment_method_billing_info(
1049
-                        $payment_method
1050
-                    );
1051
-            }
1052
-        }
1053
-        // prepend available_payment_method_options with default_payment_method_option so that it appears first in list
1054
-        // of PMs
1055
-        $available_payment_method_options = $default_payment_method_option + $available_payment_method_options;
1056
-        // now generate the actual form  inputs
1057
-        $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs(
1058
-            $available_payment_method_options
1059
-        );
1060
-        $available_payment_methods                              += $payment_methods_billing_info;
1061
-        // build the available payment methods form
1062
-        return new EE_Form_Section_Proper(
1063
-            [
1064
-                'html_id'         => 'spco-available-methods-of-payment-dv',
1065
-                'subsections'     => $available_payment_methods,
1066
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1067
-            ]
1068
-        );
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * _get_available_payment_methods
1074
-     *
1075
-     * @return EE_Payment_Method[]
1076
-     * @throws EE_Error
1077
-     * @throws InvalidArgumentException
1078
-     * @throws InvalidDataTypeException
1079
-     * @throws InvalidInterfaceException
1080
-     */
1081
-    protected function _get_available_payment_methods()
1082
-    {
1083
-        if (! empty($this->checkout->available_payment_methods)) {
1084
-            return $this->checkout->available_payment_methods;
1085
-        }
1086
-        $available_payment_methods = [];
1087
-        $EEM_Payment_Method        = EEM_Payment_Method::instance();
1088
-        // get all active payment methods
1089
-        $payment_methods = $EEM_Payment_Method->get_all_for_transaction(
1090
-            $this->checkout->transaction,
1091
-            EEM_Payment_Method::scope_cart
1092
-        );
1093
-        foreach ($payment_methods as $payment_method) {
1094
-            if ($payment_method instanceof EE_Payment_Method) {
1095
-                $available_payment_methods[ $payment_method->slug() ] = $payment_method;
1096
-            }
1097
-        }
1098
-        return $available_payment_methods;
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     *    _available_payment_method_inputs
1104
-     *
1105
-     * @access    private
1106
-     * @param array $available_payment_method_options
1107
-     * @return    EE_Form_Section_Proper
1108
-     * @throws EE_Error
1109
-     * @throws EE_Error
1110
-     */
1111
-    private function _available_payment_method_inputs($available_payment_method_options = [])
1112
-    {
1113
-        // generate inputs
1114
-        return new EE_Form_Section_Proper(
1115
-            [
1116
-                'html_id'         => 'ee-available-payment-method-inputs',
1117
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1118
-                'subsections'     => [
1119
-                    '' => new EE_Radio_Button_Input(
1120
-                        $available_payment_method_options,
1121
-                        [
1122
-                            'html_name'          => 'selected_method_of_payment',
1123
-                            'html_class'         => 'spco-payment-method',
1124
-                            'default'            => $this->checkout->selected_method_of_payment,
1125
-                            'label_size'         => 11,
1126
-                            'enforce_label_size' => true,
1127
-                        ]
1128
-                    ),
1129
-                ],
1130
-            ]
1131
-        );
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     *    _payment_method_billing_info
1137
-     *
1138
-     * @access    private
1139
-     * @param EE_Payment_Method $payment_method
1140
-     * @return EE_Form_Section_Proper
1141
-     * @throws EE_Error
1142
-     * @throws InvalidArgumentException
1143
-     * @throws InvalidDataTypeException
1144
-     * @throws InvalidInterfaceException
1145
-     */
1146
-    private function _payment_method_billing_info(EE_Payment_Method $payment_method)
1147
-    {
1148
-        $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug();
1149
-        // generate the billing form for payment method
1150
-        $billing_form                 = $currently_selected
1151
-            ? $this->_get_billing_form_for_payment_method($payment_method)
1152
-            : new EE_Form_Section_HTML();
1153
-        $this->checkout->billing_form = $currently_selected
1154
-            ? $billing_form
1155
-            : $this->checkout->billing_form;
1156
-        // it's all in the details
1157
-        $info_html = EEH_HTML::h3(
1158
-            esc_html__('Important information regarding your payment', 'event_espresso'),
1159
-            '',
1160
-            'spco-payment-method-hdr'
1161
-        );
1162
-        // add some info regarding the step, either from what's saved in the admin,
1163
-        // or a default string depending on whether the PM has a billing form or not
1164
-        if ($payment_method->description()) {
1165
-            $payment_method_info = $payment_method->description();
1166
-        } elseif ($billing_form instanceof EE_Billing_Info_Form) {
1167
-            $payment_method_info = sprintf(
1168
-                esc_html__(
1169
-                    'Please provide the following billing information, then click the "%1$s" button below in order to proceed.',
1170
-                    'event_espresso'
1171
-                ),
1172
-                $this->submit_button_text()
1173
-            );
1174
-        } else {
1175
-            $payment_method_info = sprintf(
1176
-                esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'),
1177
-                $this->submit_button_text()
1178
-            );
1179
-        }
1180
-        $info_html .= EEH_HTML::div(
1181
-            apply_filters(
1182
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info',
1183
-                $payment_method_info
1184
-            ),
1185
-            '',
1186
-            'spco-payment-method-desc ee-attention'
1187
-        );
1188
-        return new EE_Form_Section_Proper(
1189
-            [
1190
-                'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1191
-                'html_class'      => 'spco-payment-method-info-dv',
1192
-                // only display the selected or default PM
1193
-                'html_style'      => $currently_selected ? '' : 'display:none;',
1194
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1195
-                'subsections'     => [
1196
-                    'info'         => new EE_Form_Section_HTML($info_html),
1197
-                    'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(),
1198
-                ],
1199
-            ]
1200
-        );
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * get_billing_form_html_for_payment_method
1206
-     *
1207
-     * @return bool
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws ReflectionException
1211
-     * @throws InvalidDataTypeException
1212
-     * @throws InvalidInterfaceException
1213
-     */
1214
-    public function get_billing_form_html_for_payment_method()
1215
-    {
1216
-        // how have they chosen to pay?
1217
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1218
-        $this->checkout->payment_method             = $this->_get_payment_method_for_selected_method_of_payment();
1219
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1220
-            return false;
1221
-        }
1222
-        if (
1223
-            apply_filters(
1224
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1225
-                false
1226
-            )
1227
-        ) {
1228
-            EE_Error::add_success(
1229
-                apply_filters(
1230
-                    'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1231
-                    sprintf(
1232
-                        esc_html__(
1233
-                            'You have selected "%s" as your method of payment. Please note the important payment information below.',
1234
-                            'event_espresso'
1235
-                        ),
1236
-                        $this->checkout->payment_method->name()
1237
-                    )
1238
-                )
1239
-            );
1240
-        }
1241
-        // now generate billing form for selected method of payment
1242
-        $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1243
-        // fill form with attendee info if applicable
1244
-        if (
1245
-            $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
1246
-            && $this->checkout->transaction_has_primary_registrant()
1247
-        ) {
1248
-            $payment_method_billing_form->populate_from_attendee(
1249
-                $this->checkout->transaction->primary_registration()->attendee()
1250
-            );
1251
-        }
1252
-        // and debug content
1253
-        if (
1254
-            $payment_method_billing_form instanceof EE_Billing_Info_Form
1255
-            && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1256
-        ) {
1257
-            $payment_method_billing_form =
1258
-                $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1259
-                    $payment_method_billing_form
1260
-                );
1261
-        }
1262
-        $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper
1263
-            ? $payment_method_billing_form->get_html()
1264
-            : '';
1265
-        $this->checkout->json_response->set_return_data(['payment_method_info' => $billing_info]);
1266
-        // localize validation rules for main form
1267
-        $this->checkout->current_step->reg_form->localize_validation_rules();
1268
-        $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1269
-        return true;
1270
-    }
1271
-
1272
-
1273
-    /**
1274
-     * _get_billing_form_for_payment_method
1275
-     *
1276
-     * @param EE_Payment_Method $payment_method
1277
-     * @return EE_Billing_Info_Form|EE_Form_Section_HTML
1278
-     * @throws EE_Error
1279
-     * @throws InvalidArgumentException
1280
-     * @throws InvalidDataTypeException
1281
-     * @throws InvalidInterfaceException
1282
-     */
1283
-    private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method)
1284
-    {
1285
-        $billing_form = $payment_method->type_obj()->billing_form(
1286
-            $this->checkout->transaction,
1287
-            ['amount_owing' => $this->checkout->amount_owing]
1288
-        );
1289
-        if ($billing_form instanceof EE_Billing_Info_Form) {
1290
-            if (
1291
-                apply_filters(
1292
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1293
-                    false
1294
-                )
1295
-                && $this->request->requestParamIsSet('payment_method')
1296
-            ) {
1297
-                EE_Error::add_success(
1298
-                    apply_filters(
1299
-                        'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1300
-                        sprintf(
1301
-                            esc_html__(
1302
-                                'You have selected "%s" as your method of payment. Please note the important payment information below.',
1303
-                                'event_espresso'
1304
-                            ),
1305
-                            $payment_method->name()
1306
-                        )
1307
-                    )
1308
-                );
1309
-            }
1310
-            return apply_filters(
1311
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
1312
-                $billing_form,
1313
-                $payment_method
1314
-            );
1315
-        }
1316
-        // no actual billing form, so return empty HTML form section
1317
-        return new EE_Form_Section_HTML();
1318
-    }
1319
-
1320
-
1321
-    /**
1322
-     * _get_selected_method_of_payment
1323
-     *
1324
-     * @param boolean $required whether to throw an error if the "selected_method_of_payment"
1325
-     *                          is not found in the incoming request
1326
-     * @param string  $request_param
1327
-     * @return NULL|string
1328
-     * @throws EE_Error
1329
-     * @throws InvalidArgumentException
1330
-     * @throws InvalidDataTypeException
1331
-     * @throws InvalidInterfaceException
1332
-     */
1333
-    private function _get_selected_method_of_payment(
1334
-        $required = false,
1335
-        $request_param = 'selected_method_of_payment'
1336
-    ) {
1337
-        // is selected_method_of_payment set in the request ?
1338
-        $selected_method_of_payment = $this->request->getRequestParam($request_param);
1339
-        if ($selected_method_of_payment) {
1340
-            // sanitize it
1341
-            $selected_method_of_payment = is_array($selected_method_of_payment)
1342
-                ? array_shift($selected_method_of_payment)
1343
-                : $selected_method_of_payment;
1344
-            $selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
1345
-            // store it in the session so that it's available for all subsequent requests including AJAX
1346
-            $this->_save_selected_method_of_payment($selected_method_of_payment);
1347
-        } else {
1348
-            // or is is set in the session ?
1349
-            $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data(
1350
-                'selected_method_of_payment'
1351
-            );
1352
-        }
1353
-        // do ya really really gotta have it?
1354
-        if (empty($selected_method_of_payment) && $required) {
1355
-            EE_Error::add_error(
1356
-                sprintf(
1357
-                    esc_html__(
1358
-                        'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.',
1359
-                        'event_espresso'
1360
-                    ),
1361
-                    '<br/>',
1362
-                    '<br/>',
1363
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
1364
-                ),
1365
-                __FILE__,
1366
-                __FUNCTION__,
1367
-                __LINE__
1368
-            );
1369
-            return null;
1370
-        }
1371
-        return $selected_method_of_payment;
1372
-    }
1373
-
1374
-
1375
-
1376
-
1377
-
1378
-
1379
-    /********************************************************************************************************/
1380
-    /***********************************  SWITCH PAYMENT METHOD  ************************************/
1381
-    /********************************************************************************************************/
1382
-    /**
1383
-     * switch_payment_method
1384
-     *
1385
-     * @return bool
1386
-     * @throws EE_Error
1387
-     * @throws InvalidArgumentException
1388
-     * @throws InvalidDataTypeException
1389
-     * @throws InvalidInterfaceException
1390
-     * @throws ReflectionException
1391
-     */
1392
-    public function switch_payment_method()
1393
-    {
1394
-        if (! $this->_verify_payment_method_is_set()) {
1395
-            return false;
1396
-        }
1397
-        if (
1398
-            apply_filters(
1399
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1400
-                false
1401
-            )
1402
-        ) {
1403
-            EE_Error::add_success(
1404
-                apply_filters(
1405
-                    'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1406
-                    sprintf(
1407
-                        esc_html__(
1408
-                            'You have selected "%s" as your method of payment. Please note the important payment information below.',
1409
-                            'event_espresso'
1410
-                        ),
1411
-                        $this->checkout->payment_method->name()
1412
-                    )
1413
-                )
1414
-            );
1415
-        }
1416
-        // generate billing form for selected method of payment if it hasn't been done already
1417
-        if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1418
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1419
-                $this->checkout->payment_method
1420
-            );
1421
-        }
1422
-        // fill form with attendee info if applicable
1423
-        if (
1424
-            apply_filters(
1425
-                'FHEE__populate_billing_form_fields_from_attendee',
1426
-                (
1427
-                $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
1428
-                && $this->checkout->transaction_has_primary_registrant()
1429
-                ),
1430
-                $this->checkout->billing_form,
1431
-                $this->checkout->transaction
1432
-            )
1433
-        ) {
1434
-            $this->checkout->billing_form->populate_from_attendee(
1435
-                $this->checkout->transaction->primary_registration()->attendee()
1436
-            );
1437
-        }
1438
-        // and debug content
1439
-        if (
1440
-            $this->checkout->billing_form instanceof EE_Billing_Info_Form
1441
-            && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1442
-        ) {
1443
-            $this->checkout->billing_form =
1444
-                $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1445
-                    $this->checkout->billing_form
1446
-                );
1447
-        }
1448
-        // get html and validation rules for form
1449
-        if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
1450
-            $this->checkout->json_response->set_return_data(
1451
-                ['payment_method_info' => $this->checkout->billing_form->get_html()]
1452
-            );
1453
-            // localize validation rules for main form
1454
-            $this->checkout->billing_form->localize_validation_rules(true);
1455
-            $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1456
-        } else {
1457
-            $this->checkout->json_response->set_return_data(['payment_method_info' => '']);
1458
-        }
1459
-        // prevents advancement to next step
1460
-        $this->checkout->continue_reg = false;
1461
-        return true;
1462
-    }
1463
-
1464
-
1465
-    /**
1466
-     * _verify_payment_method_is_set
1467
-     *
1468
-     * @return bool
1469
-     * @throws EE_Error
1470
-     * @throws InvalidArgumentException
1471
-     * @throws ReflectionException
1472
-     * @throws InvalidDataTypeException
1473
-     * @throws InvalidInterfaceException
1474
-     */
1475
-    protected function _verify_payment_method_is_set()
1476
-    {
1477
-        // generate billing form for selected method of payment if it hasn't been done already
1478
-        if (empty($this->checkout->selected_method_of_payment)) {
1479
-            // how have they chosen to pay?
1480
-            $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1481
-        } else {
1482
-            // choose your own adventure based on method_of_payment
1483
-            switch ($this->checkout->selected_method_of_payment) {
1484
-                case 'events_sold_out':
1485
-                    EE_Error::add_attention(
1486
-                        apply_filters(
1487
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
1488
-                            esc_html__(
1489
-                                'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1490
-                                'event_espresso'
1491
-                            )
1492
-                        ),
1493
-                        __FILE__,
1494
-                        __FUNCTION__,
1495
-                        __LINE__
1496
-                    );
1497
-                    return false;
1498
-                case 'payments_closed':
1499
-                    EE_Error::add_attention(
1500
-                        apply_filters(
1501
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
1502
-                            esc_html__(
1503
-                                'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.',
1504
-                                'event_espresso'
1505
-                            )
1506
-                        ),
1507
-                        __FILE__,
1508
-                        __FUNCTION__,
1509
-                        __LINE__
1510
-                    );
1511
-                    return false;
1512
-                case 'no_payment_required':
1513
-                    EE_Error::add_attention(
1514
-                        apply_filters(
1515
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
1516
-                            esc_html__(
1517
-                                'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.',
1518
-                                'event_espresso'
1519
-                            )
1520
-                        ),
1521
-                        __FILE__,
1522
-                        __FUNCTION__,
1523
-                        __LINE__
1524
-                    );
1525
-                    return false;
1526
-                default:
1527
-            }
1528
-        }
1529
-        // verify payment method
1530
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1531
-            // get payment method for selected method of payment
1532
-            $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1533
-        }
1534
-        return $this->checkout->payment_method instanceof EE_Payment_Method;
1535
-    }
1536
-
1537
-
1538
-
1539
-    /********************************************************************************************************/
1540
-    /***************************************  SAVE PAYER DETAILS  ****************************************/
1541
-    /********************************************************************************************************/
1542
-    /**
1543
-     * save_payer_details_via_ajax
1544
-     *
1545
-     * @return void
1546
-     * @throws EE_Error
1547
-     * @throws InvalidArgumentException
1548
-     * @throws ReflectionException
1549
-     * @throws RuntimeException
1550
-     * @throws InvalidDataTypeException
1551
-     * @throws InvalidInterfaceException
1552
-     */
1553
-    public function save_payer_details_via_ajax()
1554
-    {
1555
-        if (! $this->_verify_payment_method_is_set()) {
1556
-            return;
1557
-        }
1558
-        // generate billing form for selected method of payment if it hasn't been done already
1559
-        if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1560
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1561
-                $this->checkout->payment_method
1562
-            );
1563
-        }
1564
-        // generate primary attendee from payer info if applicable
1565
-        if (! $this->checkout->transaction_has_primary_registrant()) {
1566
-            $attendee = $this->_create_attendee_from_request_data();
1567
-            if ($attendee instanceof EE_Attendee) {
1568
-                foreach ($this->checkout->transaction->registrations() as $registration) {
1569
-                    if ($registration->is_primary_registrant()) {
1570
-                        $this->checkout->primary_attendee_obj = $attendee;
1571
-                        $registration->_add_relation_to($attendee, 'Attendee');
1572
-                        $registration->set_attendee_id($attendee->ID());
1573
-                        $registration->update_cache_after_object_save('Attendee', $attendee);
1574
-                    }
1575
-                }
1576
-            }
1577
-        }
1578
-    }
1579
-
1580
-
1581
-    /**
1582
-     * create_attendee_from_request_data
1583
-     * uses info from alternate GET or POST data (such as AJAX) to create a new attendee
1584
-     *
1585
-     * @return EE_Attendee
1586
-     * @throws EE_Error
1587
-     * @throws InvalidArgumentException
1588
-     * @throws ReflectionException
1589
-     * @throws InvalidDataTypeException
1590
-     * @throws InvalidInterfaceException
1591
-     */
1592
-    protected function _create_attendee_from_request_data()
1593
-    {
1594
-        // get State ID
1595
-        $STA_ID = $this->request->getRequestParam('state');
1596
-        if (! empty($STA_ID)) {
1597
-            // can we get state object from name ?
1598
-            EE_Registry::instance()->load_model('State');
1599
-            $state  = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID');
1600
-            $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1601
-        }
1602
-        // get Country ISO
1603
-        $CNT_ISO = $this->request->getRequestParam('country');
1604
-        if (! empty($CNT_ISO)) {
1605
-            // can we get country object from name ?
1606
-            EE_Registry::instance()->load_model('Country');
1607
-            $country = EEM_Country::instance()->get_col(
1608
-                [['CNT_name' => $CNT_ISO], 'limit' => 1],
1609
-                'CNT_ISO'
1610
-            );
1611
-            $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1612
-        }
1613
-        // grab attendee data
1614
-        $attendee_data = [
1615
-            'ATT_fname'    => $this->request->getRequestParam('first_name'),
1616
-            'ATT_lname'    => $this->request->getRequestParam('last_name'),
1617
-            'ATT_email'    => $this->request->getRequestParam('email'),
1618
-            'ATT_address'  => $this->request->getRequestParam('address'),
1619
-            'ATT_address2' => $this->request->getRequestParam('address2'),
1620
-            'ATT_city'     => $this->request->getRequestParam('city'),
1621
-            'STA_ID'       => $STA_ID,
1622
-            'CNT_ISO'      => $CNT_ISO,
1623
-            'ATT_zip'      => $this->request->getRequestParam('zip'),
1624
-            'ATT_phone'    => $this->request->getRequestParam('phone'),
1625
-        ];
1626
-        // validate the email address since it is the most important piece of info
1627
-        if (empty($attendee_data['ATT_email'])) {
1628
-            EE_Error::add_error(
1629
-                esc_html__('An invalid email address was submitted.', 'event_espresso'),
1630
-                __FILE__,
1631
-                __FUNCTION__,
1632
-                __LINE__
1633
-            );
1634
-        }
1635
-        // does this attendee already exist in the db ? we're searching using a combination of first name, last name,
1636
-        // AND email address
1637
-        if (
1638
-            ! empty($attendee_data['ATT_fname'])
1639
-            && ! empty($attendee_data['ATT_lname'])
1640
-            && ! empty($attendee_data['ATT_email'])
1641
-        ) {
1642
-            $existing_attendee = EEM_Attendee::instance()->find_existing_attendee(
1643
-                [
1644
-                    'ATT_fname' => $attendee_data['ATT_fname'],
1645
-                    'ATT_lname' => $attendee_data['ATT_lname'],
1646
-                    'ATT_email' => $attendee_data['ATT_email'],
1647
-                ]
1648
-            );
1649
-            if ($existing_attendee instanceof EE_Attendee) {
1650
-                return $existing_attendee;
1651
-            }
1652
-        }
1653
-        // no existing attendee? kk let's create a new one
1654
-        // kinda lame, but we need a first and last name to create an attendee, so use the email address if those
1655
-        // don't exist
1656
-        $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname'])
1657
-            ? $attendee_data['ATT_fname']
1658
-            : $attendee_data['ATT_email'];
1659
-        $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname'])
1660
-            ? $attendee_data['ATT_lname']
1661
-            : $attendee_data['ATT_email'];
1662
-        return EE_Attendee::new_instance($attendee_data);
1663
-    }
1664
-
1665
-
1666
-
1667
-    /********************************************************************************************************/
1668
-    /****************************************  PROCESS REG STEP  *****************************************/
1669
-    /********************************************************************************************************/
1670
-    /**
1671
-     * process_reg_step
1672
-     *
1673
-     * @return bool
1674
-     * @throws EE_Error
1675
-     * @throws InvalidArgumentException
1676
-     * @throws ReflectionException
1677
-     * @throws EntityNotFoundException
1678
-     * @throws InvalidDataTypeException
1679
-     * @throws InvalidInterfaceException
1680
-     * @throws InvalidStatusException
1681
-     */
1682
-    public function process_reg_step()
1683
-    {
1684
-        // how have they chosen to pay?
1685
-        $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free()
1686
-            ? 'no_payment_required'
1687
-            : $this->_get_selected_method_of_payment(true);
1688
-        // choose your own adventure based on method_of_payment
1689
-        switch ($this->checkout->selected_method_of_payment) {
1690
-            case 'events_sold_out':
1691
-                $this->checkout->redirect     = true;
1692
-                $this->checkout->redirect_url = $this->checkout->cancel_page_url;
1693
-                $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1694
-                // mark this reg step as completed
1695
-                $this->set_completed();
1696
-                return false;
1697
-
1698
-            case 'payments_closed':
1699
-                if (
1700
-                    apply_filters(
1701
-                        'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success',
1702
-                        false
1703
-                    )
1704
-                ) {
1705
-                    EE_Error::add_success(
1706
-                        esc_html__('no payment required at this time.', 'event_espresso'),
1707
-                        __FILE__,
1708
-                        __FUNCTION__,
1709
-                        __LINE__
1710
-                    );
1711
-                }
1712
-                // mark this reg step as completed
1713
-                $this->set_completed();
1714
-                return true;
1715
-
1716
-            case 'no_payment_required':
1717
-                if (
1718
-                    apply_filters(
1719
-                        'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success',
1720
-                        false
1721
-                    )
1722
-                ) {
1723
-                    EE_Error::add_success(
1724
-                        esc_html__('no payment required.', 'event_espresso'),
1725
-                        __FILE__,
1726
-                        __FUNCTION__,
1727
-                        __LINE__
1728
-                    );
1729
-                }
1730
-                // mark this reg step as completed
1731
-                $this->set_completed();
1732
-                return true;
1733
-
1734
-            default:
1735
-                $registrations         = EE_Registry::instance()->SSN->checkout()->transaction->registrations(
1736
-                    EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
1737
-                );
1738
-                $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
1739
-                    $registrations,
1740
-                    EE_Registry::instance()->SSN->checkout()->revisit
1741
-                );
1742
-                // calculate difference between the two arrays
1743
-                $registrations = array_diff($registrations, $ejected_registrations);
1744
-                if (empty($registrations)) {
1745
-                    $this->_redirect_because_event_sold_out();
1746
-                    return false;
1747
-                }
1748
-                $payment_successful = $this->_process_payment();
1749
-                if ($payment_successful) {
1750
-                    $this->checkout->continue_reg = true;
1751
-                    $this->_maybe_set_completed($this->checkout->payment_method);
1752
-                } else {
1753
-                    $this->checkout->continue_reg = false;
1754
-                }
1755
-                return $payment_successful;
1756
-        }
1757
-    }
1758
-
1759
-
1760
-    /**
1761
-     * _redirect_because_event_sold_out
1762
-     *
1763
-     * @return void
1764
-     */
1765
-    protected function _redirect_because_event_sold_out()
1766
-    {
1767
-        $this->checkout->continue_reg = false;
1768
-        // set redirect URL
1769
-        $this->checkout->redirect_url = add_query_arg(
1770
-            ['e_reg_url_link' => $this->checkout->reg_url_link],
1771
-            $this->checkout->current_step->reg_step_url()
1772
-        );
1773
-        $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1774
-    }
1775
-
1776
-
1777
-    /**
1778
-     * _maybe_set_completed
1779
-     *
1780
-     * @param EE_Payment_Method $payment_method
1781
-     * @return void
1782
-     * @throws EE_Error
1783
-     */
1784
-    protected function _maybe_set_completed(EE_Payment_Method $payment_method)
1785
-    {
1786
-        switch ($payment_method->type_obj()->payment_occurs()) {
1787
-            case EE_PMT_Base::offsite:
1788
-                break;
1789
-            case EE_PMT_Base::onsite:
1790
-            case EE_PMT_Base::offline:
1791
-                // mark this reg step as completed
1792
-                $this->set_completed();
1793
-                break;
1794
-        }
1795
-    }
1796
-
1797
-
1798
-    /**
1799
-     *    update_reg_step
1800
-     *    this is the final step after a user  revisits the site to retry a payment
1801
-     *
1802
-     * @return bool
1803
-     * @throws EE_Error
1804
-     * @throws InvalidArgumentException
1805
-     * @throws ReflectionException
1806
-     * @throws EntityNotFoundException
1807
-     * @throws InvalidDataTypeException
1808
-     * @throws InvalidInterfaceException
1809
-     * @throws InvalidStatusException
1810
-     */
1811
-    public function update_reg_step()
1812
-    {
1813
-        $success = true;
1814
-        // if payment required
1815
-        if ($this->checkout->transaction->total() > 0) {
1816
-            do_action(
1817
-                'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway',
1818
-                $this->checkout->transaction
1819
-            );
1820
-            // attempt payment via payment method
1821
-            $success = $this->process_reg_step();
1822
-        }
1823
-        if ($success && ! $this->checkout->redirect) {
1824
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
1825
-                $this->checkout->transaction->ID()
1826
-            );
1827
-            // set return URL
1828
-            $this->checkout->redirect_url = add_query_arg(
1829
-                ['e_reg_url_link' => $this->checkout->reg_url_link],
1830
-                $this->checkout->thank_you_page_url
1831
-            );
1832
-        }
1833
-        return $success;
1834
-    }
1835
-
1836
-
1837
-    /**
1838
-     *    _process_payment
1839
-     *
1840
-     * @return bool
1841
-     * @throws EE_Error
1842
-     * @throws InvalidArgumentException
1843
-     * @throws ReflectionException
1844
-     * @throws RuntimeException
1845
-     * @throws InvalidDataTypeException
1846
-     * @throws InvalidInterfaceException
1847
-     */
1848
-    private function _process_payment()
1849
-    {
1850
-        // basically confirm that the event hasn't sold out since they hit the page
1851
-        if (! $this->_last_second_ticket_verifications()) {
1852
-            return false;
1853
-        }
1854
-        // ya gotta make a choice man
1855
-        if (empty($this->checkout->selected_method_of_payment)) {
1856
-            $this->checkout->json_response->set_plz_select_method_of_payment(
1857
-                esc_html__('Please select a method of payment before proceeding.', 'event_espresso')
1858
-            );
1859
-            return false;
1860
-        }
1861
-        // get EE_Payment_Method object
1862
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1863
-            return false;
1864
-        }
1865
-        // setup billing form
1866
-        if ($this->checkout->payment_method->is_on_site()) {
1867
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1868
-                $this->checkout->payment_method
1869
-            );
1870
-            // bad billing form ?
1871
-            if (! $this->_billing_form_is_valid()) {
1872
-                return false;
1873
-            }
1874
-        }
1875
-        // ensure primary registrant has been fully processed
1876
-        if (! $this->_setup_primary_registrant_prior_to_payment()) {
1877
-            return false;
1878
-        }
1879
-        // if session is close to expiring (under 10 minutes by default)
1880
-        if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1881
-            // add some time to session expiration so that payment can be completed
1882
-            EE_Registry::instance()->SSN->extend_expiration();
1883
-        }
1884
-        /** @type EE_Transaction_Processor $transaction_processor */
1885
-        // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1886
-        // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations
1887
-        // for events with a default reg status of Approved
1888
-        // $transaction_processor->toggle_registration_statuses_for_default_approved_events(
1889
-        //      $this->checkout->transaction, $this->checkout->reg_cache_where_params
1890
-        // );
1891
-        // attempt payment
1892
-        $payment = $this->_attempt_payment($this->checkout->payment_method);
1893
-        // process results
1894
-        $payment = $this->_validate_payment($payment);
1895
-        $payment = $this->_post_payment_processing($payment);
1896
-        // verify payment
1897
-        if ($payment instanceof EE_Payment) {
1898
-            // store that for later
1899
-            $this->checkout->payment = $payment;
1900
-            // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
1901
-            $this->checkout->transaction->toggle_failed_transaction_status();
1902
-            $payment_status = $payment->status();
1903
-            return $payment_status === EEM_Payment::status_id_approved
1904
-                   || $payment_status === EEM_Payment::status_id_pending;
1905
-        }
1906
-        if ($payment === true) {
1907
-            // please note that offline payment methods will NOT make a payment,
1908
-            // but instead just mark themselves as the PMD_ID on the transaction, and return true
1909
-            $this->checkout->payment = $payment;
1910
-            return true;
1911
-        }
1912
-        // where's my money?
1913
-        return false;
1914
-    }
1915
-
1916
-
1917
-    /**
1918
-     * _last_second_ticket_verifications
1919
-     *
1920
-     * @return bool
1921
-     * @throws EE_Error
1922
-     * @throws ReflectionException
1923
-     */
1924
-    protected function _last_second_ticket_verifications()
1925
-    {
1926
-        // don't bother re-validating if not a return visit
1927
-        if (! $this->checkout->revisit) {
1928
-            return true;
1929
-        }
1930
-        $registrations = $this->checkout->transaction->registrations();
1931
-        if (empty($registrations)) {
1932
-            return false;
1933
-        }
1934
-        foreach ($registrations as $registration) {
1935
-            if ($registration instanceof EE_Registration && ! $registration->is_approved()) {
1936
-                $event = $registration->event_obj();
1937
-                if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1938
-                    EE_Error::add_error(
1939
-                        apply_filters(
1940
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1941
-                            sprintf(
1942
-                                esc_html__(
1943
-                                    'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
1944
-                                    'event_espresso'
1945
-                                ),
1946
-                                $event->name()
1947
-                            )
1948
-                        ),
1949
-                        __FILE__,
1950
-                        __FUNCTION__,
1951
-                        __LINE__
1952
-                    );
1953
-                    return false;
1954
-                }
1955
-            }
1956
-        }
1957
-        return true;
1958
-    }
1959
-
1960
-
1961
-    /**
1962
-     * redirect_form
1963
-     *
1964
-     * @return bool
1965
-     * @throws EE_Error
1966
-     * @throws InvalidArgumentException
1967
-     * @throws ReflectionException
1968
-     * @throws InvalidDataTypeException
1969
-     * @throws InvalidInterfaceException
1970
-     */
1971
-    public function redirect_form()
1972
-    {
1973
-        $payment_method_billing_info = $this->_payment_method_billing_info(
1974
-            $this->_get_payment_method_for_selected_method_of_payment()
1975
-        );
1976
-        $html                        = $payment_method_billing_info->get_html();
1977
-        $html                        .= $this->checkout->redirect_form;
1978
-        /** @var ResponseInterface $response */
1979
-        $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
1980
-        $response->addOutput($html);
1981
-        return true;
1982
-    }
1983
-
1984
-
1985
-    /**
1986
-     * _billing_form_is_valid
1987
-     *
1988
-     * @return bool
1989
-     * @throws EE_Error
1990
-     */
1991
-    private function _billing_form_is_valid()
1992
-    {
1993
-        if (! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1994
-            return true;
1995
-        }
1996
-        if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1997
-            if ($this->checkout->billing_form->was_submitted()) {
1998
-                $this->checkout->billing_form->receive_form_submission();
1999
-                if ($this->checkout->billing_form->is_valid()) {
2000
-                    return true;
2001
-                }
2002
-                $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
2003
-                $error_strings     = [];
2004
-                foreach ($validation_errors as $validation_error) {
2005
-                    if ($validation_error instanceof EE_Validation_Error) {
2006
-                        $form_section = $validation_error->get_form_section();
2007
-                        if ($form_section instanceof EE_Form_Input_Base) {
2008
-                            $label = $form_section->html_label_text();
2009
-                        } elseif ($form_section instanceof EE_Form_Section_Base) {
2010
-                            $label = $form_section->name();
2011
-                        } else {
2012
-                            $label = esc_html__('Validation Error', 'event_espresso');
2013
-                        }
2014
-                        $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
2015
-                    }
2016
-                }
2017
-                EE_Error::add_error(
2018
-                    sprintf(
2019
-                        esc_html__(
2020
-                            'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s',
2021
-                            'event_espresso'
2022
-                        ),
2023
-                        '<br/>',
2024
-                        implode('<br/>', $error_strings)
2025
-                    ),
2026
-                    __FILE__,
2027
-                    __FUNCTION__,
2028
-                    __LINE__
2029
-                );
2030
-            } else {
2031
-                EE_Error::add_error(
2032
-                    esc_html__(
2033
-                        'The billing form was not submitted or something prevented it\'s submission.',
2034
-                        'event_espresso'
2035
-                    ),
2036
-                    __FILE__,
2037
-                    __FUNCTION__,
2038
-                    __LINE__
2039
-                );
2040
-            }
2041
-        } else {
2042
-            EE_Error::add_error(
2043
-                esc_html__(
2044
-                    'The submitted billing form is invalid possibly due to a technical reason.',
2045
-                    'event_espresso'
2046
-                ),
2047
-                __FILE__,
2048
-                __FUNCTION__,
2049
-                __LINE__
2050
-            );
2051
-        }
2052
-        return false;
2053
-    }
2054
-
2055
-
2056
-    /**
2057
-     * _setup_primary_registrant_prior_to_payment
2058
-     * ensures that the primary registrant has a valid attendee object created with the critical details populated
2059
-     * (first & last name & email) and that both the transaction object and primary registration object have been saved
2060
-     * plz note that any other registrations will NOT be saved at this point (because they may not have any details
2061
-     * yet)
2062
-     *
2063
-     * @return bool
2064
-     * @throws EE_Error
2065
-     * @throws InvalidArgumentException
2066
-     * @throws ReflectionException
2067
-     * @throws RuntimeException
2068
-     * @throws InvalidDataTypeException
2069
-     * @throws InvalidInterfaceException
2070
-     */
2071
-    private function _setup_primary_registrant_prior_to_payment()
2072
-    {
2073
-        // check if transaction has a primary registrant and that it has a related Attendee object
2074
-        // if not, then we need to at least gather some primary registrant data before attempting payment
2075
-        if (
2076
-            $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
2077
-            && ! $this->checkout->transaction_has_primary_registrant()
2078
-            && ! $this->_capture_primary_registration_data_from_billing_form()
2079
-        ) {
2080
-            return false;
2081
-        }
2082
-        // because saving an object clears it's cache, we need to do the chevy shuffle
2083
-        // grab the primary_registration object
2084
-        $primary_registration = $this->checkout->transaction->primary_registration();
2085
-        // at this point we'll consider a TXN to not have been failed
2086
-        $this->checkout->transaction->toggle_failed_transaction_status();
2087
-        // save the TXN ( which clears cached copy of primary_registration)
2088
-        $this->checkout->transaction->save();
2089
-        // grab TXN ID and save it to the primary_registration
2090
-        $primary_registration->set_transaction_id($this->checkout->transaction->ID());
2091
-        // save what we have so far
2092
-        $primary_registration->save();
2093
-        return true;
2094
-    }
2095
-
2096
-
2097
-    /**
2098
-     * _capture_primary_registration_data_from_billing_form
2099
-     *
2100
-     * @return bool
2101
-     * @throws EE_Error
2102
-     * @throws InvalidArgumentException
2103
-     * @throws ReflectionException
2104
-     * @throws InvalidDataTypeException
2105
-     * @throws InvalidInterfaceException
2106
-     */
2107
-    private function _capture_primary_registration_data_from_billing_form()
2108
-    {
2109
-        // convert billing form data into an attendee
2110
-        $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
2111
-        if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2112
-            EE_Error::add_error(
2113
-                sprintf(
2114
-                    esc_html__(
2115
-                        'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.',
2116
-                        'event_espresso'
2117
-                    ),
2118
-                    '<br/>',
2119
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2120
-                ),
2121
-                __FILE__,
2122
-                __FUNCTION__,
2123
-                __LINE__
2124
-            );
2125
-            return false;
2126
-        }
2127
-        $primary_registration = $this->checkout->transaction->primary_registration();
2128
-        if (! $primary_registration instanceof EE_Registration) {
2129
-            EE_Error::add_error(
2130
-                sprintf(
2131
-                    esc_html__(
2132
-                        'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2133
-                        'event_espresso'
2134
-                    ),
2135
-                    '<br/>',
2136
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2137
-                ),
2138
-                __FILE__,
2139
-                __FUNCTION__,
2140
-                __LINE__
2141
-            );
2142
-            return false;
2143
-        }
2144
-        if (
2145
-            ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee')
2146
-              instanceof
2147
-              EE_Attendee
2148
-        ) {
2149
-            EE_Error::add_error(
2150
-                sprintf(
2151
-                    esc_html__(
2152
-                        'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.',
2153
-                        'event_espresso'
2154
-                    ),
2155
-                    '<br/>',
2156
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2157
-                ),
2158
-                __FILE__,
2159
-                __FUNCTION__,
2160
-                __LINE__
2161
-            );
2162
-            return false;
2163
-        }
2164
-        /** @type EE_Registration_Processor $registration_processor */
2165
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
2166
-        // at this point, we should have enough details about the registrant to consider the registration NOT incomplete
2167
-        $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
2168
-        return true;
2169
-    }
2170
-
2171
-
2172
-    /**
2173
-     * _get_payment_method_for_selected_method_of_payment
2174
-     * retrieves a valid payment method
2175
-     *
2176
-     * @return EE_Payment_Method
2177
-     * @throws EE_Error
2178
-     * @throws InvalidArgumentException
2179
-     * @throws ReflectionException
2180
-     * @throws InvalidDataTypeException
2181
-     * @throws InvalidInterfaceException
2182
-     */
2183
-    private function _get_payment_method_for_selected_method_of_payment()
2184
-    {
2185
-        if ($this->checkout->selected_method_of_payment === 'events_sold_out') {
2186
-            $this->_redirect_because_event_sold_out();
2187
-            return null;
2188
-        }
2189
-        // get EE_Payment_Method object
2190
-        if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) {
2191
-            $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
2192
-        } else {
2193
-            // load EEM_Payment_Method
2194
-            EE_Registry::instance()->load_model('Payment_Method');
2195
-            $EEM_Payment_Method = EEM_Payment_Method::instance();
2196
-            $payment_method     = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2197
-        }
2198
-        // verify $payment_method
2199
-        if (! $payment_method instanceof EE_Payment_Method) {
2200
-            // not a payment
2201
-            EE_Error::add_error(
2202
-                sprintf(
2203
-                    esc_html__(
2204
-                        'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2205
-                        'event_espresso'
2206
-                    ),
2207
-                    '<br/>',
2208
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2209
-                ),
2210
-                __FILE__,
2211
-                __FUNCTION__,
2212
-                __LINE__
2213
-            );
2214
-            return null;
2215
-        }
2216
-        // and verify it has a valid Payment_Method Type object
2217
-        if (! $payment_method->type_obj() instanceof EE_PMT_Base) {
2218
-            // not a payment
2219
-            EE_Error::add_error(
2220
-                sprintf(
2221
-                    esc_html__(
2222
-                        'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2223
-                        'event_espresso'
2224
-                    ),
2225
-                    '<br/>',
2226
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2227
-                ),
2228
-                __FILE__,
2229
-                __FUNCTION__,
2230
-                __LINE__
2231
-            );
2232
-            return null;
2233
-        }
2234
-        return $payment_method;
2235
-    }
2236
-
2237
-
2238
-    /**
2239
-     *    _attempt_payment
2240
-     *
2241
-     * @access    private
2242
-     * @type    EE_Payment_Method $payment_method
2243
-     * @return mixed EE_Payment | boolean
2244
-     * @throws EE_Error
2245
-     * @throws InvalidArgumentException
2246
-     * @throws ReflectionException
2247
-     * @throws InvalidDataTypeException
2248
-     * @throws InvalidInterfaceException
2249
-     */
2250
-    private function _attempt_payment(EE_Payment_Method $payment_method)
2251
-    {
2252
-        $payment = null;
2253
-        $this->checkout->transaction->save();
2254
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2255
-        if (! $payment_processor instanceof EE_Payment_Processor) {
2256
-            return false;
2257
-        }
2258
-        try {
2259
-            $payment_processor->set_revisit($this->checkout->revisit);
2260
-            // generate payment object
2261
-            $payment = $payment_processor->process_payment(
2262
-                $payment_method,
2263
-                $this->checkout->transaction,
2264
-                $this->checkout->amount_owing,
2265
-                $this->checkout->billing_form,
2266
-                $this->_get_return_url($payment_method),
2267
-                'CART',
2268
-                $this->checkout->admin_request,
2269
-                true,
2270
-                $this->reg_step_url()
2271
-            );
2272
-        } catch (Exception $e) {
2273
-            $this->_handle_payment_processor_exception($e);
2274
-        }
2275
-        return $payment;
2276
-    }
2277
-
2278
-
2279
-    /**
2280
-     * _handle_payment_processor_exception
2281
-     *
2282
-     * @param Exception $e
2283
-     * @return void
2284
-     * @throws EE_Error
2285
-     * @throws InvalidArgumentException
2286
-     * @throws InvalidDataTypeException
2287
-     * @throws InvalidInterfaceException
2288
-     */
2289
-    protected function _handle_payment_processor_exception(Exception $e)
2290
-    {
2291
-        EE_Error::add_error(
2292
-            sprintf(
2293
-                esc_html__(
2294
-                    'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s',
2295
-                    'event_espresso'
2296
-                ),
2297
-                '<br/>',
2298
-                EE_Registry::instance()->CFG->organization->get_pretty('email'),
2299
-                $e->getMessage(),
2300
-                $e->getFile(),
2301
-                $e->getLine()
2302
-            ),
2303
-            __FILE__,
2304
-            __FUNCTION__,
2305
-            __LINE__
2306
-        );
2307
-    }
2308
-
2309
-
2310
-    /**
2311
-     * _get_return_url
2312
-     *
2313
-     * @param EE_Payment_Method $payment_method
2314
-     * @return string
2315
-     * @throws EE_Error
2316
-     * @throws ReflectionException
2317
-     */
2318
-    protected function _get_return_url(EE_Payment_Method $payment_method)
2319
-    {
2320
-        $return_url = '';
2321
-        switch ($payment_method->type_obj()->payment_occurs()) {
2322
-            case EE_PMT_Base::offsite:
2323
-                $return_url = add_query_arg(
2324
-                    [
2325
-                        'action'                     => 'process_gateway_response',
2326
-                        'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2327
-                        'spco_txn'                   => $this->checkout->transaction->ID(),
2328
-                    ],
2329
-                    $this->reg_step_url()
2330
-                );
2331
-                break;
2332
-            case EE_PMT_Base::onsite:
2333
-            case EE_PMT_Base::offline:
2334
-                $return_url = $this->checkout->next_step->reg_step_url();
2335
-                break;
2336
-        }
2337
-        return $return_url;
2338
-    }
2339
-
2340
-
2341
-    /**
2342
-     * _validate_payment
2343
-     *
2344
-     * @param EE_Payment $payment
2345
-     * @return EE_Payment|FALSE
2346
-     * @throws EE_Error
2347
-     * @throws InvalidArgumentException
2348
-     * @throws InvalidDataTypeException
2349
-     * @throws InvalidInterfaceException
2350
-     */
2351
-    private function _validate_payment($payment = null)
2352
-    {
2353
-        if ($this->checkout->payment_method->is_off_line()) {
2354
-            return true;
2355
-        }
2356
-        // verify payment object
2357
-        if (! $payment instanceof EE_Payment) {
2358
-            // not a payment
2359
-            EE_Error::add_error(
2360
-                sprintf(
2361
-                    esc_html__(
2362
-                        'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.',
2363
-                        'event_espresso'
2364
-                    ),
2365
-                    '<br/>',
2366
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2367
-                ),
2368
-                __FILE__,
2369
-                __FUNCTION__,
2370
-                __LINE__
2371
-            );
2372
-            return false;
2373
-        }
2374
-        return $payment;
2375
-    }
2376
-
2377
-
2378
-    /**
2379
-     * _post_payment_processing
2380
-     *
2381
-     * @param EE_Payment|bool $payment
2382
-     * @return bool
2383
-     * @throws EE_Error
2384
-     * @throws InvalidArgumentException
2385
-     * @throws InvalidDataTypeException
2386
-     * @throws InvalidInterfaceException
2387
-     * @throws ReflectionException
2388
-     */
2389
-    private function _post_payment_processing($payment = null)
2390
-    {
2391
-        // Off-Line payment?
2392
-        if ($payment === true) {
2393
-            // $this->_setup_redirect_for_next_step();
2394
-            return true;
2395
-            // On-Site payment?
2396
-        } elseif ($this->checkout->payment_method->is_on_site()) {
2397
-            if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2398
-                // $this->_setup_redirect_for_next_step();
2399
-                $this->checkout->continue_reg = false;
2400
-            }
2401
-            // Off-Site payment?
2402
-        } elseif ($this->checkout->payment_method->is_off_site()) {
2403
-            // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info
2404
-            if ($payment instanceof EE_Payment && $payment->redirect_url()) {
2405
-                do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
2406
-                $this->checkout->redirect      = true;
2407
-                $this->checkout->redirect_form = $payment->redirect_form();
2408
-                $this->checkout->redirect_url  = $this->reg_step_url('redirect_form');
2409
-                // set JSON response
2410
-                $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
2411
-                // and lastly, let's bump the payment status to pending
2412
-                $payment->set_status(EEM_Payment::status_id_pending);
2413
-                $payment->save();
2414
-            } else {
2415
-                // we couldn't redirect the user. Let's tell them why.
2416
-                $error_message = sprintf(
2417
-                    esc_html__(
2418
-                        'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.',
2419
-                        'event_espresso'
2420
-                    ),
2421
-                    '<br/>',
2422
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2423
-                );
2424
-                if ($payment instanceof EE_Payment && $payment->gateway_response()) {
2425
-                    $error_message = $error_message . '<br/>' . $payment->gateway_response();
2426
-                }
2427
-                $this->checkout->continue_reg = false;
2428
-                EE_Error::add_error(
2429
-                    $error_message,
2430
-                    __FILE__,
2431
-                    __FUNCTION__,
2432
-                    __LINE__
2433
-                );
2434
-            }
2435
-        } else {
2436
-            // ummm ya... not Off-Line, not On-Site, not off-Site ????
2437
-            $this->checkout->continue_reg = false;
2438
-            return false;
2439
-        }
2440
-        return $payment;
2441
-    }
2442
-
2443
-
2444
-    /**
2445
-     *    _process_payment_status
2446
-     *
2447
-     * @type    EE_Payment $payment
2448
-     * @param string       $payment_occurs
2449
-     * @return bool
2450
-     * @throws EE_Error
2451
-     * @throws InvalidArgumentException
2452
-     * @throws InvalidDataTypeException
2453
-     * @throws InvalidInterfaceException
2454
-     */
2455
-    private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline)
2456
-    {
2457
-        // off-line payment? carry on
2458
-        if ($payment_occurs === EE_PMT_Base::offline) {
2459
-            return true;
2460
-        }
2461
-        // verify payment validity
2462
-        if ($payment instanceof EE_Payment) {
2463
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
2464
-            $msg = $payment->gateway_response();
2465
-            // check results
2466
-            switch ($payment->status()) {
2467
-                // good payment
2468
-                case EEM_Payment::status_id_approved:
2469
-                    EE_Error::add_success(
2470
-                        esc_html__('Your payment was processed successfully.', 'event_espresso'),
2471
-                        __FILE__,
2472
-                        __FUNCTION__,
2473
-                        __LINE__
2474
-                    );
2475
-                    return true;
2476
-                // slow payment
2477
-                case EEM_Payment::status_id_pending:
2478
-                    if (empty($msg)) {
2479
-                        $msg = esc_html__(
2480
-                            'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.',
2481
-                            'event_espresso'
2482
-                        );
2483
-                    }
2484
-                    EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
2485
-                    return true;
2486
-                // don't wanna payment
2487
-                case EEM_Payment::status_id_cancelled:
2488
-                    if (empty($msg)) {
2489
-                        $msg = _n(
2490
-                            'Payment cancelled. Please try again.',
2491
-                            'Payment cancelled. Please try again or select another method of payment.',
2492
-                            count($this->checkout->available_payment_methods),
2493
-                            'event_espresso'
2494
-                        );
2495
-                    }
2496
-                    EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2497
-                    return false;
2498
-                // not enough payment
2499
-                case EEM_Payment::status_id_declined:
2500
-                    if (empty($msg)) {
2501
-                        $msg = _n(
2502
-                            'We\'re sorry but your payment was declined. Please try again.',
2503
-                            'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
2504
-                            count($this->checkout->available_payment_methods),
2505
-                            'event_espresso'
2506
-                        );
2507
-                    }
2508
-                    EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2509
-                    return false;
2510
-                // bad payment
2511
-                case EEM_Payment::status_id_failed:
2512
-                    if (! empty($msg)) {
2513
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2514
-                        return false;
2515
-                    }
2516
-                    // default to error below
2517
-                    break;
2518
-            }
2519
-        }
2520
-        // off-site payment gateway responses are too unreliable, so let's just assume that
2521
-        // the payment processing is just running slower than the registrant's request
2522
-        if ($payment_occurs === EE_PMT_Base::offsite) {
2523
-            return true;
2524
-        }
2525
-        EE_Error::add_error(
2526
-            sprintf(
2527
-                esc_html__(
2528
-                    'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.',
2529
-                    'event_espresso'
2530
-                ),
2531
-                '<br/>',
2532
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
2533
-            ),
2534
-            __FILE__,
2535
-            __FUNCTION__,
2536
-            __LINE__
2537
-        );
2538
-        return false;
2539
-    }
2540
-
2541
-
2542
-
2543
-
2544
-
2545
-
2546
-    /********************************************************************************************************/
2547
-    /**********************************  PROCESS GATEWAY RESPONSE  **********************************/
2548
-    /********************************************************************************************************/
2549
-    /**
2550
-     * process_gateway_response
2551
-     * this is the return point for Off-Site Payment Methods
2552
-     * It will attempt to "handle the IPN" if it appears that this has not already occurred,
2553
-     * otherwise, it will load up the last payment made for the TXN.
2554
-     * If the payment retrieved looks good, it will then either:
2555
-     *    complete the current step and allow advancement to the next reg step
2556
-     *        or present the payment options again
2557
-     *
2558
-     * @return bool
2559
-     * @throws EE_Error
2560
-     * @throws InvalidArgumentException
2561
-     * @throws ReflectionException
2562
-     * @throws InvalidDataTypeException
2563
-     * @throws InvalidInterfaceException
2564
-     */
2565
-    public function process_gateway_response()
2566
-    {
2567
-        // how have they chosen to pay?
2568
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2569
-        // get EE_Payment_Method object
2570
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2571
-            $this->checkout->continue_reg = false;
2572
-            return false;
2573
-        }
2574
-        if (! $this->checkout->payment_method->is_off_site()) {
2575
-            return false;
2576
-        }
2577
-        $this->_validate_offsite_return();
2578
-        // verify TXN
2579
-        if ($this->checkout->transaction instanceof EE_Transaction) {
2580
-            $gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2581
-            if (! $gateway instanceof EE_Offsite_Gateway) {
2582
-                $this->checkout->continue_reg = false;
2583
-                return false;
2584
-            }
2585
-            $payment = $this->_process_off_site_payment($gateway);
2586
-            $payment = $this->_process_cancelled_payments($payment);
2587
-            $payment = $this->_validate_payment($payment);
2588
-            // if payment was not declined by the payment gateway or cancelled by the registrant
2589
-            if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
2590
-                // $this->_setup_redirect_for_next_step();
2591
-                // store that for later
2592
-                $this->checkout->payment = $payment;
2593
-                // mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2594
-                // because we will complete this step during the IPN processing then
2595
-                if (! $this->handle_IPN_in_this_request()) {
2596
-                    $this->set_completed();
2597
-                }
2598
-                return true;
2599
-            }
2600
-        }
2601
-        // DEBUG LOG
2602
-        // $this->checkout->log(
2603
-        //     __CLASS__,
2604
-        //     __FUNCTION__,
2605
-        //     __LINE__,
2606
-        //     array('payment' => $payment)
2607
-        // );
2608
-        $this->checkout->continue_reg = false;
2609
-        return false;
2610
-    }
2611
-
2612
-
2613
-    /**
2614
-     * _validate_return
2615
-     *
2616
-     * @return void
2617
-     * @throws EE_Error
2618
-     * @throws InvalidArgumentException
2619
-     * @throws InvalidDataTypeException
2620
-     * @throws InvalidInterfaceException
2621
-     * @throws ReflectionException
2622
-     */
2623
-    private function _validate_offsite_return()
2624
-    {
2625
-        $TXN_ID = $this->request->getRequestParam('spco_txn', 0, 'int');
2626
-        if ($TXN_ID !== $this->checkout->transaction->ID()) {
2627
-            // Houston... we might have a problem
2628
-            $invalid_TXN = false;
2629
-            // first gather some info
2630
-            $valid_TXN          = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2631
-            $primary_registrant = $valid_TXN instanceof EE_Transaction
2632
-                ? $valid_TXN->primary_registration()
2633
-                : null;
2634
-            // let's start by retrieving the cart for this TXN
2635
-            $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction);
2636
-            if ($cart instanceof EE_Cart) {
2637
-                // verify that the current cart has tickets
2638
-                $tickets = $cart->get_tickets();
2639
-                if (empty($tickets)) {
2640
-                    $invalid_TXN = true;
2641
-                }
2642
-            } else {
2643
-                $invalid_TXN = true;
2644
-            }
2645
-            $valid_TXN_SID = $primary_registrant instanceof EE_Registration
2646
-                ? $primary_registrant->session_ID()
2647
-                : null;
2648
-            // validate current Session ID and compare against valid TXN session ID
2649
-            if (
2650
-                $invalid_TXN // if this is already true, then skip other checks
2651
-                || EE_Session::instance()->id() === null
2652
-                || (
2653
-                    // WARNING !!!
2654
-                    // this could be PayPal sending back duplicate requests (ya they do that)
2655
-                    // or it **could** mean someone is simply registering AGAIN after having just done so
2656
-                    // so now we need to determine if this current TXN looks valid or not
2657
-                    // and whether this reg step has even been started ?
2658
-                    EE_Session::instance()->id() === $valid_TXN_SID
2659
-                    // really? you're half way through this reg step, but you never started it ?
2660
-                    && $this->checkout->transaction->reg_step_completed($this->slug()) === false
2661
-                )
2662
-            ) {
2663
-                $invalid_TXN = true;
2664
-            }
2665
-            if ($invalid_TXN) {
2666
-                // is the valid TXN completed ?
2667
-                if ($valid_TXN instanceof EE_Transaction) {
2668
-                    // has this step even been started ?
2669
-                    $reg_step_completed = $valid_TXN->reg_step_completed($this->slug());
2670
-                    if ($reg_step_completed !== false && $reg_step_completed !== true) {
2671
-                        // so it **looks** like this is a double request from PayPal
2672
-                        // so let's try to pick up where we left off
2673
-                        $this->checkout->transaction = $valid_TXN;
2674
-                        $this->checkout->refresh_all_entities(true);
2675
-                        return;
2676
-                    }
2677
-                }
2678
-                // you appear to be lost?
2679
-                $this->_redirect_wayward_request($primary_registrant);
2680
-            }
2681
-        }
2682
-    }
2683
-
2684
-
2685
-    /**
2686
-     * _redirect_wayward_request
2687
-     *
2688
-     * @param EE_Registration|null $primary_registrant
2689
-     * @return void
2690
-     * @throws EE_Error
2691
-     * @throws InvalidArgumentException
2692
-     * @throws InvalidDataTypeException
2693
-     * @throws InvalidInterfaceException
2694
-     * @throws ReflectionException
2695
-     */
2696
-    private function _redirect_wayward_request(EE_Registration $primary_registrant)
2697
-    {
2698
-        if (! $primary_registrant instanceof EE_Registration) {
2699
-            // try redirecting based on the current TXN
2700
-            $primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2701
-                ? $this->checkout->transaction->primary_registration()
2702
-                : null;
2703
-        }
2704
-        if (! $primary_registrant instanceof EE_Registration) {
2705
-            EE_Error::add_error(
2706
-                sprintf(
2707
-                    esc_html__(
2708
-                        'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.',
2709
-                        'event_espresso'
2710
-                    ),
2711
-                    '<br/>',
2712
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2713
-                ),
2714
-                __FILE__,
2715
-                __FUNCTION__,
2716
-                __LINE__
2717
-            );
2718
-            return;
2719
-        }
2720
-        // make sure transaction is not locked
2721
-        $this->checkout->transaction->unlock();
2722
-        wp_safe_redirect(
2723
-            add_query_arg(
2724
-                [
2725
-                    'e_reg_url_link' => $primary_registrant->reg_url_link(),
2726
-                ],
2727
-                $this->checkout->thank_you_page_url
2728
-            )
2729
-        );
2730
-        exit();
2731
-    }
2732
-
2733
-
2734
-    /**
2735
-     * _process_off_site_payment
2736
-     *
2737
-     * @param EE_Offsite_Gateway $gateway
2738
-     * @return EE_Payment
2739
-     * @throws EE_Error
2740
-     * @throws InvalidArgumentException
2741
-     * @throws InvalidDataTypeException
2742
-     * @throws InvalidInterfaceException
2743
-     * @throws ReflectionException
2744
-     */
2745
-    private function _process_off_site_payment(EE_Offsite_Gateway $gateway)
2746
-    {
2747
-        try {
2748
-            $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
2749
-            $request_data = $request->requestParams();
2750
-            // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
2751
-            $this->set_handle_IPN_in_this_request(
2752
-                $gateway->handle_IPN_in_this_request($request_data, false)
2753
-            );
2754
-            if ($this->handle_IPN_in_this_request()) {
2755
-                // get payment details and process results
2756
-                /** @type EE_Payment_Processor $payment_processor */
2757
-                $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2758
-                $payment           = $payment_processor->process_ipn(
2759
-                    $request_data,
2760
-                    $this->checkout->transaction,
2761
-                    $this->checkout->payment_method,
2762
-                    true,
2763
-                    false
2764
-                );
2765
-                // $payment_source = 'process_ipn';
2766
-            } else {
2767
-                $payment = $this->checkout->transaction->last_payment();
2768
-                // $payment_source = 'last_payment';
2769
-            }
2770
-        } catch (Exception $e) {
2771
-            // let's just eat the exception and try to move on using any previously set payment info
2772
-            $payment = $this->checkout->transaction->last_payment();
2773
-            // $payment_source = 'last_payment after Exception';
2774
-            // but if we STILL don't have a payment object
2775
-            if (! $payment instanceof EE_Payment) {
2776
-                // then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2777
-                $this->_handle_payment_processor_exception($e);
2778
-            }
2779
-        }
2780
-        return $payment;
2781
-    }
2782
-
2783
-
2784
-    /**
2785
-     * _process_cancelled_payments
2786
-     * just makes sure that the payment status gets updated correctly
2787
-     * so tha tan error isn't generated during payment validation
2788
-     *
2789
-     * @param EE_Payment $payment
2790
-     * @return EE_Payment|null
2791
-     * @throws EE_Error
2792
-     */
2793
-    private function _process_cancelled_payments($payment = null)
2794
-    {
2795
-        if (
2796
-            $payment instanceof EE_Payment
2797
-            && $this->request->requestParamIsSet('ee_cancel_payment')
2798
-            && $payment->status() === EEM_Payment::status_id_failed
2799
-        ) {
2800
-            $payment->set_status(EEM_Payment::status_id_cancelled);
2801
-        }
2802
-        return $payment;
2803
-    }
2804
-
2805
-
2806
-    /**
2807
-     *    get_transaction_details_for_gateways
2808
-     *
2809
-     * @access    public
2810
-     * @return void
2811
-     * @throws EE_Error
2812
-     * @throws InvalidArgumentException
2813
-     * @throws ReflectionException
2814
-     * @throws InvalidDataTypeException
2815
-     * @throws InvalidInterfaceException
2816
-     */
2817
-    public function get_transaction_details_for_gateways()
2818
-    {
2819
-        $txn_details = [];
2820
-        // ya gotta make a choice man
2821
-        if (empty($this->checkout->selected_method_of_payment)) {
2822
-            $txn_details = [
2823
-                'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'),
2824
-            ];
2825
-        }
2826
-        // get EE_Payment_Method object
2827
-        if (
2828
-            empty($txn_details)
2829
-            && ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2830
-        ) {
2831
-            $txn_details = [
2832
-                'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2833
-                'error'                      => esc_html__(
2834
-                    'A valid Payment Method could not be determined.',
2835
-                    'event_espresso'
2836
-                ),
2837
-            ];
2838
-        }
2839
-        if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2840
-            $return_url  = $this->_get_return_url($this->checkout->payment_method);
2841
-            $txn_details = [
2842
-                'TXN_ID'         => $this->checkout->transaction->ID(),
2843
-                'TXN_timestamp'  => $this->checkout->transaction->datetime(),
2844
-                'TXN_total'      => $this->checkout->transaction->total(),
2845
-                'TXN_paid'       => $this->checkout->transaction->paid(),
2846
-                'TXN_reg_steps'  => $this->checkout->transaction->reg_steps(),
2847
-                'STS_ID'         => $this->checkout->transaction->status_ID(),
2848
-                'PMD_ID'         => $this->checkout->transaction->payment_method_ID(),
2849
-                'payment_amount' => $this->checkout->amount_owing,
2850
-                'return_url'     => $return_url,
2851
-                'cancel_url'     => add_query_arg(['ee_cancel_payment' => true], $return_url),
2852
-                'notify_url'     => EE_Config::instance()->core->txn_page_url(
2853
-                    [
2854
-                        'e_reg_url_link'    => $this->checkout->transaction->primary_registration()->reg_url_link(),
2855
-                        'ee_payment_method' => $this->checkout->payment_method->slug(),
2856
-                    ]
2857
-                ),
2858
-            ];
2859
-        }
2860
-        echo wp_json_encode($txn_details);
2861
-        exit();
2862
-    }
2863
-
2864
-
2865
-    /**
2866
-     *    __sleep
2867
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
2868
-     * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
2869
-     * reg form, because if needed, it will be regenerated anyways
2870
-     *
2871
-     * @return array
2872
-     */
2873
-    public function __sleep()
2874
-    {
2875
-        // remove the reg form and the checkout
2876
-        return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout', 'line_item_display']);
2877
-    }
22
+	/**
23
+	 * @var EE_Line_Item_Display $Line_Item_Display
24
+	 */
25
+	protected $line_item_display;
26
+
27
+	/**
28
+	 * @var boolean $handle_IPN_in_this_request
29
+	 */
30
+	protected $handle_IPN_in_this_request = false;
31
+
32
+
33
+	/**
34
+	 *    set_hooks - for hooking into EE Core, other modules, etc
35
+	 *
36
+	 * @access    public
37
+	 * @return    void
38
+	 */
39
+	public static function set_hooks()
40
+	{
41
+		add_filter(
42
+			'FHEE__SPCO__EE_Line_Item_Filter_Collection',
43
+			['EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters']
44
+		);
45
+		add_action(
46
+			'wp_ajax_switch_spco_billing_form',
47
+			['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form']
48
+		);
49
+		add_action(
50
+			'wp_ajax_nopriv_switch_spco_billing_form',
51
+			['EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form']
52
+		);
53
+		add_action('wp_ajax_save_payer_details', ['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']);
54
+		add_action(
55
+			'wp_ajax_nopriv_save_payer_details',
56
+			['EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details']
57
+		);
58
+		add_action(
59
+			'wp_ajax_get_transaction_details_for_gateways',
60
+			['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details']
61
+		);
62
+		add_action(
63
+			'wp_ajax_nopriv_get_transaction_details_for_gateways',
64
+			['EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details']
65
+		);
66
+		add_filter(
67
+			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
68
+			['EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'],
69
+			10,
70
+			1
71
+		);
72
+	}
73
+
74
+
75
+	/**
76
+	 *    ajax switch_spco_billing_form
77
+	 *
78
+	 */
79
+	public static function switch_spco_billing_form()
80
+	{
81
+		EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
82
+	}
83
+
84
+
85
+	/**
86
+	 *    ajax save_payer_details
87
+	 *
88
+	 */
89
+	public static function save_payer_details()
90
+	{
91
+		EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
92
+	}
93
+
94
+
95
+	/**
96
+	 *    ajax get_transaction_details
97
+	 *
98
+	 */
99
+	public static function get_transaction_details()
100
+	{
101
+		EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
102
+	}
103
+
104
+
105
+	/**
106
+	 * bypass_recaptcha_for_load_payment_method
107
+	 *
108
+	 * @access public
109
+	 * @return array
110
+	 * @throws InvalidArgumentException
111
+	 * @throws InvalidDataTypeException
112
+	 * @throws InvalidInterfaceException
113
+	 */
114
+	public static function bypass_recaptcha_for_load_payment_method()
115
+	{
116
+		return [
117
+			'EESID'  => EE_Registry::instance()->SSN->id(),
118
+			'step'   => 'payment_options',
119
+			'action' => 'spco_billing_form',
120
+		];
121
+	}
122
+
123
+
124
+	/**
125
+	 *    class constructor
126
+	 *
127
+	 * @access    public
128
+	 * @param EE_Checkout $checkout
129
+	 */
130
+	public function __construct(EE_Checkout $checkout)
131
+	{
132
+		$this->request   = EED_Single_Page_Checkout::getRequest();
133
+		$this->_slug     = 'payment_options';
134
+		$this->_name     = esc_html__('Payment Options', 'event_espresso');
135
+		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/payment_options_main.template.php';
136
+		$this->checkout  = $checkout;
137
+		$this->_reset_success_message();
138
+		$this->set_instructions(
139
+			esc_html__(
140
+				'Please select a method of payment and provide any necessary billing information before proceeding.',
141
+				'event_espresso'
142
+			)
143
+		);
144
+	}
145
+
146
+
147
+	/**
148
+	 * @return null
149
+	 */
150
+	public function line_item_display()
151
+	{
152
+		return $this->line_item_display;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @param null $line_item_display
158
+	 */
159
+	public function set_line_item_display($line_item_display)
160
+	{
161
+		$this->line_item_display = $line_item_display;
162
+	}
163
+
164
+
165
+	/**
166
+	 * @return boolean
167
+	 */
168
+	public function handle_IPN_in_this_request()
169
+	{
170
+		return $this->handle_IPN_in_this_request;
171
+	}
172
+
173
+
174
+	/**
175
+	 * @param boolean $handle_IPN_in_this_request
176
+	 */
177
+	public function set_handle_IPN_in_this_request($handle_IPN_in_this_request)
178
+	{
179
+		$this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
180
+	}
181
+
182
+
183
+	/**
184
+	 * translate_js_strings
185
+	 *
186
+	 * @return void
187
+	 */
188
+	public function translate_js_strings()
189
+	{
190
+		EE_Registry::$i18n_js_strings['no_payment_method']      = esc_html__(
191
+			'Please select a method of payment in order to continue.',
192
+			'event_espresso'
193
+		);
194
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
195
+			'A valid method of payment could not be determined. Please refresh the page and try again.',
196
+			'event_espresso'
197
+		);
198
+		EE_Registry::$i18n_js_strings['forwarding_to_offsite']  = esc_html__(
199
+			'Forwarding to Secure Payment Provider.',
200
+			'event_espresso'
201
+		);
202
+	}
203
+
204
+
205
+	/**
206
+	 * enqueue_styles_and_scripts
207
+	 *
208
+	 * @return void
209
+	 * @throws EE_Error
210
+	 * @throws InvalidArgumentException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidInterfaceException
213
+	 * @throws ReflectionException
214
+	 */
215
+	public function enqueue_styles_and_scripts()
216
+	{
217
+		$transaction = $this->checkout->transaction;
218
+		// if the transaction isn't set or nothing is owed on it, don't enqueue any JS
219
+		if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
220
+			return;
221
+		}
222
+		foreach (
223
+			EEM_Payment_Method::instance()->get_all_for_transaction(
224
+				$transaction,
225
+				EEM_Payment_Method::scope_cart
226
+			) as $payment_method
227
+		) {
228
+			$type_obj = $payment_method->type_obj();
229
+			if ($type_obj instanceof EE_PMT_Base) {
230
+				$billing_form = $type_obj->generate_new_billing_form($transaction);
231
+				if ($billing_form instanceof EE_Form_Section_Proper) {
232
+					$billing_form->enqueue_js();
233
+				}
234
+			}
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * initialize_reg_step
241
+	 *
242
+	 * @return bool
243
+	 * @throws EE_Error
244
+	 * @throws InvalidArgumentException
245
+	 * @throws ReflectionException
246
+	 * @throws InvalidDataTypeException
247
+	 * @throws InvalidInterfaceException
248
+	 */
249
+	public function initialize_reg_step()
250
+	{
251
+		// TODO: if /when we implement donations, then this will need overriding
252
+		if (
253
+			// don't need payment options for:
254
+			// registrations made via the admin
255
+			// completed transactions
256
+			// overpaid transactions
257
+			// $ 0.00 transactions(no payment required)
258
+			! $this->checkout->payment_required()
259
+			// but do NOT remove if current action being called belongs to this reg step
260
+			&& ! is_callable([$this, $this->checkout->action])
261
+			&& ! $this->completed()
262
+		) {
263
+			// and if so, then we no longer need the Payment Options step
264
+			if ($this->is_current_step()) {
265
+				$this->checkout->generate_reg_form = false;
266
+			}
267
+			$this->checkout->remove_reg_step($this->_slug);
268
+			// DEBUG LOG
269
+			// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
270
+			return false;
271
+		}
272
+		// load EEM_Payment_Method
273
+		EE_Registry::instance()->load_model('Payment_Method');
274
+		// get all active payment methods
275
+		$this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
276
+			$this->checkout->transaction,
277
+			EEM_Payment_Method::scope_cart
278
+		);
279
+		return true;
280
+	}
281
+
282
+
283
+	/**
284
+	 * @return EE_Form_Section_Proper
285
+	 * @throws EE_Error
286
+	 * @throws InvalidArgumentException
287
+	 * @throws ReflectionException
288
+	 * @throws EntityNotFoundException
289
+	 * @throws InvalidDataTypeException
290
+	 * @throws InvalidInterfaceException
291
+	 * @throws InvalidStatusException
292
+	 */
293
+	public function generate_reg_form()
294
+	{
295
+		// reset in case someone changes their mind
296
+		$this->_reset_selected_method_of_payment();
297
+		// set some defaults
298
+		$this->checkout->selected_method_of_payment = 'payments_closed';
299
+		$registrations_requiring_payment            = [];
300
+		$registrations_for_free_events              = [];
301
+		$registrations_requiring_pre_approval       = [];
302
+		$sold_out_events                            = [];
303
+		$insufficient_spaces_available              = [];
304
+		$no_payment_required                        = true;
305
+		// loop thru registrations to gather info
306
+		$registrations         = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
307
+		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
308
+			$registrations,
309
+			$this->checkout->revisit
310
+		);
311
+		foreach ($registrations as $REG_ID => $registration) {
312
+			/** @var $registration EE_Registration */
313
+			// has this registration lost it's space ?
314
+			if (isset($ejected_registrations[ $REG_ID ])) {
315
+				if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) {
316
+					$sold_out_events[ $registration->event()->ID() ] = $registration->event();
317
+				} else {
318
+					$insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
319
+				}
320
+				continue;
321
+			}
322
+			// event requires admin approval
323
+			if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
324
+				// add event to list of events with pre-approval reg status
325
+				$registrations_requiring_pre_approval[ $REG_ID ] = $registration;
326
+				do_action(
327
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
328
+					$registration->event(),
329
+					$this
330
+				);
331
+				continue;
332
+			}
333
+			if (
334
+				$this->checkout->revisit
335
+				&& $registration->status_ID() !== EEM_Registration::status_id_approved
336
+				&& (
337
+					$registration->event()->is_sold_out()
338
+					|| $registration->event()->is_sold_out(true)
339
+				)
340
+			) {
341
+				// add event to list of events that are sold out
342
+				$sold_out_events[ $registration->event()->ID() ] = $registration->event();
343
+				do_action(
344
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
345
+					$registration->event(),
346
+					$this
347
+				);
348
+				continue;
349
+			}
350
+			// are they allowed to pay now and is there monies owing?
351
+			if ($registration->owes_monies_and_can_pay()) {
352
+				$registrations_requiring_payment[ $REG_ID ] = $registration;
353
+				do_action(
354
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
355
+					$registration->event(),
356
+					$this
357
+				);
358
+			} elseif (
359
+				! $this->checkout->revisit
360
+					  && $registration->status_ID() !== EEM_Registration::status_id_not_approved
361
+					  && $registration->ticket()->is_free()
362
+			) {
363
+				$registrations_for_free_events[ $registration->ticket()->ID() ] = $registration;
364
+			}
365
+		}
366
+		$subsections = [];
367
+		// now decide which template to load
368
+		if (! empty($sold_out_events)) {
369
+			$subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
370
+		}
371
+		if (! empty($insufficient_spaces_available)) {
372
+			$subsections['insufficient_space'] = $this->_insufficient_spaces_available(
373
+				$insufficient_spaces_available
374
+			);
375
+		}
376
+		if (! empty($registrations_requiring_pre_approval)) {
377
+			$subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
378
+				$registrations_requiring_pre_approval
379
+			);
380
+		}
381
+		if (! empty($registrations_for_free_events)) {
382
+			$subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
383
+		}
384
+		if (! empty($registrations_requiring_payment)) {
385
+			if ($this->checkout->amount_owing > 0) {
386
+				// autoload Line_Item_Display classes
387
+				EEH_Autoloader::register_line_item_filter_autoloaders();
388
+				$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
389
+					apply_filters(
390
+						'FHEE__SPCO__EE_Line_Item_Filter_Collection',
391
+						new EE_Line_Item_Filter_Collection()
392
+					),
393
+					$this->checkout->cart->get_grand_total()
394
+				);
395
+				/** @var EE_Line_Item $filtered_line_item_tree */
396
+				$filtered_line_item_tree = $line_item_filter_processor->process();
397
+				EEH_Autoloader::register_line_item_display_autoloaders();
398
+				$this->set_line_item_display(new EE_Line_Item_Display('spco'));
399
+				$subsections['payment_options'] = $this->_display_payment_options(
400
+					$this->line_item_display->display_line_item(
401
+						$filtered_line_item_tree,
402
+						['registrations' => $registrations]
403
+					)
404
+				);
405
+				$this->checkout->amount_owing   = $filtered_line_item_tree->total();
406
+				$this->_apply_registration_payments_to_amount_owing($registrations);
407
+			}
408
+			$no_payment_required = false;
409
+		} else {
410
+			$this->_hide_reg_step_submit_button_if_revisit();
411
+		}
412
+		$this->_save_selected_method_of_payment();
413
+
414
+		$subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
415
+		$subsections['extra_hidden_inputs']   = $this->_extra_hidden_inputs($no_payment_required);
416
+
417
+		return new EE_Form_Section_Proper(
418
+			[
419
+				'name'            => $this->reg_form_name(),
420
+				'html_id'         => $this->reg_form_name(),
421
+				'subsections'     => $subsections,
422
+				'layout_strategy' => new EE_No_Layout(),
423
+			]
424
+		);
425
+	}
426
+
427
+
428
+	/**
429
+	 * add line item filters required for this reg step
430
+	 * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks():
431
+	 *        add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options',
432
+	 *        'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the
433
+	 *        payment options reg step, can apply these filters via the following: apply_filters(
434
+	 *        'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing
435
+	 *        filter collection by passing that instead of instantiating a new collection
436
+	 *
437
+	 * @param EE_Line_Item_Filter_Collection $line_item_filter_collection
438
+	 * @return EE_Line_Item_Filter_Collection
439
+	 * @throws EE_Error
440
+	 * @throws InvalidArgumentException
441
+	 * @throws ReflectionException
442
+	 * @throws EntityNotFoundException
443
+	 * @throws InvalidDataTypeException
444
+	 * @throws InvalidInterfaceException
445
+	 * @throws InvalidStatusException
446
+	 */
447
+	public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection)
448
+	{
449
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
450
+			return $line_item_filter_collection;
451
+		}
452
+		if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
453
+			return $line_item_filter_collection;
454
+		}
455
+		if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
456
+			return $line_item_filter_collection;
457
+		}
458
+		$line_item_filter_collection->add(
459
+			new EE_Billable_Line_Item_Filter(
460
+				EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations(
461
+					EE_Registry::instance()->SSN->checkout()->transaction->registrations(
462
+						EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
463
+					)
464
+				)
465
+			)
466
+		);
467
+		$line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
468
+		return $line_item_filter_collection;
469
+	}
470
+
471
+
472
+	/**
473
+	 * remove_ejected_registrations
474
+	 * if a registrant has lost their potential space at an event due to lack of payment,
475
+	 * then this method removes them from the list of registrations being paid for during this request
476
+	 *
477
+	 * @param EE_Registration[] $registrations
478
+	 * @return EE_Registration[]
479
+	 * @throws EE_Error
480
+	 * @throws InvalidArgumentException
481
+	 * @throws ReflectionException
482
+	 * @throws EntityNotFoundException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 * @throws InvalidStatusException
486
+	 */
487
+	public static function remove_ejected_registrations(array $registrations)
488
+	{
489
+		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
490
+			$registrations,
491
+			EE_Registry::instance()->SSN->checkout()->revisit
492
+		);
493
+		foreach ($registrations as $REG_ID => $registration) {
494
+			// has this registration lost it's space ?
495
+			if (isset($ejected_registrations[ $REG_ID ])) {
496
+				unset($registrations[ $REG_ID ]);
497
+			}
498
+		}
499
+		return $registrations;
500
+	}
501
+
502
+
503
+	/**
504
+	 * find_registrations_that_lost_their_space
505
+	 * If a registrant chooses an offline payment method like Invoice,
506
+	 * then no space is reserved for them at the event until they fully pay fo that site
507
+	 * (unless the event's default reg status is set to APPROVED)
508
+	 * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales,
509
+	 * then this method will determine which registrations have lost the ability to complete the reg process.
510
+	 *
511
+	 * @param EE_Registration[] $registrations
512
+	 * @param bool              $revisit
513
+	 * @return array
514
+	 * @throws EE_Error
515
+	 * @throws InvalidArgumentException
516
+	 * @throws ReflectionException
517
+	 * @throws EntityNotFoundException
518
+	 * @throws InvalidDataTypeException
519
+	 * @throws InvalidInterfaceException
520
+	 * @throws InvalidStatusException
521
+	 */
522
+	public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false)
523
+	{
524
+		// registrations per event
525
+		$event_reg_count = [];
526
+		// spaces left per event
527
+		$event_spaces_remaining = [];
528
+		// tickets left sorted by ID
529
+		$tickets_remaining = [];
530
+		// registrations that have lost their space
531
+		$ejected_registrations = [];
532
+		foreach ($registrations as $REG_ID => $registration) {
533
+			if (
534
+				$registration->status_ID() === EEM_Registration::status_id_approved
535
+				|| apply_filters(
536
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
537
+					false,
538
+					$registration,
539
+					$revisit
540
+				)
541
+			) {
542
+				continue;
543
+			}
544
+			$EVT_ID = $registration->event_ID();
545
+			$ticket = $registration->ticket();
546
+			if (! isset($tickets_remaining[ $ticket->ID() ])) {
547
+				$tickets_remaining[ $ticket->ID() ] = $ticket->remaining();
548
+			}
549
+			if ($tickets_remaining[ $ticket->ID() ] > 0) {
550
+				if (! isset($event_reg_count[ $EVT_ID ])) {
551
+					$event_reg_count[ $EVT_ID ] = 0;
552
+				}
553
+				$event_reg_count[ $EVT_ID ]++;
554
+				if (! isset($event_spaces_remaining[ $EVT_ID ])) {
555
+					$event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale();
556
+				}
557
+			}
558
+			if (
559
+				$revisit
560
+				&& ($tickets_remaining[ $ticket->ID() ] === 0
561
+					|| $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ]
562
+				)
563
+			) {
564
+				$ejected_registrations[ $REG_ID ] = $registration->event();
565
+				if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
566
+					/** @type EE_Registration_Processor $registration_processor */
567
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
568
+					// at this point, we should have enough details about the registrant to consider the registration
569
+					// NOT incomplete
570
+					$registration_processor->manually_update_registration_status(
571
+						$registration,
572
+						EEM_Registration::status_id_wait_list
573
+					);
574
+				}
575
+			}
576
+		}
577
+		return $ejected_registrations;
578
+	}
579
+
580
+
581
+	/**
582
+	 * _hide_reg_step_submit_button
583
+	 * removes the html for the reg step submit button
584
+	 * by replacing it with an empty string via filter callback
585
+	 *
586
+	 * @return void
587
+	 */
588
+	protected function _adjust_registration_status_if_event_old_sold()
589
+	{
590
+	}
591
+
592
+
593
+	/**
594
+	 * _hide_reg_step_submit_button
595
+	 * removes the html for the reg step submit button
596
+	 * by replacing it with an empty string via filter callback
597
+	 *
598
+	 * @return void
599
+	 */
600
+	protected function _hide_reg_step_submit_button_if_revisit()
601
+	{
602
+		if ($this->checkout->revisit) {
603
+			add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
604
+		}
605
+	}
606
+
607
+
608
+	/**
609
+	 * sold_out_events
610
+	 * displays notices regarding events that have sold out since hte registrant first signed up
611
+	 *
612
+	 * @param EE_Event[] $sold_out_events_array
613
+	 * @return EE_Form_Section_Proper
614
+	 * @throws EE_Error
615
+	 */
616
+	private function _sold_out_events($sold_out_events_array = [])
617
+	{
618
+		// set some defaults
619
+		$this->checkout->selected_method_of_payment = 'events_sold_out';
620
+		$sold_out_events                            = '';
621
+		foreach ($sold_out_events_array as $sold_out_event) {
622
+			$sold_out_events .= EEH_HTML::li(
623
+				EEH_HTML::span(
624
+					'  ' . $sold_out_event->name(),
625
+					'',
626
+					'dashicons dashicons-marker ee-icon-size-16 pink-text'
627
+				)
628
+			);
629
+		}
630
+		return new EE_Form_Section_Proper(
631
+			[
632
+				'layout_strategy' => new EE_Template_Layout(
633
+					[
634
+						'layout_template_file' => SPCO_REG_STEPS_PATH
635
+												  . $this->_slug
636
+												  . '/sold_out_events.template.php',
637
+						'template_args'        => apply_filters(
638
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
639
+							[
640
+								'sold_out_events'     => $sold_out_events,
641
+								'sold_out_events_msg' => apply_filters(
642
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
643
+									sprintf(
644
+										esc_html__(
645
+											'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s',
646
+											'event_espresso'
647
+										),
648
+										'<strong>',
649
+										'</strong>',
650
+										'<br />'
651
+									)
652
+								),
653
+							]
654
+						),
655
+					]
656
+				),
657
+			]
658
+		);
659
+	}
660
+
661
+
662
+	/**
663
+	 * _insufficient_spaces_available
664
+	 * displays notices regarding events that do not have enough remaining spaces
665
+	 * to satisfy the current number of registrations looking to pay
666
+	 *
667
+	 * @param EE_Event[] $insufficient_spaces_events_array
668
+	 * @return EE_Form_Section_Proper
669
+	 * @throws EE_Error
670
+	 * @throws ReflectionException
671
+	 */
672
+	private function _insufficient_spaces_available($insufficient_spaces_events_array = [])
673
+	{
674
+		// set some defaults
675
+		$this->checkout->selected_method_of_payment = 'invoice';
676
+		$insufficient_space_events                  = '';
677
+		foreach ($insufficient_spaces_events_array as $event) {
678
+			if ($event instanceof EE_Event) {
679
+				$insufficient_space_events .= EEH_HTML::li(
680
+					EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
681
+				);
682
+			}
683
+		}
684
+		return new EE_Form_Section_Proper(
685
+			[
686
+				'subsections'     => [
687
+					'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
688
+					'extra_hidden_inputs'   => $this->_extra_hidden_inputs(),
689
+				],
690
+				'layout_strategy' => new EE_Template_Layout(
691
+					[
692
+						'layout_template_file' => SPCO_REG_STEPS_PATH
693
+												  . $this->_slug
694
+												  . '/sold_out_events.template.php',
695
+						'template_args'        => apply_filters(
696
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args',
697
+							[
698
+								'sold_out_events'     => $insufficient_space_events,
699
+								'sold_out_events_msg' => apply_filters(
700
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg',
701
+									esc_html__(
702
+										'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
703
+										'event_espresso'
704
+									)
705
+								),
706
+							]
707
+						),
708
+					]
709
+				),
710
+			]
711
+		);
712
+	}
713
+
714
+
715
+	/**
716
+	 * registrations_requiring_pre_approval
717
+	 *
718
+	 * @param array $registrations_requiring_pre_approval
719
+	 * @return EE_Form_Section_Proper
720
+	 * @throws EE_Error
721
+	 * @throws EntityNotFoundException
722
+	 * @throws ReflectionException
723
+	 */
724
+	private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = [])
725
+	{
726
+		$events_requiring_pre_approval = [];
727
+		foreach ($registrations_requiring_pre_approval as $registration) {
728
+			if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
729
+				$events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
730
+					EEH_HTML::span(
731
+						'',
732
+						'',
733
+						'dashicons dashicons-marker ee-icon-size-16 orange-text'
734
+					)
735
+					. EEH_HTML::span($registration->event()->name(), '', 'orange-text')
736
+				);
737
+			}
738
+		}
739
+		return new EE_Form_Section_Proper(
740
+			[
741
+				'layout_strategy' => new EE_Template_Layout(
742
+					[
743
+						'layout_template_file' => SPCO_REG_STEPS_PATH
744
+												  . $this->_slug
745
+												  . '/events_requiring_pre_approval.template.php', // layout_template
746
+						'template_args'        => apply_filters(
747
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
748
+							[
749
+								'events_requiring_pre_approval'     => implode('', $events_requiring_pre_approval),
750
+								'events_requiring_pre_approval_msg' => apply_filters(
751
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
752
+									esc_html__(
753
+										'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
754
+										'event_espresso'
755
+									)
756
+								),
757
+							]
758
+						),
759
+					]
760
+				),
761
+			]
762
+		);
763
+	}
764
+
765
+
766
+	/**
767
+	 * _no_payment_required
768
+	 *
769
+	 * @param EE_Event[] $registrations_for_free_events
770
+	 * @return EE_Form_Section_Proper
771
+	 * @throws EE_Error
772
+	 */
773
+	private function _no_payment_required($registrations_for_free_events = [])
774
+	{
775
+		// set some defaults
776
+		$this->checkout->selected_method_of_payment = 'no_payment_required';
777
+		// generate no_payment_required form
778
+		return new EE_Form_Section_Proper(
779
+			[
780
+				'layout_strategy' => new EE_Template_Layout(
781
+					[
782
+						'layout_template_file' => SPCO_REG_STEPS_PATH
783
+												  . $this->_slug
784
+												  . '/no_payment_required.template.php', // layout_template
785
+						'template_args'        => apply_filters(
786
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
787
+							[
788
+								'revisit'                       => $this->checkout->revisit,
789
+								'registrations'                 => [],
790
+								'ticket_count'                  => [],
791
+								'registrations_for_free_events' => $registrations_for_free_events,
792
+								'no_payment_required_msg'       => EEH_HTML::p(
793
+									esc_html__('This is a free event, so no billing will occur.', 'event_espresso')
794
+								),
795
+							]
796
+						),
797
+					]
798
+				),
799
+			]
800
+		);
801
+	}
802
+
803
+
804
+	/**
805
+	 * _display_payment_options
806
+	 *
807
+	 * @param string $transaction_details
808
+	 * @return EE_Form_Section_Proper
809
+	 * @throws EE_Error
810
+	 * @throws InvalidArgumentException
811
+	 * @throws InvalidDataTypeException
812
+	 * @throws InvalidInterfaceException
813
+	 */
814
+	private function _display_payment_options($transaction_details = '')
815
+	{
816
+		// has method_of_payment been set by no-js user?
817
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
818
+		// build payment options form
819
+		return apply_filters(
820
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form',
821
+			new EE_Form_Section_Proper(
822
+				[
823
+					'subsections'     => [
824
+						'before_payment_options' => apply_filters(
825
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
826
+							new EE_Form_Section_Proper(
827
+								['layout_strategy' => new EE_Div_Per_Section_Layout()]
828
+							)
829
+						),
830
+						'payment_options'        => $this->_setup_payment_options(),
831
+						'after_payment_options'  => apply_filters(
832
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
833
+							new EE_Form_Section_Proper(
834
+								['layout_strategy' => new EE_Div_Per_Section_Layout()]
835
+							)
836
+						),
837
+					],
838
+					'layout_strategy' => new EE_Template_Layout(
839
+						[
840
+							'layout_template_file' => $this->_template,
841
+							'template_args'        => apply_filters(
842
+								'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args',
843
+								[
844
+									'reg_count'                 => $this->line_item_display->total_items(),
845
+									'transaction_details'       => $transaction_details,
846
+									'available_payment_methods' => [],
847
+								]
848
+							),
849
+						]
850
+					),
851
+				]
852
+			)
853
+		);
854
+	}
855
+
856
+
857
+	/**
858
+	 * _extra_hidden_inputs
859
+	 *
860
+	 * @param bool $no_payment_required
861
+	 * @return EE_Form_Section_Proper
862
+	 * @throws EE_Error
863
+	 * @throws ReflectionException
864
+	 */
865
+	private function _extra_hidden_inputs($no_payment_required = true)
866
+	{
867
+		return new EE_Form_Section_Proper(
868
+			[
869
+				'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
870
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
871
+				'subsections'     => [
872
+					'spco_no_payment_required' => new EE_Hidden_Input(
873
+						[
874
+							'normalization_strategy' => new EE_Boolean_Normalization(),
875
+							'html_name'              => 'spco_no_payment_required',
876
+							'html_id'                => 'spco-no-payment-required-payment_options',
877
+							'default'                => $no_payment_required,
878
+						]
879
+					),
880
+					'spco_transaction_id'      => new EE_Fixed_Hidden_Input(
881
+						[
882
+							'normalization_strategy' => new EE_Int_Normalization(),
883
+							'html_name'              => 'spco_transaction_id',
884
+							'html_id'                => 'spco-transaction-id',
885
+							'default'                => $this->checkout->transaction->ID(),
886
+						]
887
+					),
888
+				],
889
+			]
890
+		);
891
+	}
892
+
893
+
894
+	/**
895
+	 *    _apply_registration_payments_to_amount_owing
896
+	 *
897
+	 * @param array $registrations
898
+	 * @throws EE_Error
899
+	 */
900
+	protected function _apply_registration_payments_to_amount_owing(array $registrations)
901
+	{
902
+		$payments = [];
903
+		foreach ($registrations as $registration) {
904
+			if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
905
+				$payments += $registration->registration_payments();
906
+			}
907
+		}
908
+		if (! empty($payments)) {
909
+			foreach ($payments as $payment) {
910
+				if ($payment instanceof EE_Registration_Payment) {
911
+					$this->checkout->amount_owing -= $payment->amount();
912
+				}
913
+			}
914
+		}
915
+	}
916
+
917
+
918
+	/**
919
+	 *    _reset_selected_method_of_payment
920
+	 *
921
+	 * @access    private
922
+	 * @param bool $force_reset
923
+	 * @return void
924
+	 * @throws InvalidArgumentException
925
+	 * @throws InvalidDataTypeException
926
+	 * @throws InvalidInterfaceException
927
+	 */
928
+	private function _reset_selected_method_of_payment($force_reset = false)
929
+	{
930
+		/** @var RequestInterface $request */
931
+		$request              = LoaderFactory::getLoader()->getShared(RequestInterface::class);
932
+		$reset_payment_method = $request->getRequestParam('reset_payment_method', $force_reset, 'bool');
933
+		if ($reset_payment_method) {
934
+			$this->checkout->selected_method_of_payment = null;
935
+			$this->checkout->payment_method             = null;
936
+			$this->checkout->billing_form               = null;
937
+			$this->_save_selected_method_of_payment();
938
+		}
939
+	}
940
+
941
+
942
+	/**
943
+	 * _save_selected_method_of_payment
944
+	 * stores the selected_method_of_payment in the session
945
+	 * so that it's available for all subsequent requests including AJAX
946
+	 *
947
+	 * @access        private
948
+	 * @param string $selected_method_of_payment
949
+	 * @return void
950
+	 * @throws InvalidArgumentException
951
+	 * @throws InvalidDataTypeException
952
+	 * @throws InvalidInterfaceException
953
+	 */
954
+	private function _save_selected_method_of_payment($selected_method_of_payment = '')
955
+	{
956
+		$selected_method_of_payment = ! empty($selected_method_of_payment)
957
+			? $selected_method_of_payment
958
+			: $this->checkout->selected_method_of_payment;
959
+		EE_Registry::instance()->SSN->set_session_data(
960
+			['selected_method_of_payment' => $selected_method_of_payment]
961
+		);
962
+	}
963
+
964
+
965
+	/**
966
+	 * _setup_payment_options
967
+	 *
968
+	 * @return EE_Form_Section_Proper
969
+	 * @throws EE_Error
970
+	 * @throws InvalidArgumentException
971
+	 * @throws InvalidDataTypeException
972
+	 * @throws InvalidInterfaceException
973
+	 */
974
+	public function _setup_payment_options()
975
+	{
976
+		// load payment method classes
977
+		$this->checkout->available_payment_methods = $this->_get_available_payment_methods();
978
+		if (empty($this->checkout->available_payment_methods)) {
979
+			EE_Error::add_error(
980
+				apply_filters(
981
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods',
982
+					sprintf(
983
+						esc_html__(
984
+							'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.',
985
+							'event_espresso'
986
+						),
987
+						'<br>',
988
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
989
+					)
990
+				),
991
+				__FILE__,
992
+				__FUNCTION__,
993
+				__LINE__
994
+			);
995
+		}
996
+		// switch up header depending on number of available payment methods
997
+		$payment_method_header     = count($this->checkout->available_payment_methods) > 1
998
+			? apply_filters(
999
+				'FHEE__registration_page_payment_options__method_of_payment_hdr',
1000
+				esc_html__('Please Select Your Method of Payment', 'event_espresso')
1001
+			)
1002
+			: apply_filters(
1003
+				'FHEE__registration_page_payment_options__method_of_payment_hdr',
1004
+				esc_html__('Method of Payment', 'event_espresso')
1005
+			);
1006
+		$available_payment_methods = [
1007
+			// display the "Payment Method" header
1008
+			'payment_method_header' => new EE_Form_Section_HTML(
1009
+				apply_filters(
1010
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__payment_method_header',
1011
+					EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr'),
1012
+					$payment_method_header
1013
+				)
1014
+			),
1015
+		];
1016
+		// the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
1017
+		$available_payment_method_options = [];
1018
+		$default_payment_method_option    = [];
1019
+		// additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
1020
+		$payment_methods_billing_info = [
1021
+			new EE_Form_Section_HTML(
1022
+				EEH_HTML::div('<br />', '', '', 'clear:both;')
1023
+			),
1024
+		];
1025
+		// loop through payment methods
1026
+		foreach ($this->checkout->available_payment_methods as $payment_method) {
1027
+			if ($payment_method instanceof EE_Payment_Method) {
1028
+				$payment_method_button = EEH_HTML::img(
1029
+					$payment_method->button_url(),
1030
+					$payment_method->name(),
1031
+					'spco-payment-method-' . $payment_method->slug() . '-btn-img',
1032
+					'spco-payment-method-btn-img'
1033
+				);
1034
+				// check if any payment methods are set as default
1035
+				// if payment method is already selected OR nothing is selected and this payment method should be
1036
+				// open_by_default
1037
+				if (
1038
+					($this->checkout->selected_method_of_payment === $payment_method->slug())
1039
+					|| (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1040
+				) {
1041
+					$this->checkout->selected_method_of_payment = $payment_method->slug();
1042
+					$this->_save_selected_method_of_payment();
1043
+					$default_payment_method_option[ $payment_method->slug() ] = $payment_method_button;
1044
+				} else {
1045
+					$available_payment_method_options[ $payment_method->slug() ] = $payment_method_button;
1046
+				}
1047
+				$payment_methods_billing_info[ $payment_method->slug() . '-info' ] =
1048
+					$this->_payment_method_billing_info(
1049
+						$payment_method
1050
+					);
1051
+			}
1052
+		}
1053
+		// prepend available_payment_method_options with default_payment_method_option so that it appears first in list
1054
+		// of PMs
1055
+		$available_payment_method_options = $default_payment_method_option + $available_payment_method_options;
1056
+		// now generate the actual form  inputs
1057
+		$available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs(
1058
+			$available_payment_method_options
1059
+		);
1060
+		$available_payment_methods                              += $payment_methods_billing_info;
1061
+		// build the available payment methods form
1062
+		return new EE_Form_Section_Proper(
1063
+			[
1064
+				'html_id'         => 'spco-available-methods-of-payment-dv',
1065
+				'subsections'     => $available_payment_methods,
1066
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1067
+			]
1068
+		);
1069
+	}
1070
+
1071
+
1072
+	/**
1073
+	 * _get_available_payment_methods
1074
+	 *
1075
+	 * @return EE_Payment_Method[]
1076
+	 * @throws EE_Error
1077
+	 * @throws InvalidArgumentException
1078
+	 * @throws InvalidDataTypeException
1079
+	 * @throws InvalidInterfaceException
1080
+	 */
1081
+	protected function _get_available_payment_methods()
1082
+	{
1083
+		if (! empty($this->checkout->available_payment_methods)) {
1084
+			return $this->checkout->available_payment_methods;
1085
+		}
1086
+		$available_payment_methods = [];
1087
+		$EEM_Payment_Method        = EEM_Payment_Method::instance();
1088
+		// get all active payment methods
1089
+		$payment_methods = $EEM_Payment_Method->get_all_for_transaction(
1090
+			$this->checkout->transaction,
1091
+			EEM_Payment_Method::scope_cart
1092
+		);
1093
+		foreach ($payment_methods as $payment_method) {
1094
+			if ($payment_method instanceof EE_Payment_Method) {
1095
+				$available_payment_methods[ $payment_method->slug() ] = $payment_method;
1096
+			}
1097
+		}
1098
+		return $available_payment_methods;
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 *    _available_payment_method_inputs
1104
+	 *
1105
+	 * @access    private
1106
+	 * @param array $available_payment_method_options
1107
+	 * @return    EE_Form_Section_Proper
1108
+	 * @throws EE_Error
1109
+	 * @throws EE_Error
1110
+	 */
1111
+	private function _available_payment_method_inputs($available_payment_method_options = [])
1112
+	{
1113
+		// generate inputs
1114
+		return new EE_Form_Section_Proper(
1115
+			[
1116
+				'html_id'         => 'ee-available-payment-method-inputs',
1117
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1118
+				'subsections'     => [
1119
+					'' => new EE_Radio_Button_Input(
1120
+						$available_payment_method_options,
1121
+						[
1122
+							'html_name'          => 'selected_method_of_payment',
1123
+							'html_class'         => 'spco-payment-method',
1124
+							'default'            => $this->checkout->selected_method_of_payment,
1125
+							'label_size'         => 11,
1126
+							'enforce_label_size' => true,
1127
+						]
1128
+					),
1129
+				],
1130
+			]
1131
+		);
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 *    _payment_method_billing_info
1137
+	 *
1138
+	 * @access    private
1139
+	 * @param EE_Payment_Method $payment_method
1140
+	 * @return EE_Form_Section_Proper
1141
+	 * @throws EE_Error
1142
+	 * @throws InvalidArgumentException
1143
+	 * @throws InvalidDataTypeException
1144
+	 * @throws InvalidInterfaceException
1145
+	 */
1146
+	private function _payment_method_billing_info(EE_Payment_Method $payment_method)
1147
+	{
1148
+		$currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug();
1149
+		// generate the billing form for payment method
1150
+		$billing_form                 = $currently_selected
1151
+			? $this->_get_billing_form_for_payment_method($payment_method)
1152
+			: new EE_Form_Section_HTML();
1153
+		$this->checkout->billing_form = $currently_selected
1154
+			? $billing_form
1155
+			: $this->checkout->billing_form;
1156
+		// it's all in the details
1157
+		$info_html = EEH_HTML::h3(
1158
+			esc_html__('Important information regarding your payment', 'event_espresso'),
1159
+			'',
1160
+			'spco-payment-method-hdr'
1161
+		);
1162
+		// add some info regarding the step, either from what's saved in the admin,
1163
+		// or a default string depending on whether the PM has a billing form or not
1164
+		if ($payment_method->description()) {
1165
+			$payment_method_info = $payment_method->description();
1166
+		} elseif ($billing_form instanceof EE_Billing_Info_Form) {
1167
+			$payment_method_info = sprintf(
1168
+				esc_html__(
1169
+					'Please provide the following billing information, then click the "%1$s" button below in order to proceed.',
1170
+					'event_espresso'
1171
+				),
1172
+				$this->submit_button_text()
1173
+			);
1174
+		} else {
1175
+			$payment_method_info = sprintf(
1176
+				esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'),
1177
+				$this->submit_button_text()
1178
+			);
1179
+		}
1180
+		$info_html .= EEH_HTML::div(
1181
+			apply_filters(
1182
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info',
1183
+				$payment_method_info
1184
+			),
1185
+			'',
1186
+			'spco-payment-method-desc ee-attention'
1187
+		);
1188
+		return new EE_Form_Section_Proper(
1189
+			[
1190
+				'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1191
+				'html_class'      => 'spco-payment-method-info-dv',
1192
+				// only display the selected or default PM
1193
+				'html_style'      => $currently_selected ? '' : 'display:none;',
1194
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1195
+				'subsections'     => [
1196
+					'info'         => new EE_Form_Section_HTML($info_html),
1197
+					'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(),
1198
+				],
1199
+			]
1200
+		);
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * get_billing_form_html_for_payment_method
1206
+	 *
1207
+	 * @return bool
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws ReflectionException
1211
+	 * @throws InvalidDataTypeException
1212
+	 * @throws InvalidInterfaceException
1213
+	 */
1214
+	public function get_billing_form_html_for_payment_method()
1215
+	{
1216
+		// how have they chosen to pay?
1217
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1218
+		$this->checkout->payment_method             = $this->_get_payment_method_for_selected_method_of_payment();
1219
+		if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1220
+			return false;
1221
+		}
1222
+		if (
1223
+			apply_filters(
1224
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1225
+				false
1226
+			)
1227
+		) {
1228
+			EE_Error::add_success(
1229
+				apply_filters(
1230
+					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1231
+					sprintf(
1232
+						esc_html__(
1233
+							'You have selected "%s" as your method of payment. Please note the important payment information below.',
1234
+							'event_espresso'
1235
+						),
1236
+						$this->checkout->payment_method->name()
1237
+					)
1238
+				)
1239
+			);
1240
+		}
1241
+		// now generate billing form for selected method of payment
1242
+		$payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1243
+		// fill form with attendee info if applicable
1244
+		if (
1245
+			$payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
1246
+			&& $this->checkout->transaction_has_primary_registrant()
1247
+		) {
1248
+			$payment_method_billing_form->populate_from_attendee(
1249
+				$this->checkout->transaction->primary_registration()->attendee()
1250
+			);
1251
+		}
1252
+		// and debug content
1253
+		if (
1254
+			$payment_method_billing_form instanceof EE_Billing_Info_Form
1255
+			&& $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1256
+		) {
1257
+			$payment_method_billing_form =
1258
+				$this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1259
+					$payment_method_billing_form
1260
+				);
1261
+		}
1262
+		$billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper
1263
+			? $payment_method_billing_form->get_html()
1264
+			: '';
1265
+		$this->checkout->json_response->set_return_data(['payment_method_info' => $billing_info]);
1266
+		// localize validation rules for main form
1267
+		$this->checkout->current_step->reg_form->localize_validation_rules();
1268
+		$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1269
+		return true;
1270
+	}
1271
+
1272
+
1273
+	/**
1274
+	 * _get_billing_form_for_payment_method
1275
+	 *
1276
+	 * @param EE_Payment_Method $payment_method
1277
+	 * @return EE_Billing_Info_Form|EE_Form_Section_HTML
1278
+	 * @throws EE_Error
1279
+	 * @throws InvalidArgumentException
1280
+	 * @throws InvalidDataTypeException
1281
+	 * @throws InvalidInterfaceException
1282
+	 */
1283
+	private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method)
1284
+	{
1285
+		$billing_form = $payment_method->type_obj()->billing_form(
1286
+			$this->checkout->transaction,
1287
+			['amount_owing' => $this->checkout->amount_owing]
1288
+		);
1289
+		if ($billing_form instanceof EE_Billing_Info_Form) {
1290
+			if (
1291
+				apply_filters(
1292
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1293
+					false
1294
+				)
1295
+				&& $this->request->requestParamIsSet('payment_method')
1296
+			) {
1297
+				EE_Error::add_success(
1298
+					apply_filters(
1299
+						'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1300
+						sprintf(
1301
+							esc_html__(
1302
+								'You have selected "%s" as your method of payment. Please note the important payment information below.',
1303
+								'event_espresso'
1304
+							),
1305
+							$payment_method->name()
1306
+						)
1307
+					)
1308
+				);
1309
+			}
1310
+			return apply_filters(
1311
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
1312
+				$billing_form,
1313
+				$payment_method
1314
+			);
1315
+		}
1316
+		// no actual billing form, so return empty HTML form section
1317
+		return new EE_Form_Section_HTML();
1318
+	}
1319
+
1320
+
1321
+	/**
1322
+	 * _get_selected_method_of_payment
1323
+	 *
1324
+	 * @param boolean $required whether to throw an error if the "selected_method_of_payment"
1325
+	 *                          is not found in the incoming request
1326
+	 * @param string  $request_param
1327
+	 * @return NULL|string
1328
+	 * @throws EE_Error
1329
+	 * @throws InvalidArgumentException
1330
+	 * @throws InvalidDataTypeException
1331
+	 * @throws InvalidInterfaceException
1332
+	 */
1333
+	private function _get_selected_method_of_payment(
1334
+		$required = false,
1335
+		$request_param = 'selected_method_of_payment'
1336
+	) {
1337
+		// is selected_method_of_payment set in the request ?
1338
+		$selected_method_of_payment = $this->request->getRequestParam($request_param);
1339
+		if ($selected_method_of_payment) {
1340
+			// sanitize it
1341
+			$selected_method_of_payment = is_array($selected_method_of_payment)
1342
+				? array_shift($selected_method_of_payment)
1343
+				: $selected_method_of_payment;
1344
+			$selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
1345
+			// store it in the session so that it's available for all subsequent requests including AJAX
1346
+			$this->_save_selected_method_of_payment($selected_method_of_payment);
1347
+		} else {
1348
+			// or is is set in the session ?
1349
+			$selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data(
1350
+				'selected_method_of_payment'
1351
+			);
1352
+		}
1353
+		// do ya really really gotta have it?
1354
+		if (empty($selected_method_of_payment) && $required) {
1355
+			EE_Error::add_error(
1356
+				sprintf(
1357
+					esc_html__(
1358
+						'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.',
1359
+						'event_espresso'
1360
+					),
1361
+					'<br/>',
1362
+					'<br/>',
1363
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1364
+				),
1365
+				__FILE__,
1366
+				__FUNCTION__,
1367
+				__LINE__
1368
+			);
1369
+			return null;
1370
+		}
1371
+		return $selected_method_of_payment;
1372
+	}
1373
+
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+	/********************************************************************************************************/
1380
+	/***********************************  SWITCH PAYMENT METHOD  ************************************/
1381
+	/********************************************************************************************************/
1382
+	/**
1383
+	 * switch_payment_method
1384
+	 *
1385
+	 * @return bool
1386
+	 * @throws EE_Error
1387
+	 * @throws InvalidArgumentException
1388
+	 * @throws InvalidDataTypeException
1389
+	 * @throws InvalidInterfaceException
1390
+	 * @throws ReflectionException
1391
+	 */
1392
+	public function switch_payment_method()
1393
+	{
1394
+		if (! $this->_verify_payment_method_is_set()) {
1395
+			return false;
1396
+		}
1397
+		if (
1398
+			apply_filters(
1399
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1400
+				false
1401
+			)
1402
+		) {
1403
+			EE_Error::add_success(
1404
+				apply_filters(
1405
+					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1406
+					sprintf(
1407
+						esc_html__(
1408
+							'You have selected "%s" as your method of payment. Please note the important payment information below.',
1409
+							'event_espresso'
1410
+						),
1411
+						$this->checkout->payment_method->name()
1412
+					)
1413
+				)
1414
+			);
1415
+		}
1416
+		// generate billing form for selected method of payment if it hasn't been done already
1417
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1418
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1419
+				$this->checkout->payment_method
1420
+			);
1421
+		}
1422
+		// fill form with attendee info if applicable
1423
+		if (
1424
+			apply_filters(
1425
+				'FHEE__populate_billing_form_fields_from_attendee',
1426
+				(
1427
+				$this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
1428
+				&& $this->checkout->transaction_has_primary_registrant()
1429
+				),
1430
+				$this->checkout->billing_form,
1431
+				$this->checkout->transaction
1432
+			)
1433
+		) {
1434
+			$this->checkout->billing_form->populate_from_attendee(
1435
+				$this->checkout->transaction->primary_registration()->attendee()
1436
+			);
1437
+		}
1438
+		// and debug content
1439
+		if (
1440
+			$this->checkout->billing_form instanceof EE_Billing_Info_Form
1441
+			&& $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1442
+		) {
1443
+			$this->checkout->billing_form =
1444
+				$this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1445
+					$this->checkout->billing_form
1446
+				);
1447
+		}
1448
+		// get html and validation rules for form
1449
+		if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
1450
+			$this->checkout->json_response->set_return_data(
1451
+				['payment_method_info' => $this->checkout->billing_form->get_html()]
1452
+			);
1453
+			// localize validation rules for main form
1454
+			$this->checkout->billing_form->localize_validation_rules(true);
1455
+			$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1456
+		} else {
1457
+			$this->checkout->json_response->set_return_data(['payment_method_info' => '']);
1458
+		}
1459
+		// prevents advancement to next step
1460
+		$this->checkout->continue_reg = false;
1461
+		return true;
1462
+	}
1463
+
1464
+
1465
+	/**
1466
+	 * _verify_payment_method_is_set
1467
+	 *
1468
+	 * @return bool
1469
+	 * @throws EE_Error
1470
+	 * @throws InvalidArgumentException
1471
+	 * @throws ReflectionException
1472
+	 * @throws InvalidDataTypeException
1473
+	 * @throws InvalidInterfaceException
1474
+	 */
1475
+	protected function _verify_payment_method_is_set()
1476
+	{
1477
+		// generate billing form for selected method of payment if it hasn't been done already
1478
+		if (empty($this->checkout->selected_method_of_payment)) {
1479
+			// how have they chosen to pay?
1480
+			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1481
+		} else {
1482
+			// choose your own adventure based on method_of_payment
1483
+			switch ($this->checkout->selected_method_of_payment) {
1484
+				case 'events_sold_out':
1485
+					EE_Error::add_attention(
1486
+						apply_filters(
1487
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
1488
+							esc_html__(
1489
+								'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1490
+								'event_espresso'
1491
+							)
1492
+						),
1493
+						__FILE__,
1494
+						__FUNCTION__,
1495
+						__LINE__
1496
+					);
1497
+					return false;
1498
+				case 'payments_closed':
1499
+					EE_Error::add_attention(
1500
+						apply_filters(
1501
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
1502
+							esc_html__(
1503
+								'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.',
1504
+								'event_espresso'
1505
+							)
1506
+						),
1507
+						__FILE__,
1508
+						__FUNCTION__,
1509
+						__LINE__
1510
+					);
1511
+					return false;
1512
+				case 'no_payment_required':
1513
+					EE_Error::add_attention(
1514
+						apply_filters(
1515
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
1516
+							esc_html__(
1517
+								'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.',
1518
+								'event_espresso'
1519
+							)
1520
+						),
1521
+						__FILE__,
1522
+						__FUNCTION__,
1523
+						__LINE__
1524
+					);
1525
+					return false;
1526
+				default:
1527
+			}
1528
+		}
1529
+		// verify payment method
1530
+		if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1531
+			// get payment method for selected method of payment
1532
+			$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1533
+		}
1534
+		return $this->checkout->payment_method instanceof EE_Payment_Method;
1535
+	}
1536
+
1537
+
1538
+
1539
+	/********************************************************************************************************/
1540
+	/***************************************  SAVE PAYER DETAILS  ****************************************/
1541
+	/********************************************************************************************************/
1542
+	/**
1543
+	 * save_payer_details_via_ajax
1544
+	 *
1545
+	 * @return void
1546
+	 * @throws EE_Error
1547
+	 * @throws InvalidArgumentException
1548
+	 * @throws ReflectionException
1549
+	 * @throws RuntimeException
1550
+	 * @throws InvalidDataTypeException
1551
+	 * @throws InvalidInterfaceException
1552
+	 */
1553
+	public function save_payer_details_via_ajax()
1554
+	{
1555
+		if (! $this->_verify_payment_method_is_set()) {
1556
+			return;
1557
+		}
1558
+		// generate billing form for selected method of payment if it hasn't been done already
1559
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1560
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1561
+				$this->checkout->payment_method
1562
+			);
1563
+		}
1564
+		// generate primary attendee from payer info if applicable
1565
+		if (! $this->checkout->transaction_has_primary_registrant()) {
1566
+			$attendee = $this->_create_attendee_from_request_data();
1567
+			if ($attendee instanceof EE_Attendee) {
1568
+				foreach ($this->checkout->transaction->registrations() as $registration) {
1569
+					if ($registration->is_primary_registrant()) {
1570
+						$this->checkout->primary_attendee_obj = $attendee;
1571
+						$registration->_add_relation_to($attendee, 'Attendee');
1572
+						$registration->set_attendee_id($attendee->ID());
1573
+						$registration->update_cache_after_object_save('Attendee', $attendee);
1574
+					}
1575
+				}
1576
+			}
1577
+		}
1578
+	}
1579
+
1580
+
1581
+	/**
1582
+	 * create_attendee_from_request_data
1583
+	 * uses info from alternate GET or POST data (such as AJAX) to create a new attendee
1584
+	 *
1585
+	 * @return EE_Attendee
1586
+	 * @throws EE_Error
1587
+	 * @throws InvalidArgumentException
1588
+	 * @throws ReflectionException
1589
+	 * @throws InvalidDataTypeException
1590
+	 * @throws InvalidInterfaceException
1591
+	 */
1592
+	protected function _create_attendee_from_request_data()
1593
+	{
1594
+		// get State ID
1595
+		$STA_ID = $this->request->getRequestParam('state');
1596
+		if (! empty($STA_ID)) {
1597
+			// can we get state object from name ?
1598
+			EE_Registry::instance()->load_model('State');
1599
+			$state  = EEM_State::instance()->get_col([['STA_name' => $STA_ID], 'limit' => 1], 'STA_ID');
1600
+			$STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1601
+		}
1602
+		// get Country ISO
1603
+		$CNT_ISO = $this->request->getRequestParam('country');
1604
+		if (! empty($CNT_ISO)) {
1605
+			// can we get country object from name ?
1606
+			EE_Registry::instance()->load_model('Country');
1607
+			$country = EEM_Country::instance()->get_col(
1608
+				[['CNT_name' => $CNT_ISO], 'limit' => 1],
1609
+				'CNT_ISO'
1610
+			);
1611
+			$CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1612
+		}
1613
+		// grab attendee data
1614
+		$attendee_data = [
1615
+			'ATT_fname'    => $this->request->getRequestParam('first_name'),
1616
+			'ATT_lname'    => $this->request->getRequestParam('last_name'),
1617
+			'ATT_email'    => $this->request->getRequestParam('email'),
1618
+			'ATT_address'  => $this->request->getRequestParam('address'),
1619
+			'ATT_address2' => $this->request->getRequestParam('address2'),
1620
+			'ATT_city'     => $this->request->getRequestParam('city'),
1621
+			'STA_ID'       => $STA_ID,
1622
+			'CNT_ISO'      => $CNT_ISO,
1623
+			'ATT_zip'      => $this->request->getRequestParam('zip'),
1624
+			'ATT_phone'    => $this->request->getRequestParam('phone'),
1625
+		];
1626
+		// validate the email address since it is the most important piece of info
1627
+		if (empty($attendee_data['ATT_email'])) {
1628
+			EE_Error::add_error(
1629
+				esc_html__('An invalid email address was submitted.', 'event_espresso'),
1630
+				__FILE__,
1631
+				__FUNCTION__,
1632
+				__LINE__
1633
+			);
1634
+		}
1635
+		// does this attendee already exist in the db ? we're searching using a combination of first name, last name,
1636
+		// AND email address
1637
+		if (
1638
+			! empty($attendee_data['ATT_fname'])
1639
+			&& ! empty($attendee_data['ATT_lname'])
1640
+			&& ! empty($attendee_data['ATT_email'])
1641
+		) {
1642
+			$existing_attendee = EEM_Attendee::instance()->find_existing_attendee(
1643
+				[
1644
+					'ATT_fname' => $attendee_data['ATT_fname'],
1645
+					'ATT_lname' => $attendee_data['ATT_lname'],
1646
+					'ATT_email' => $attendee_data['ATT_email'],
1647
+				]
1648
+			);
1649
+			if ($existing_attendee instanceof EE_Attendee) {
1650
+				return $existing_attendee;
1651
+			}
1652
+		}
1653
+		// no existing attendee? kk let's create a new one
1654
+		// kinda lame, but we need a first and last name to create an attendee, so use the email address if those
1655
+		// don't exist
1656
+		$attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname'])
1657
+			? $attendee_data['ATT_fname']
1658
+			: $attendee_data['ATT_email'];
1659
+		$attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname'])
1660
+			? $attendee_data['ATT_lname']
1661
+			: $attendee_data['ATT_email'];
1662
+		return EE_Attendee::new_instance($attendee_data);
1663
+	}
1664
+
1665
+
1666
+
1667
+	/********************************************************************************************************/
1668
+	/****************************************  PROCESS REG STEP  *****************************************/
1669
+	/********************************************************************************************************/
1670
+	/**
1671
+	 * process_reg_step
1672
+	 *
1673
+	 * @return bool
1674
+	 * @throws EE_Error
1675
+	 * @throws InvalidArgumentException
1676
+	 * @throws ReflectionException
1677
+	 * @throws EntityNotFoundException
1678
+	 * @throws InvalidDataTypeException
1679
+	 * @throws InvalidInterfaceException
1680
+	 * @throws InvalidStatusException
1681
+	 */
1682
+	public function process_reg_step()
1683
+	{
1684
+		// how have they chosen to pay?
1685
+		$this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free()
1686
+			? 'no_payment_required'
1687
+			: $this->_get_selected_method_of_payment(true);
1688
+		// choose your own adventure based on method_of_payment
1689
+		switch ($this->checkout->selected_method_of_payment) {
1690
+			case 'events_sold_out':
1691
+				$this->checkout->redirect     = true;
1692
+				$this->checkout->redirect_url = $this->checkout->cancel_page_url;
1693
+				$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1694
+				// mark this reg step as completed
1695
+				$this->set_completed();
1696
+				return false;
1697
+
1698
+			case 'payments_closed':
1699
+				if (
1700
+					apply_filters(
1701
+						'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success',
1702
+						false
1703
+					)
1704
+				) {
1705
+					EE_Error::add_success(
1706
+						esc_html__('no payment required at this time.', 'event_espresso'),
1707
+						__FILE__,
1708
+						__FUNCTION__,
1709
+						__LINE__
1710
+					);
1711
+				}
1712
+				// mark this reg step as completed
1713
+				$this->set_completed();
1714
+				return true;
1715
+
1716
+			case 'no_payment_required':
1717
+				if (
1718
+					apply_filters(
1719
+						'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success',
1720
+						false
1721
+					)
1722
+				) {
1723
+					EE_Error::add_success(
1724
+						esc_html__('no payment required.', 'event_espresso'),
1725
+						__FILE__,
1726
+						__FUNCTION__,
1727
+						__LINE__
1728
+					);
1729
+				}
1730
+				// mark this reg step as completed
1731
+				$this->set_completed();
1732
+				return true;
1733
+
1734
+			default:
1735
+				$registrations         = EE_Registry::instance()->SSN->checkout()->transaction->registrations(
1736
+					EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
1737
+				);
1738
+				$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
1739
+					$registrations,
1740
+					EE_Registry::instance()->SSN->checkout()->revisit
1741
+				);
1742
+				// calculate difference between the two arrays
1743
+				$registrations = array_diff($registrations, $ejected_registrations);
1744
+				if (empty($registrations)) {
1745
+					$this->_redirect_because_event_sold_out();
1746
+					return false;
1747
+				}
1748
+				$payment_successful = $this->_process_payment();
1749
+				if ($payment_successful) {
1750
+					$this->checkout->continue_reg = true;
1751
+					$this->_maybe_set_completed($this->checkout->payment_method);
1752
+				} else {
1753
+					$this->checkout->continue_reg = false;
1754
+				}
1755
+				return $payment_successful;
1756
+		}
1757
+	}
1758
+
1759
+
1760
+	/**
1761
+	 * _redirect_because_event_sold_out
1762
+	 *
1763
+	 * @return void
1764
+	 */
1765
+	protected function _redirect_because_event_sold_out()
1766
+	{
1767
+		$this->checkout->continue_reg = false;
1768
+		// set redirect URL
1769
+		$this->checkout->redirect_url = add_query_arg(
1770
+			['e_reg_url_link' => $this->checkout->reg_url_link],
1771
+			$this->checkout->current_step->reg_step_url()
1772
+		);
1773
+		$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1774
+	}
1775
+
1776
+
1777
+	/**
1778
+	 * _maybe_set_completed
1779
+	 *
1780
+	 * @param EE_Payment_Method $payment_method
1781
+	 * @return void
1782
+	 * @throws EE_Error
1783
+	 */
1784
+	protected function _maybe_set_completed(EE_Payment_Method $payment_method)
1785
+	{
1786
+		switch ($payment_method->type_obj()->payment_occurs()) {
1787
+			case EE_PMT_Base::offsite:
1788
+				break;
1789
+			case EE_PMT_Base::onsite:
1790
+			case EE_PMT_Base::offline:
1791
+				// mark this reg step as completed
1792
+				$this->set_completed();
1793
+				break;
1794
+		}
1795
+	}
1796
+
1797
+
1798
+	/**
1799
+	 *    update_reg_step
1800
+	 *    this is the final step after a user  revisits the site to retry a payment
1801
+	 *
1802
+	 * @return bool
1803
+	 * @throws EE_Error
1804
+	 * @throws InvalidArgumentException
1805
+	 * @throws ReflectionException
1806
+	 * @throws EntityNotFoundException
1807
+	 * @throws InvalidDataTypeException
1808
+	 * @throws InvalidInterfaceException
1809
+	 * @throws InvalidStatusException
1810
+	 */
1811
+	public function update_reg_step()
1812
+	{
1813
+		$success = true;
1814
+		// if payment required
1815
+		if ($this->checkout->transaction->total() > 0) {
1816
+			do_action(
1817
+				'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway',
1818
+				$this->checkout->transaction
1819
+			);
1820
+			// attempt payment via payment method
1821
+			$success = $this->process_reg_step();
1822
+		}
1823
+		if ($success && ! $this->checkout->redirect) {
1824
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
1825
+				$this->checkout->transaction->ID()
1826
+			);
1827
+			// set return URL
1828
+			$this->checkout->redirect_url = add_query_arg(
1829
+				['e_reg_url_link' => $this->checkout->reg_url_link],
1830
+				$this->checkout->thank_you_page_url
1831
+			);
1832
+		}
1833
+		return $success;
1834
+	}
1835
+
1836
+
1837
+	/**
1838
+	 *    _process_payment
1839
+	 *
1840
+	 * @return bool
1841
+	 * @throws EE_Error
1842
+	 * @throws InvalidArgumentException
1843
+	 * @throws ReflectionException
1844
+	 * @throws RuntimeException
1845
+	 * @throws InvalidDataTypeException
1846
+	 * @throws InvalidInterfaceException
1847
+	 */
1848
+	private function _process_payment()
1849
+	{
1850
+		// basically confirm that the event hasn't sold out since they hit the page
1851
+		if (! $this->_last_second_ticket_verifications()) {
1852
+			return false;
1853
+		}
1854
+		// ya gotta make a choice man
1855
+		if (empty($this->checkout->selected_method_of_payment)) {
1856
+			$this->checkout->json_response->set_plz_select_method_of_payment(
1857
+				esc_html__('Please select a method of payment before proceeding.', 'event_espresso')
1858
+			);
1859
+			return false;
1860
+		}
1861
+		// get EE_Payment_Method object
1862
+		if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1863
+			return false;
1864
+		}
1865
+		// setup billing form
1866
+		if ($this->checkout->payment_method->is_on_site()) {
1867
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1868
+				$this->checkout->payment_method
1869
+			);
1870
+			// bad billing form ?
1871
+			if (! $this->_billing_form_is_valid()) {
1872
+				return false;
1873
+			}
1874
+		}
1875
+		// ensure primary registrant has been fully processed
1876
+		if (! $this->_setup_primary_registrant_prior_to_payment()) {
1877
+			return false;
1878
+		}
1879
+		// if session is close to expiring (under 10 minutes by default)
1880
+		if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1881
+			// add some time to session expiration so that payment can be completed
1882
+			EE_Registry::instance()->SSN->extend_expiration();
1883
+		}
1884
+		/** @type EE_Transaction_Processor $transaction_processor */
1885
+		// $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1886
+		// in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations
1887
+		// for events with a default reg status of Approved
1888
+		// $transaction_processor->toggle_registration_statuses_for_default_approved_events(
1889
+		//      $this->checkout->transaction, $this->checkout->reg_cache_where_params
1890
+		// );
1891
+		// attempt payment
1892
+		$payment = $this->_attempt_payment($this->checkout->payment_method);
1893
+		// process results
1894
+		$payment = $this->_validate_payment($payment);
1895
+		$payment = $this->_post_payment_processing($payment);
1896
+		// verify payment
1897
+		if ($payment instanceof EE_Payment) {
1898
+			// store that for later
1899
+			$this->checkout->payment = $payment;
1900
+			// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
1901
+			$this->checkout->transaction->toggle_failed_transaction_status();
1902
+			$payment_status = $payment->status();
1903
+			return $payment_status === EEM_Payment::status_id_approved
1904
+				   || $payment_status === EEM_Payment::status_id_pending;
1905
+		}
1906
+		if ($payment === true) {
1907
+			// please note that offline payment methods will NOT make a payment,
1908
+			// but instead just mark themselves as the PMD_ID on the transaction, and return true
1909
+			$this->checkout->payment = $payment;
1910
+			return true;
1911
+		}
1912
+		// where's my money?
1913
+		return false;
1914
+	}
1915
+
1916
+
1917
+	/**
1918
+	 * _last_second_ticket_verifications
1919
+	 *
1920
+	 * @return bool
1921
+	 * @throws EE_Error
1922
+	 * @throws ReflectionException
1923
+	 */
1924
+	protected function _last_second_ticket_verifications()
1925
+	{
1926
+		// don't bother re-validating if not a return visit
1927
+		if (! $this->checkout->revisit) {
1928
+			return true;
1929
+		}
1930
+		$registrations = $this->checkout->transaction->registrations();
1931
+		if (empty($registrations)) {
1932
+			return false;
1933
+		}
1934
+		foreach ($registrations as $registration) {
1935
+			if ($registration instanceof EE_Registration && ! $registration->is_approved()) {
1936
+				$event = $registration->event_obj();
1937
+				if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1938
+					EE_Error::add_error(
1939
+						apply_filters(
1940
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1941
+							sprintf(
1942
+								esc_html__(
1943
+									'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
1944
+									'event_espresso'
1945
+								),
1946
+								$event->name()
1947
+							)
1948
+						),
1949
+						__FILE__,
1950
+						__FUNCTION__,
1951
+						__LINE__
1952
+					);
1953
+					return false;
1954
+				}
1955
+			}
1956
+		}
1957
+		return true;
1958
+	}
1959
+
1960
+
1961
+	/**
1962
+	 * redirect_form
1963
+	 *
1964
+	 * @return bool
1965
+	 * @throws EE_Error
1966
+	 * @throws InvalidArgumentException
1967
+	 * @throws ReflectionException
1968
+	 * @throws InvalidDataTypeException
1969
+	 * @throws InvalidInterfaceException
1970
+	 */
1971
+	public function redirect_form()
1972
+	{
1973
+		$payment_method_billing_info = $this->_payment_method_billing_info(
1974
+			$this->_get_payment_method_for_selected_method_of_payment()
1975
+		);
1976
+		$html                        = $payment_method_billing_info->get_html();
1977
+		$html                        .= $this->checkout->redirect_form;
1978
+		/** @var ResponseInterface $response */
1979
+		$response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
1980
+		$response->addOutput($html);
1981
+		return true;
1982
+	}
1983
+
1984
+
1985
+	/**
1986
+	 * _billing_form_is_valid
1987
+	 *
1988
+	 * @return bool
1989
+	 * @throws EE_Error
1990
+	 */
1991
+	private function _billing_form_is_valid()
1992
+	{
1993
+		if (! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1994
+			return true;
1995
+		}
1996
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1997
+			if ($this->checkout->billing_form->was_submitted()) {
1998
+				$this->checkout->billing_form->receive_form_submission();
1999
+				if ($this->checkout->billing_form->is_valid()) {
2000
+					return true;
2001
+				}
2002
+				$validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
2003
+				$error_strings     = [];
2004
+				foreach ($validation_errors as $validation_error) {
2005
+					if ($validation_error instanceof EE_Validation_Error) {
2006
+						$form_section = $validation_error->get_form_section();
2007
+						if ($form_section instanceof EE_Form_Input_Base) {
2008
+							$label = $form_section->html_label_text();
2009
+						} elseif ($form_section instanceof EE_Form_Section_Base) {
2010
+							$label = $form_section->name();
2011
+						} else {
2012
+							$label = esc_html__('Validation Error', 'event_espresso');
2013
+						}
2014
+						$error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
2015
+					}
2016
+				}
2017
+				EE_Error::add_error(
2018
+					sprintf(
2019
+						esc_html__(
2020
+							'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s',
2021
+							'event_espresso'
2022
+						),
2023
+						'<br/>',
2024
+						implode('<br/>', $error_strings)
2025
+					),
2026
+					__FILE__,
2027
+					__FUNCTION__,
2028
+					__LINE__
2029
+				);
2030
+			} else {
2031
+				EE_Error::add_error(
2032
+					esc_html__(
2033
+						'The billing form was not submitted or something prevented it\'s submission.',
2034
+						'event_espresso'
2035
+					),
2036
+					__FILE__,
2037
+					__FUNCTION__,
2038
+					__LINE__
2039
+				);
2040
+			}
2041
+		} else {
2042
+			EE_Error::add_error(
2043
+				esc_html__(
2044
+					'The submitted billing form is invalid possibly due to a technical reason.',
2045
+					'event_espresso'
2046
+				),
2047
+				__FILE__,
2048
+				__FUNCTION__,
2049
+				__LINE__
2050
+			);
2051
+		}
2052
+		return false;
2053
+	}
2054
+
2055
+
2056
+	/**
2057
+	 * _setup_primary_registrant_prior_to_payment
2058
+	 * ensures that the primary registrant has a valid attendee object created with the critical details populated
2059
+	 * (first & last name & email) and that both the transaction object and primary registration object have been saved
2060
+	 * plz note that any other registrations will NOT be saved at this point (because they may not have any details
2061
+	 * yet)
2062
+	 *
2063
+	 * @return bool
2064
+	 * @throws EE_Error
2065
+	 * @throws InvalidArgumentException
2066
+	 * @throws ReflectionException
2067
+	 * @throws RuntimeException
2068
+	 * @throws InvalidDataTypeException
2069
+	 * @throws InvalidInterfaceException
2070
+	 */
2071
+	private function _setup_primary_registrant_prior_to_payment()
2072
+	{
2073
+		// check if transaction has a primary registrant and that it has a related Attendee object
2074
+		// if not, then we need to at least gather some primary registrant data before attempting payment
2075
+		if (
2076
+			$this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
2077
+			&& ! $this->checkout->transaction_has_primary_registrant()
2078
+			&& ! $this->_capture_primary_registration_data_from_billing_form()
2079
+		) {
2080
+			return false;
2081
+		}
2082
+		// because saving an object clears it's cache, we need to do the chevy shuffle
2083
+		// grab the primary_registration object
2084
+		$primary_registration = $this->checkout->transaction->primary_registration();
2085
+		// at this point we'll consider a TXN to not have been failed
2086
+		$this->checkout->transaction->toggle_failed_transaction_status();
2087
+		// save the TXN ( which clears cached copy of primary_registration)
2088
+		$this->checkout->transaction->save();
2089
+		// grab TXN ID and save it to the primary_registration
2090
+		$primary_registration->set_transaction_id($this->checkout->transaction->ID());
2091
+		// save what we have so far
2092
+		$primary_registration->save();
2093
+		return true;
2094
+	}
2095
+
2096
+
2097
+	/**
2098
+	 * _capture_primary_registration_data_from_billing_form
2099
+	 *
2100
+	 * @return bool
2101
+	 * @throws EE_Error
2102
+	 * @throws InvalidArgumentException
2103
+	 * @throws ReflectionException
2104
+	 * @throws InvalidDataTypeException
2105
+	 * @throws InvalidInterfaceException
2106
+	 */
2107
+	private function _capture_primary_registration_data_from_billing_form()
2108
+	{
2109
+		// convert billing form data into an attendee
2110
+		$this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
2111
+		if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2112
+			EE_Error::add_error(
2113
+				sprintf(
2114
+					esc_html__(
2115
+						'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.',
2116
+						'event_espresso'
2117
+					),
2118
+					'<br/>',
2119
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2120
+				),
2121
+				__FILE__,
2122
+				__FUNCTION__,
2123
+				__LINE__
2124
+			);
2125
+			return false;
2126
+		}
2127
+		$primary_registration = $this->checkout->transaction->primary_registration();
2128
+		if (! $primary_registration instanceof EE_Registration) {
2129
+			EE_Error::add_error(
2130
+				sprintf(
2131
+					esc_html__(
2132
+						'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2133
+						'event_espresso'
2134
+					),
2135
+					'<br/>',
2136
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2137
+				),
2138
+				__FILE__,
2139
+				__FUNCTION__,
2140
+				__LINE__
2141
+			);
2142
+			return false;
2143
+		}
2144
+		if (
2145
+			! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee')
2146
+			  instanceof
2147
+			  EE_Attendee
2148
+		) {
2149
+			EE_Error::add_error(
2150
+				sprintf(
2151
+					esc_html__(
2152
+						'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.',
2153
+						'event_espresso'
2154
+					),
2155
+					'<br/>',
2156
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2157
+				),
2158
+				__FILE__,
2159
+				__FUNCTION__,
2160
+				__LINE__
2161
+			);
2162
+			return false;
2163
+		}
2164
+		/** @type EE_Registration_Processor $registration_processor */
2165
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
2166
+		// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
2167
+		$registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
2168
+		return true;
2169
+	}
2170
+
2171
+
2172
+	/**
2173
+	 * _get_payment_method_for_selected_method_of_payment
2174
+	 * retrieves a valid payment method
2175
+	 *
2176
+	 * @return EE_Payment_Method
2177
+	 * @throws EE_Error
2178
+	 * @throws InvalidArgumentException
2179
+	 * @throws ReflectionException
2180
+	 * @throws InvalidDataTypeException
2181
+	 * @throws InvalidInterfaceException
2182
+	 */
2183
+	private function _get_payment_method_for_selected_method_of_payment()
2184
+	{
2185
+		if ($this->checkout->selected_method_of_payment === 'events_sold_out') {
2186
+			$this->_redirect_because_event_sold_out();
2187
+			return null;
2188
+		}
2189
+		// get EE_Payment_Method object
2190
+		if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) {
2191
+			$payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
2192
+		} else {
2193
+			// load EEM_Payment_Method
2194
+			EE_Registry::instance()->load_model('Payment_Method');
2195
+			$EEM_Payment_Method = EEM_Payment_Method::instance();
2196
+			$payment_method     = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2197
+		}
2198
+		// verify $payment_method
2199
+		if (! $payment_method instanceof EE_Payment_Method) {
2200
+			// not a payment
2201
+			EE_Error::add_error(
2202
+				sprintf(
2203
+					esc_html__(
2204
+						'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2205
+						'event_espresso'
2206
+					),
2207
+					'<br/>',
2208
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2209
+				),
2210
+				__FILE__,
2211
+				__FUNCTION__,
2212
+				__LINE__
2213
+			);
2214
+			return null;
2215
+		}
2216
+		// and verify it has a valid Payment_Method Type object
2217
+		if (! $payment_method->type_obj() instanceof EE_PMT_Base) {
2218
+			// not a payment
2219
+			EE_Error::add_error(
2220
+				sprintf(
2221
+					esc_html__(
2222
+						'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2223
+						'event_espresso'
2224
+					),
2225
+					'<br/>',
2226
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2227
+				),
2228
+				__FILE__,
2229
+				__FUNCTION__,
2230
+				__LINE__
2231
+			);
2232
+			return null;
2233
+		}
2234
+		return $payment_method;
2235
+	}
2236
+
2237
+
2238
+	/**
2239
+	 *    _attempt_payment
2240
+	 *
2241
+	 * @access    private
2242
+	 * @type    EE_Payment_Method $payment_method
2243
+	 * @return mixed EE_Payment | boolean
2244
+	 * @throws EE_Error
2245
+	 * @throws InvalidArgumentException
2246
+	 * @throws ReflectionException
2247
+	 * @throws InvalidDataTypeException
2248
+	 * @throws InvalidInterfaceException
2249
+	 */
2250
+	private function _attempt_payment(EE_Payment_Method $payment_method)
2251
+	{
2252
+		$payment = null;
2253
+		$this->checkout->transaction->save();
2254
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2255
+		if (! $payment_processor instanceof EE_Payment_Processor) {
2256
+			return false;
2257
+		}
2258
+		try {
2259
+			$payment_processor->set_revisit($this->checkout->revisit);
2260
+			// generate payment object
2261
+			$payment = $payment_processor->process_payment(
2262
+				$payment_method,
2263
+				$this->checkout->transaction,
2264
+				$this->checkout->amount_owing,
2265
+				$this->checkout->billing_form,
2266
+				$this->_get_return_url($payment_method),
2267
+				'CART',
2268
+				$this->checkout->admin_request,
2269
+				true,
2270
+				$this->reg_step_url()
2271
+			);
2272
+		} catch (Exception $e) {
2273
+			$this->_handle_payment_processor_exception($e);
2274
+		}
2275
+		return $payment;
2276
+	}
2277
+
2278
+
2279
+	/**
2280
+	 * _handle_payment_processor_exception
2281
+	 *
2282
+	 * @param Exception $e
2283
+	 * @return void
2284
+	 * @throws EE_Error
2285
+	 * @throws InvalidArgumentException
2286
+	 * @throws InvalidDataTypeException
2287
+	 * @throws InvalidInterfaceException
2288
+	 */
2289
+	protected function _handle_payment_processor_exception(Exception $e)
2290
+	{
2291
+		EE_Error::add_error(
2292
+			sprintf(
2293
+				esc_html__(
2294
+					'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s',
2295
+					'event_espresso'
2296
+				),
2297
+				'<br/>',
2298
+				EE_Registry::instance()->CFG->organization->get_pretty('email'),
2299
+				$e->getMessage(),
2300
+				$e->getFile(),
2301
+				$e->getLine()
2302
+			),
2303
+			__FILE__,
2304
+			__FUNCTION__,
2305
+			__LINE__
2306
+		);
2307
+	}
2308
+
2309
+
2310
+	/**
2311
+	 * _get_return_url
2312
+	 *
2313
+	 * @param EE_Payment_Method $payment_method
2314
+	 * @return string
2315
+	 * @throws EE_Error
2316
+	 * @throws ReflectionException
2317
+	 */
2318
+	protected function _get_return_url(EE_Payment_Method $payment_method)
2319
+	{
2320
+		$return_url = '';
2321
+		switch ($payment_method->type_obj()->payment_occurs()) {
2322
+			case EE_PMT_Base::offsite:
2323
+				$return_url = add_query_arg(
2324
+					[
2325
+						'action'                     => 'process_gateway_response',
2326
+						'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2327
+						'spco_txn'                   => $this->checkout->transaction->ID(),
2328
+					],
2329
+					$this->reg_step_url()
2330
+				);
2331
+				break;
2332
+			case EE_PMT_Base::onsite:
2333
+			case EE_PMT_Base::offline:
2334
+				$return_url = $this->checkout->next_step->reg_step_url();
2335
+				break;
2336
+		}
2337
+		return $return_url;
2338
+	}
2339
+
2340
+
2341
+	/**
2342
+	 * _validate_payment
2343
+	 *
2344
+	 * @param EE_Payment $payment
2345
+	 * @return EE_Payment|FALSE
2346
+	 * @throws EE_Error
2347
+	 * @throws InvalidArgumentException
2348
+	 * @throws InvalidDataTypeException
2349
+	 * @throws InvalidInterfaceException
2350
+	 */
2351
+	private function _validate_payment($payment = null)
2352
+	{
2353
+		if ($this->checkout->payment_method->is_off_line()) {
2354
+			return true;
2355
+		}
2356
+		// verify payment object
2357
+		if (! $payment instanceof EE_Payment) {
2358
+			// not a payment
2359
+			EE_Error::add_error(
2360
+				sprintf(
2361
+					esc_html__(
2362
+						'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.',
2363
+						'event_espresso'
2364
+					),
2365
+					'<br/>',
2366
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2367
+				),
2368
+				__FILE__,
2369
+				__FUNCTION__,
2370
+				__LINE__
2371
+			);
2372
+			return false;
2373
+		}
2374
+		return $payment;
2375
+	}
2376
+
2377
+
2378
+	/**
2379
+	 * _post_payment_processing
2380
+	 *
2381
+	 * @param EE_Payment|bool $payment
2382
+	 * @return bool
2383
+	 * @throws EE_Error
2384
+	 * @throws InvalidArgumentException
2385
+	 * @throws InvalidDataTypeException
2386
+	 * @throws InvalidInterfaceException
2387
+	 * @throws ReflectionException
2388
+	 */
2389
+	private function _post_payment_processing($payment = null)
2390
+	{
2391
+		// Off-Line payment?
2392
+		if ($payment === true) {
2393
+			// $this->_setup_redirect_for_next_step();
2394
+			return true;
2395
+			// On-Site payment?
2396
+		} elseif ($this->checkout->payment_method->is_on_site()) {
2397
+			if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2398
+				// $this->_setup_redirect_for_next_step();
2399
+				$this->checkout->continue_reg = false;
2400
+			}
2401
+			// Off-Site payment?
2402
+		} elseif ($this->checkout->payment_method->is_off_site()) {
2403
+			// if a payment object was made and it specifies a redirect url, then we'll setup that redirect info
2404
+			if ($payment instanceof EE_Payment && $payment->redirect_url()) {
2405
+				do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
2406
+				$this->checkout->redirect      = true;
2407
+				$this->checkout->redirect_form = $payment->redirect_form();
2408
+				$this->checkout->redirect_url  = $this->reg_step_url('redirect_form');
2409
+				// set JSON response
2410
+				$this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
2411
+				// and lastly, let's bump the payment status to pending
2412
+				$payment->set_status(EEM_Payment::status_id_pending);
2413
+				$payment->save();
2414
+			} else {
2415
+				// we couldn't redirect the user. Let's tell them why.
2416
+				$error_message = sprintf(
2417
+					esc_html__(
2418
+						'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.',
2419
+						'event_espresso'
2420
+					),
2421
+					'<br/>',
2422
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2423
+				);
2424
+				if ($payment instanceof EE_Payment && $payment->gateway_response()) {
2425
+					$error_message = $error_message . '<br/>' . $payment->gateway_response();
2426
+				}
2427
+				$this->checkout->continue_reg = false;
2428
+				EE_Error::add_error(
2429
+					$error_message,
2430
+					__FILE__,
2431
+					__FUNCTION__,
2432
+					__LINE__
2433
+				);
2434
+			}
2435
+		} else {
2436
+			// ummm ya... not Off-Line, not On-Site, not off-Site ????
2437
+			$this->checkout->continue_reg = false;
2438
+			return false;
2439
+		}
2440
+		return $payment;
2441
+	}
2442
+
2443
+
2444
+	/**
2445
+	 *    _process_payment_status
2446
+	 *
2447
+	 * @type    EE_Payment $payment
2448
+	 * @param string       $payment_occurs
2449
+	 * @return bool
2450
+	 * @throws EE_Error
2451
+	 * @throws InvalidArgumentException
2452
+	 * @throws InvalidDataTypeException
2453
+	 * @throws InvalidInterfaceException
2454
+	 */
2455
+	private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline)
2456
+	{
2457
+		// off-line payment? carry on
2458
+		if ($payment_occurs === EE_PMT_Base::offline) {
2459
+			return true;
2460
+		}
2461
+		// verify payment validity
2462
+		if ($payment instanceof EE_Payment) {
2463
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
2464
+			$msg = $payment->gateway_response();
2465
+			// check results
2466
+			switch ($payment->status()) {
2467
+				// good payment
2468
+				case EEM_Payment::status_id_approved:
2469
+					EE_Error::add_success(
2470
+						esc_html__('Your payment was processed successfully.', 'event_espresso'),
2471
+						__FILE__,
2472
+						__FUNCTION__,
2473
+						__LINE__
2474
+					);
2475
+					return true;
2476
+				// slow payment
2477
+				case EEM_Payment::status_id_pending:
2478
+					if (empty($msg)) {
2479
+						$msg = esc_html__(
2480
+							'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.',
2481
+							'event_espresso'
2482
+						);
2483
+					}
2484
+					EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
2485
+					return true;
2486
+				// don't wanna payment
2487
+				case EEM_Payment::status_id_cancelled:
2488
+					if (empty($msg)) {
2489
+						$msg = _n(
2490
+							'Payment cancelled. Please try again.',
2491
+							'Payment cancelled. Please try again or select another method of payment.',
2492
+							count($this->checkout->available_payment_methods),
2493
+							'event_espresso'
2494
+						);
2495
+					}
2496
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2497
+					return false;
2498
+				// not enough payment
2499
+				case EEM_Payment::status_id_declined:
2500
+					if (empty($msg)) {
2501
+						$msg = _n(
2502
+							'We\'re sorry but your payment was declined. Please try again.',
2503
+							'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
2504
+							count($this->checkout->available_payment_methods),
2505
+							'event_espresso'
2506
+						);
2507
+					}
2508
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2509
+					return false;
2510
+				// bad payment
2511
+				case EEM_Payment::status_id_failed:
2512
+					if (! empty($msg)) {
2513
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2514
+						return false;
2515
+					}
2516
+					// default to error below
2517
+					break;
2518
+			}
2519
+		}
2520
+		// off-site payment gateway responses are too unreliable, so let's just assume that
2521
+		// the payment processing is just running slower than the registrant's request
2522
+		if ($payment_occurs === EE_PMT_Base::offsite) {
2523
+			return true;
2524
+		}
2525
+		EE_Error::add_error(
2526
+			sprintf(
2527
+				esc_html__(
2528
+					'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.',
2529
+					'event_espresso'
2530
+				),
2531
+				'<br/>',
2532
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
2533
+			),
2534
+			__FILE__,
2535
+			__FUNCTION__,
2536
+			__LINE__
2537
+		);
2538
+		return false;
2539
+	}
2540
+
2541
+
2542
+
2543
+
2544
+
2545
+
2546
+	/********************************************************************************************************/
2547
+	/**********************************  PROCESS GATEWAY RESPONSE  **********************************/
2548
+	/********************************************************************************************************/
2549
+	/**
2550
+	 * process_gateway_response
2551
+	 * this is the return point for Off-Site Payment Methods
2552
+	 * It will attempt to "handle the IPN" if it appears that this has not already occurred,
2553
+	 * otherwise, it will load up the last payment made for the TXN.
2554
+	 * If the payment retrieved looks good, it will then either:
2555
+	 *    complete the current step and allow advancement to the next reg step
2556
+	 *        or present the payment options again
2557
+	 *
2558
+	 * @return bool
2559
+	 * @throws EE_Error
2560
+	 * @throws InvalidArgumentException
2561
+	 * @throws ReflectionException
2562
+	 * @throws InvalidDataTypeException
2563
+	 * @throws InvalidInterfaceException
2564
+	 */
2565
+	public function process_gateway_response()
2566
+	{
2567
+		// how have they chosen to pay?
2568
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2569
+		// get EE_Payment_Method object
2570
+		if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2571
+			$this->checkout->continue_reg = false;
2572
+			return false;
2573
+		}
2574
+		if (! $this->checkout->payment_method->is_off_site()) {
2575
+			return false;
2576
+		}
2577
+		$this->_validate_offsite_return();
2578
+		// verify TXN
2579
+		if ($this->checkout->transaction instanceof EE_Transaction) {
2580
+			$gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2581
+			if (! $gateway instanceof EE_Offsite_Gateway) {
2582
+				$this->checkout->continue_reg = false;
2583
+				return false;
2584
+			}
2585
+			$payment = $this->_process_off_site_payment($gateway);
2586
+			$payment = $this->_process_cancelled_payments($payment);
2587
+			$payment = $this->_validate_payment($payment);
2588
+			// if payment was not declined by the payment gateway or cancelled by the registrant
2589
+			if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
2590
+				// $this->_setup_redirect_for_next_step();
2591
+				// store that for later
2592
+				$this->checkout->payment = $payment;
2593
+				// mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2594
+				// because we will complete this step during the IPN processing then
2595
+				if (! $this->handle_IPN_in_this_request()) {
2596
+					$this->set_completed();
2597
+				}
2598
+				return true;
2599
+			}
2600
+		}
2601
+		// DEBUG LOG
2602
+		// $this->checkout->log(
2603
+		//     __CLASS__,
2604
+		//     __FUNCTION__,
2605
+		//     __LINE__,
2606
+		//     array('payment' => $payment)
2607
+		// );
2608
+		$this->checkout->continue_reg = false;
2609
+		return false;
2610
+	}
2611
+
2612
+
2613
+	/**
2614
+	 * _validate_return
2615
+	 *
2616
+	 * @return void
2617
+	 * @throws EE_Error
2618
+	 * @throws InvalidArgumentException
2619
+	 * @throws InvalidDataTypeException
2620
+	 * @throws InvalidInterfaceException
2621
+	 * @throws ReflectionException
2622
+	 */
2623
+	private function _validate_offsite_return()
2624
+	{
2625
+		$TXN_ID = $this->request->getRequestParam('spco_txn', 0, 'int');
2626
+		if ($TXN_ID !== $this->checkout->transaction->ID()) {
2627
+			// Houston... we might have a problem
2628
+			$invalid_TXN = false;
2629
+			// first gather some info
2630
+			$valid_TXN          = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2631
+			$primary_registrant = $valid_TXN instanceof EE_Transaction
2632
+				? $valid_TXN->primary_registration()
2633
+				: null;
2634
+			// let's start by retrieving the cart for this TXN
2635
+			$cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction);
2636
+			if ($cart instanceof EE_Cart) {
2637
+				// verify that the current cart has tickets
2638
+				$tickets = $cart->get_tickets();
2639
+				if (empty($tickets)) {
2640
+					$invalid_TXN = true;
2641
+				}
2642
+			} else {
2643
+				$invalid_TXN = true;
2644
+			}
2645
+			$valid_TXN_SID = $primary_registrant instanceof EE_Registration
2646
+				? $primary_registrant->session_ID()
2647
+				: null;
2648
+			// validate current Session ID and compare against valid TXN session ID
2649
+			if (
2650
+				$invalid_TXN // if this is already true, then skip other checks
2651
+				|| EE_Session::instance()->id() === null
2652
+				|| (
2653
+					// WARNING !!!
2654
+					// this could be PayPal sending back duplicate requests (ya they do that)
2655
+					// or it **could** mean someone is simply registering AGAIN after having just done so
2656
+					// so now we need to determine if this current TXN looks valid or not
2657
+					// and whether this reg step has even been started ?
2658
+					EE_Session::instance()->id() === $valid_TXN_SID
2659
+					// really? you're half way through this reg step, but you never started it ?
2660
+					&& $this->checkout->transaction->reg_step_completed($this->slug()) === false
2661
+				)
2662
+			) {
2663
+				$invalid_TXN = true;
2664
+			}
2665
+			if ($invalid_TXN) {
2666
+				// is the valid TXN completed ?
2667
+				if ($valid_TXN instanceof EE_Transaction) {
2668
+					// has this step even been started ?
2669
+					$reg_step_completed = $valid_TXN->reg_step_completed($this->slug());
2670
+					if ($reg_step_completed !== false && $reg_step_completed !== true) {
2671
+						// so it **looks** like this is a double request from PayPal
2672
+						// so let's try to pick up where we left off
2673
+						$this->checkout->transaction = $valid_TXN;
2674
+						$this->checkout->refresh_all_entities(true);
2675
+						return;
2676
+					}
2677
+				}
2678
+				// you appear to be lost?
2679
+				$this->_redirect_wayward_request($primary_registrant);
2680
+			}
2681
+		}
2682
+	}
2683
+
2684
+
2685
+	/**
2686
+	 * _redirect_wayward_request
2687
+	 *
2688
+	 * @param EE_Registration|null $primary_registrant
2689
+	 * @return void
2690
+	 * @throws EE_Error
2691
+	 * @throws InvalidArgumentException
2692
+	 * @throws InvalidDataTypeException
2693
+	 * @throws InvalidInterfaceException
2694
+	 * @throws ReflectionException
2695
+	 */
2696
+	private function _redirect_wayward_request(EE_Registration $primary_registrant)
2697
+	{
2698
+		if (! $primary_registrant instanceof EE_Registration) {
2699
+			// try redirecting based on the current TXN
2700
+			$primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2701
+				? $this->checkout->transaction->primary_registration()
2702
+				: null;
2703
+		}
2704
+		if (! $primary_registrant instanceof EE_Registration) {
2705
+			EE_Error::add_error(
2706
+				sprintf(
2707
+					esc_html__(
2708
+						'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.',
2709
+						'event_espresso'
2710
+					),
2711
+					'<br/>',
2712
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2713
+				),
2714
+				__FILE__,
2715
+				__FUNCTION__,
2716
+				__LINE__
2717
+			);
2718
+			return;
2719
+		}
2720
+		// make sure transaction is not locked
2721
+		$this->checkout->transaction->unlock();
2722
+		wp_safe_redirect(
2723
+			add_query_arg(
2724
+				[
2725
+					'e_reg_url_link' => $primary_registrant->reg_url_link(),
2726
+				],
2727
+				$this->checkout->thank_you_page_url
2728
+			)
2729
+		);
2730
+		exit();
2731
+	}
2732
+
2733
+
2734
+	/**
2735
+	 * _process_off_site_payment
2736
+	 *
2737
+	 * @param EE_Offsite_Gateway $gateway
2738
+	 * @return EE_Payment
2739
+	 * @throws EE_Error
2740
+	 * @throws InvalidArgumentException
2741
+	 * @throws InvalidDataTypeException
2742
+	 * @throws InvalidInterfaceException
2743
+	 * @throws ReflectionException
2744
+	 */
2745
+	private function _process_off_site_payment(EE_Offsite_Gateway $gateway)
2746
+	{
2747
+		try {
2748
+			$request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
2749
+			$request_data = $request->requestParams();
2750
+			// if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
2751
+			$this->set_handle_IPN_in_this_request(
2752
+				$gateway->handle_IPN_in_this_request($request_data, false)
2753
+			);
2754
+			if ($this->handle_IPN_in_this_request()) {
2755
+				// get payment details and process results
2756
+				/** @type EE_Payment_Processor $payment_processor */
2757
+				$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2758
+				$payment           = $payment_processor->process_ipn(
2759
+					$request_data,
2760
+					$this->checkout->transaction,
2761
+					$this->checkout->payment_method,
2762
+					true,
2763
+					false
2764
+				);
2765
+				// $payment_source = 'process_ipn';
2766
+			} else {
2767
+				$payment = $this->checkout->transaction->last_payment();
2768
+				// $payment_source = 'last_payment';
2769
+			}
2770
+		} catch (Exception $e) {
2771
+			// let's just eat the exception and try to move on using any previously set payment info
2772
+			$payment = $this->checkout->transaction->last_payment();
2773
+			// $payment_source = 'last_payment after Exception';
2774
+			// but if we STILL don't have a payment object
2775
+			if (! $payment instanceof EE_Payment) {
2776
+				// then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2777
+				$this->_handle_payment_processor_exception($e);
2778
+			}
2779
+		}
2780
+		return $payment;
2781
+	}
2782
+
2783
+
2784
+	/**
2785
+	 * _process_cancelled_payments
2786
+	 * just makes sure that the payment status gets updated correctly
2787
+	 * so tha tan error isn't generated during payment validation
2788
+	 *
2789
+	 * @param EE_Payment $payment
2790
+	 * @return EE_Payment|null
2791
+	 * @throws EE_Error
2792
+	 */
2793
+	private function _process_cancelled_payments($payment = null)
2794
+	{
2795
+		if (
2796
+			$payment instanceof EE_Payment
2797
+			&& $this->request->requestParamIsSet('ee_cancel_payment')
2798
+			&& $payment->status() === EEM_Payment::status_id_failed
2799
+		) {
2800
+			$payment->set_status(EEM_Payment::status_id_cancelled);
2801
+		}
2802
+		return $payment;
2803
+	}
2804
+
2805
+
2806
+	/**
2807
+	 *    get_transaction_details_for_gateways
2808
+	 *
2809
+	 * @access    public
2810
+	 * @return void
2811
+	 * @throws EE_Error
2812
+	 * @throws InvalidArgumentException
2813
+	 * @throws ReflectionException
2814
+	 * @throws InvalidDataTypeException
2815
+	 * @throws InvalidInterfaceException
2816
+	 */
2817
+	public function get_transaction_details_for_gateways()
2818
+	{
2819
+		$txn_details = [];
2820
+		// ya gotta make a choice man
2821
+		if (empty($this->checkout->selected_method_of_payment)) {
2822
+			$txn_details = [
2823
+				'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'),
2824
+			];
2825
+		}
2826
+		// get EE_Payment_Method object
2827
+		if (
2828
+			empty($txn_details)
2829
+			&& ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2830
+		) {
2831
+			$txn_details = [
2832
+				'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2833
+				'error'                      => esc_html__(
2834
+					'A valid Payment Method could not be determined.',
2835
+					'event_espresso'
2836
+				),
2837
+			];
2838
+		}
2839
+		if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2840
+			$return_url  = $this->_get_return_url($this->checkout->payment_method);
2841
+			$txn_details = [
2842
+				'TXN_ID'         => $this->checkout->transaction->ID(),
2843
+				'TXN_timestamp'  => $this->checkout->transaction->datetime(),
2844
+				'TXN_total'      => $this->checkout->transaction->total(),
2845
+				'TXN_paid'       => $this->checkout->transaction->paid(),
2846
+				'TXN_reg_steps'  => $this->checkout->transaction->reg_steps(),
2847
+				'STS_ID'         => $this->checkout->transaction->status_ID(),
2848
+				'PMD_ID'         => $this->checkout->transaction->payment_method_ID(),
2849
+				'payment_amount' => $this->checkout->amount_owing,
2850
+				'return_url'     => $return_url,
2851
+				'cancel_url'     => add_query_arg(['ee_cancel_payment' => true], $return_url),
2852
+				'notify_url'     => EE_Config::instance()->core->txn_page_url(
2853
+					[
2854
+						'e_reg_url_link'    => $this->checkout->transaction->primary_registration()->reg_url_link(),
2855
+						'ee_payment_method' => $this->checkout->payment_method->slug(),
2856
+					]
2857
+				),
2858
+			];
2859
+		}
2860
+		echo wp_json_encode($txn_details);
2861
+		exit();
2862
+	}
2863
+
2864
+
2865
+	/**
2866
+	 *    __sleep
2867
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
2868
+	 * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
2869
+	 * reg form, because if needed, it will be regenerated anyways
2870
+	 *
2871
+	 * @return array
2872
+	 */
2873
+	public function __sleep()
2874
+	{
2875
+		// remove the reg form and the checkout
2876
+		return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout', 'line_item_display']);
2877
+	}
2878 2878
 }
Please login to merge, or discard this patch.
modules/core_rest_api/EED_Core_Rest_Api.module.php 2 patches
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      */
124 124
     protected static function _set_hooks_for_changes()
125 125
     {
126
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false);
126
+        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api/changes'), false);
127 127
         foreach ($folder_contents as $classname_in_namespace => $filepath) {
128 128
             // ignore the base parent class
129 129
             // and legacy named classes
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             ) {
134 134
                 continue;
135 135
             }
136
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
136
+            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace;
137 137
             if (class_exists($full_classname)) {
138 138
                 $instance_of_class = new $full_classname();
139 139
                 if ($instance_of_class instanceof ChangesInBase) {
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
                      * }
179 179
                      */
180 180
                     // skip route options
181
-                    if (! is_numeric($endpoint_key)) {
181
+                    if ( ! is_numeric($endpoint_key)) {
182 182
                         continue;
183 183
                     }
184
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
184
+                    if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
185 185
                         throw new EE_Error(
186 186
                             esc_html__(
187 187
                             // @codingStandardsIgnoreStart
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                     }
203 203
                     if (isset($data_for_single_endpoint['callback_args'])) {
204 204
                         $callback_args = $data_for_single_endpoint['callback_args'];
205
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
205
+                        $single_endpoint_args['callback'] = function(\WP_REST_Request $request) use (
206 206
                             $callback,
207 207
                             $callback_args
208 208
                         ) {
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                     // the REST API will issue a _doing_it_wrong notice.
220 220
                     // Since the EE REST API defers capabilities to the db model system,
221 221
                     // we will just use the generic WP callback for public endpoints
222
-                    if (! isset($single_endpoint_args['permission_callback'])) {
222
+                    if ( ! isset($single_endpoint_args['permission_callback'])) {
223 223
                         $single_endpoint_args['permission_callback'] = '__return_true';
224 224
                     }
225 225
                     $multiple_endpoint_args[] = $single_endpoint_args;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
                     $schema_route_data = $data_for_multiple_endpoints['schema'];
229 229
                     $schema_callback = $schema_route_data['schema_callback'];
230 230
                     $callback_args = $schema_route_data['callback_args'];
231
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
231
+                    $multiple_endpoint_args['schema'] = function() use ($schema_callback, $callback_args) {
232 232
                         return call_user_func_array(
233 233
                             $schema_callback,
234 234
                             $callback_args
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     {
271 271
         // delete the saved EE REST API routes
272 272
         foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
273
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
273
+            delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version);
274 274
         }
275 275
     }
276 276
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
     {
290 290
         $ee_routes = array();
291 291
         foreach (self::versions_served() as $version => $hidden_endpoints) {
292
-            $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
292
+            $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version(
293 293
                 $version,
294 294
                 $hidden_endpoints
295 295
             );
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
      */
310 310
     protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
311 311
     {
312
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
313
-        if (! $ee_routes || EED_Core_Rest_Api::debugMode()) {
312
+        $ee_routes = get_option(self::saved_routes_option_names.$version, null);
313
+        if ( ! $ee_routes || EED_Core_Rest_Api::debugMode()) {
314 314
             $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
315 315
         }
316 316
         return $ee_routes;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                 $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
338 338
             )
339 339
         );
340
-        $option_name = self::saved_routes_option_names . $version;
340
+        $option_name = self::saved_routes_option_names.$version;
341 341
         if (get_option($option_name)) {
342 342
             update_option($option_name, $routes, true);
343 343
         } else {
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
     {
383 383
         $model_routes = array();
384 384
         foreach (self::versions_served() as $version => $hidden_endpoint) {
385
-            $model_routes[ EED_Core_Rest_Api::ee_api_namespace
386
-                           . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
385
+            $model_routes[EED_Core_Rest_Api::ee_api_namespace
386
+                           . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
387 387
         }
388 388
         return $model_routes;
389 389
     }
@@ -452,13 +452,13 @@  discard block
 block discarded – undo
452 452
         foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
453 453
             $model = \EE_Registry::instance()->load_model($model_name);
454 454
             // if this isn't a valid model then let's skip iterate to the next item in the loop.
455
-            if (! $model instanceof EEM_Base) {
455
+            if ( ! $model instanceof EEM_Base) {
456 456
                 continue;
457 457
             }
458 458
             // yes we could just register one route for ALL models, but then they wouldn't show up in the index
459 459
             $plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
460 460
             $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
461
-            $model_routes[ $plural_model_route ] = array(
461
+            $model_routes[$plural_model_route] = array(
462 462
                 array(
463 463
                     'callback'        => array(
464 464
                         'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
                     'hidden_endpoint' => $hidden_endpoint,
470 470
                     'args'            => $this->_get_read_query_params($model, $version),
471 471
                     '_links'          => array(
472
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
472
+                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route),
473 473
                     ),
474 474
                 ),
475 475
                 'schema' => array(
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
                     'callback_args'   => array($version, $model_name),
481 481
                 ),
482 482
             );
483
-            $model_routes[ $singular_model_route ] = array(
483
+            $model_routes[$singular_model_route] = array(
484 484
                 array(
485 485
                     'callback'        => array(
486 486
                         'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
                     $model
500 500
                 )
501 501
             ) {
502
-                $model_routes[ $plural_model_route ][] = array(
502
+                $model_routes[$plural_model_route][] = array(
503 503
                     'callback'        => array(
504 504
                         'EventEspresso\core\libraries\rest_api\controllers\model\Write',
505 505
                         'handleRequestInsert',
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
                     'hidden_endpoint' => $hidden_endpoint,
510 510
                     'args'            => $this->_get_write_params($model_name, $model_version_info, true),
511 511
                 );
512
-                $model_routes[ $singular_model_route ] = array_merge(
513
-                    $model_routes[ $singular_model_route ],
512
+                $model_routes[$singular_model_route] = array_merge(
513
+                    $model_routes[$singular_model_route],
514 514
                     array(
515 515
                         array(
516 516
                             'callback'        => array(
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
                     '(?P<id>[^\/]+)',
542 542
                     $relation_obj
543 543
                 );
544
-                $model_routes[ $related_route ] = array(
544
+                $model_routes[$related_route] = array(
545 545
                     array(
546 546
                         'callback'        => array(
547 547
                             'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
                     ),
555 555
                 );
556 556
 
557
-                $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)';
558
-                $model_routes[ $related_write_route ] = array(
557
+                $related_write_route = $related_route.'/'.'(?P<related_id>[^\/]+)';
558
+                $model_routes[$related_write_route] = array(
559 559
                     array(
560 560
                         'callback'        => array(
561 561
                             'EventEspresso\core\libraries\rest_api\controllers\model\Write',
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
      */
609 609
     public static function get_entity_route($model, $id)
610 610
     {
611
-        return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
611
+        return EED_Core_Rest_Api::get_collection_route($model).'/'.$id;
612 612
     }
613 613
 
614 614
 
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
             $relation_obj->get_other_model()->get_this_model_name(),
629 629
             $relation_obj
630 630
         );
631
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
631
+        return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part;
632 632
     }
633 633
 
634 634
 
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
      */
643 643
     public static function get_versioned_route_to($relative_route, $version = '4.8.36')
644 644
     {
645
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
645
+        return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route;
646 646
     }
647 647
 
648 648
 
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
     {
657 657
         $routes = array();
658 658
         foreach (self::versions_served() as $version => $hidden_endpoint) {
659
-            $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
659
+            $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version(
660 660
                 $version,
661 661
                 $hidden_endpoint
662 662
             );
@@ -779,12 +779,12 @@  discard block
 block discarded – undo
779 779
     {
780 780
         // if they're related through a HABTM relation, check for any non-FKs
781 781
         $all_relation_settings = $source_model->relation_settings();
782
-        $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ];
782
+        $relation_settings = $all_relation_settings[$related_model->get_this_model_name()];
783 783
         $params = array();
784 784
         if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) {
785 785
             foreach ($relation_settings->getNonKeyFields() as $field) {
786 786
                 /* @var $field EE_Model_Field_Base */
787
-                $params[ $field->get_name() ] = array(
787
+                $params[$field->get_name()] = array(
788 788
                     'required' => ! $field->is_nullable(),
789 789
                     'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version),
790 790
                     'type' => $field->getSchemaType(),
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
     {
810 810
         $default_orderby = array();
811 811
         foreach ($model->get_combined_primary_key_fields() as $key_field) {
812
-            $default_orderby[ $key_field->get_name() ] = 'ASC';
812
+            $default_orderby[$key_field->get_name()] = 'ASC';
813 813
         }
814 814
         return array_merge(
815 815
             $this->_get_response_selection_query_params($model, $version),
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
                     'type'              => array(
844 844
                         'object',
845 845
                         'string',
846
-                    ),// because we accept a variety of types, WP core validation and sanitization
846
+                    ), // because we accept a variety of types, WP core validation and sanitization
847 847
                     // freaks out. We'll just validate this argument while handling the request
848 848
                     'validate_callback' => null,
849 849
                     'sanitize_callback' => null,
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
                 $sanitize_callback = null;
943 943
             }
944 944
             $arg_info['sanitize_callback'] = $sanitize_callback;
945
-            $args_info[ $field_name ] = $arg_info;
945
+            $args_info[$field_name] = $arg_info;
946 946
             if ($field_obj instanceof EE_Datetime_Field) {
947 947
                 $gmt_arg_info = $arg_info;
948 948
                 $gmt_arg_info['description'] = sprintf(
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
                     $field_obj->get_nicename(),
954 954
                     $field_name
955 955
                 );
956
-                $args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
956
+                $args_info[$field_name.'_gmt'] = $gmt_arg_info;
957 957
             }
958 958
         }
959 959
         return $args_info;
@@ -977,18 +977,18 @@  discard block
 block discarded – undo
977 977
     {
978 978
         $attributes = $request->get_attributes();
979 979
         if (
980
-            ! isset($attributes['args'][ $param ])
981
-            || ! is_array($attributes['args'][ $param ])
980
+            ! isset($attributes['args'][$param])
981
+            || ! is_array($attributes['args'][$param])
982 982
         ) {
983 983
             $validation_result = true;
984 984
         } else {
985
-            $args = $attributes['args'][ $param ];
985
+            $args = $attributes['args'][$param];
986 986
             if (
987 987
                 (
988 988
                     $value === ''
989 989
                     || $value === null
990 990
                 )
991
-                && (! isset($args['required'])
991
+                && ( ! isset($args['required'])
992 992
                     || $args['required'] === false
993 993
                 )
994 994
             ) {
@@ -999,7 +999,7 @@  discard block
 block discarded – undo
999 999
                       && $args['format'] === 'email'
1000 1000
             ) {
1001 1001
                 $validation_result = true;
1002
-                if (! self::_validate_email($value)) {
1002
+                if ( ! self::_validate_email($value)) {
1003 1003
                     $validation_result = new WP_Error(
1004 1004
                         'rest_invalid_param',
1005 1005
                         esc_html__(
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
     {
1050 1050
         $config_routes = array();
1051 1051
         foreach (self::versions_served() as $version => $hidden_endpoint) {
1052
-            $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
1052
+            $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version(
1053 1053
                 $version,
1054 1054
                 $hidden_endpoint
1055 1055
             );
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
     {
1105 1105
         $meta_routes = array();
1106 1106
         foreach (self::versions_served() as $version => $hidden_endpoint) {
1107
-            $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1107
+            $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version(
1108 1108
                 $version,
1109 1109
                 $hidden_endpoint
1110 1110
             );
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
             foreach ($relative_urls as $resource_name => $endpoints) {
1157 1157
                 foreach ($endpoints as $key => $endpoint) {
1158 1158
                     // skip schema and other route options
1159
-                    if (! is_numeric($key)) {
1159
+                    if ( ! is_numeric($key)) {
1160 1160
                         continue;
1161 1161
                     }
1162 1162
                     // by default, hide "hidden_endpoint"s, unless the request indicates
@@ -1166,9 +1166,9 @@  discard block
 block discarded – undo
1166 1166
                         ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1167 1167
                         || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1168 1168
                     ) {
1169
-                        $full_route = '/' . ltrim($namespace, '/');
1170
-                        $full_route .= '/' . ltrim($resource_name, '/');
1171
-                        unset($route_data[ $full_route ]);
1169
+                        $full_route = '/'.ltrim($namespace, '/');
1170
+                        $full_route .= '/'.ltrim($resource_name, '/');
1171
+                        unset($route_data[$full_route]);
1172 1172
                     }
1173 1173
                 }
1174 1174
             }
@@ -1242,13 +1242,13 @@  discard block
 block discarded – undo
1242 1242
 
1243 1243
             if ($key_versioned_endpoint === $latest_version) {
1244 1244
                 // don't hide the latest version in the index
1245
-                $versions_served[ $key_versioned_endpoint ] = false;
1245
+                $versions_served[$key_versioned_endpoint] = false;
1246 1246
             } elseif (
1247 1247
                 version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=')
1248 1248
                 && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<')
1249 1249
             ) {
1250 1250
                 // include, but hide, previous versions which are still supported
1251
-                $versions_served[ $key_versioned_endpoint ] = true;
1251
+                $versions_served[$key_versioned_endpoint] = true;
1252 1252
             } elseif (
1253 1253
                 apply_filters(
1254 1254
                     'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
                 )
1258 1258
             ) {
1259 1259
                 // if a version is no longer supported, don't include it in index or list of versions served
1260
-                $versions_served[ $key_versioned_endpoint ] = true;
1260
+                $versions_served[$key_versioned_endpoint] = true;
1261 1261
             }
1262 1262
         }
1263 1263
         return $versions_served;
@@ -1315,7 +1315,7 @@  discard block
 block discarded – undo
1315 1315
         $model_names = self::model_names_with_plural_routes($version);
1316 1316
         $collection_routes = array();
1317 1317
         foreach ($model_names as $model_name => $model_class_name) {
1318
-            $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/'
1318
+            $collection_routes[strtolower($model_name)] = '/'.self::ee_api_namespace.$version.'/'
1319 1319
                                                             . EEH_Inflector::pluralize_and_lower($model_name);
1320 1320
         }
1321 1321
         return $collection_routes;
@@ -1336,9 +1336,9 @@  discard block
 block discarded – undo
1336 1336
             $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields();
1337 1337
             foreach ($primary_keys as $primary_key_name => $primary_key_field) {
1338 1338
                 if (count($primary_keys) > 1) {
1339
-                    $primary_key_items[ strtolower($model_name) ][] = $primary_key_name;
1339
+                    $primary_key_items[strtolower($model_name)][] = $primary_key_name;
1340 1340
                 } else {
1341
-                    $primary_key_items[ strtolower($model_name) ] = $primary_key_name;
1341
+                    $primary_key_items[strtolower($model_name)] = $primary_key_name;
1342 1342
                 }
1343 1343
             }
1344 1344
         }
Please login to merge, or discard this patch.
Indentation   +1348 added lines, -1348 removed lines patch added patch discarded remove patch
@@ -22,1352 +22,1352 @@
 block discarded – undo
22 22
  */
23 23
 class EED_Core_Rest_Api extends \EED_Module
24 24
 {
25
-    const ee_api_namespace = Domain::API_NAMESPACE;
26
-
27
-    const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
28
-
29
-    const saved_routes_option_names = 'ee_core_routes';
30
-
31
-    /**
32
-     * string used in _links response bodies to make them globally unique.
33
-     *
34
-     * @see http://v2.wp-api.org/extending/linking/
35
-     */
36
-    const ee_api_link_namespace = 'https://api.eventespresso.com/';
37
-
38
-    /**
39
-     * @var CalculatedModelFields
40
-     */
41
-    protected static $_field_calculator;
42
-
43
-
44
-    /**
45
-     * @return EED_Core_Rest_Api|EED_Module
46
-     */
47
-    public static function instance()
48
-    {
49
-        self::$_field_calculator = LoaderFactory::getLoader()->load('EventEspresso\core\libraries\rest_api\CalculatedModelFields');
50
-        return parent::get_instance(__CLASS__);
51
-    }
52
-
53
-
54
-    /**
55
-     *    set_hooks - for hooking into EE Core, other modules, etc
56
-     *
57
-     * @access    public
58
-     * @return    void
59
-     */
60
-    public static function set_hooks()
61
-    {
62
-        self::set_hooks_both();
63
-    }
64
-
65
-
66
-    /**
67
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
68
-     *
69
-     * @access    public
70
-     * @return    void
71
-     */
72
-    public static function set_hooks_admin()
73
-    {
74
-        self::set_hooks_both();
75
-    }
76
-
77
-
78
-    public static function set_hooks_both()
79
-    {
80
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
81
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
82
-        add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
83
-        add_filter(
84
-            'rest_index',
85
-            array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')
86
-        );
87
-        EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
88
-    }
89
-
90
-
91
-    /**
92
-     * sets up hooks which only need to be included as part of REST API requests;
93
-     * other requests like to the frontend or admin etc don't need them
94
-     *
95
-     * @throws \EE_Error
96
-     */
97
-    public static function set_hooks_rest_api()
98
-    {
99
-        // set hooks which account for changes made to the API
100
-        EED_Core_Rest_Api::_set_hooks_for_changes();
101
-    }
102
-
103
-
104
-    /**
105
-     * public wrapper of _set_hooks_for_changes.
106
-     * Loads all the hooks which make requests to old versions of the API
107
-     * appear the same as they always did
108
-     *
109
-     * @throws EE_Error
110
-     */
111
-    public static function set_hooks_for_changes()
112
-    {
113
-        self::_set_hooks_for_changes();
114
-    }
115
-
116
-
117
-    /**
118
-     * Loads all the hooks which make requests to old versions of the API
119
-     * appear the same as they always did
120
-     *
121
-     * @throws EE_Error
122
-     */
123
-    protected static function _set_hooks_for_changes()
124
-    {
125
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false);
126
-        foreach ($folder_contents as $classname_in_namespace => $filepath) {
127
-            // ignore the base parent class
128
-            // and legacy named classes
129
-            if (
130
-                $classname_in_namespace === 'ChangesInBase'
131
-                || strpos($classname_in_namespace, 'Changes_In_') === 0
132
-            ) {
133
-                continue;
134
-            }
135
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
136
-            if (class_exists($full_classname)) {
137
-                $instance_of_class = new $full_classname();
138
-                if ($instance_of_class instanceof ChangesInBase) {
139
-                    $instance_of_class->setHooks();
140
-                }
141
-            }
142
-        }
143
-    }
144
-
145
-
146
-    /**
147
-     * Filters the WP routes to add our EE-related ones. This takes a bit of time
148
-     * so we actually prefer to only do it when an EE plugin is activated or upgraded
149
-     *
150
-     * @throws \EE_Error
151
-     */
152
-    public static function register_routes()
153
-    {
154
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
155
-            foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
156
-                /**
157
-                 * @var array     $data_for_multiple_endpoints numerically indexed array
158
-                 *                                         but can also contain route options like {
159
-                 * @type array    $schema                      {
160
-                 * @type callable $schema_callback
161
-                 * @type array    $callback_args               arguments that will be passed to the callback, after the
162
-                 * WP_REST_Request of course
163
-                 * }
164
-                 * }
165
-                 */
166
-                // when registering routes, register all the endpoints' data at the same time
167
-                $multiple_endpoint_args = array();
168
-                foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
169
-                    /**
170
-                     * @var array     $data_for_single_endpoint {
171
-                     * @type callable $callback
172
-                     * @type string methods
173
-                     * @type array args
174
-                     * @type array _links
175
-                     * @type array    $callback_args            arguments that will be passed to the callback, after the
176
-                     * WP_REST_Request of course
177
-                     * }
178
-                     */
179
-                    // skip route options
180
-                    if (! is_numeric($endpoint_key)) {
181
-                        continue;
182
-                    }
183
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
184
-                        throw new EE_Error(
185
-                            esc_html__(
186
-                            // @codingStandardsIgnoreStart
187
-                                'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
188
-                                // @codingStandardsIgnoreEnd
189
-                                'event_espresso'
190
-                            )
191
-                        );
192
-                    }
193
-                    $callback = $data_for_single_endpoint['callback'];
194
-                    $single_endpoint_args = array(
195
-                        'methods' => $data_for_single_endpoint['methods'],
196
-                        'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
197
-                            : array(),
198
-                    );
199
-                    if (isset($data_for_single_endpoint['_links'])) {
200
-                        $single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
201
-                    }
202
-                    if (isset($data_for_single_endpoint['callback_args'])) {
203
-                        $callback_args = $data_for_single_endpoint['callback_args'];
204
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
205
-                            $callback,
206
-                            $callback_args
207
-                        ) {
208
-                            array_unshift($callback_args, $request);
209
-                            return call_user_func_array(
210
-                                $callback,
211
-                                $callback_args
212
-                            );
213
-                        };
214
-                    } else {
215
-                        $single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
216
-                    }
217
-                    // As of WordPress 5.5, if a permission_callback is not provided,
218
-                    // the REST API will issue a _doing_it_wrong notice.
219
-                    // Since the EE REST API defers capabilities to the db model system,
220
-                    // we will just use the generic WP callback for public endpoints
221
-                    if (! isset($single_endpoint_args['permission_callback'])) {
222
-                        $single_endpoint_args['permission_callback'] = '__return_true';
223
-                    }
224
-                    $multiple_endpoint_args[] = $single_endpoint_args;
225
-                }
226
-                if (isset($data_for_multiple_endpoints['schema'])) {
227
-                    $schema_route_data = $data_for_multiple_endpoints['schema'];
228
-                    $schema_callback = $schema_route_data['schema_callback'];
229
-                    $callback_args = $schema_route_data['callback_args'];
230
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
231
-                        return call_user_func_array(
232
-                            $schema_callback,
233
-                            $callback_args
234
-                        );
235
-                    };
236
-                }
237
-                register_rest_route(
238
-                    $namespace,
239
-                    $relative_route,
240
-                    $multiple_endpoint_args
241
-                );
242
-            }
243
-        }
244
-    }
245
-
246
-
247
-    /**
248
-     * Checks if there was a version change or something that merits invalidating the cached
249
-     * route data. If so, invalidates the cached route data so that it gets refreshed
250
-     * next time the WP API is used
251
-     */
252
-    public static function invalidate_cached_route_data_on_version_change()
253
-    {
254
-        if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
255
-            EED_Core_Rest_Api::invalidate_cached_route_data();
256
-        }
257
-        foreach (EE_Registry::instance()->addons as $addon) {
258
-            if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
259
-                EED_Core_Rest_Api::invalidate_cached_route_data();
260
-            }
261
-        }
262
-    }
263
-
264
-
265
-    /**
266
-     * Removes the cached route data so it will get refreshed next time the WP API is used
267
-     */
268
-    public static function invalidate_cached_route_data()
269
-    {
270
-        // delete the saved EE REST API routes
271
-        foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
272
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
273
-        }
274
-    }
275
-
276
-
277
-    /**
278
-     * Gets the EE route data
279
-     *
280
-     * @return array top-level key is the namespace, next-level key is the route and its value is array{
281
-     * @throws \EE_Error
282
-     * @type string|array $callback
283
-     * @type string       $methods
284
-     * @type boolean      $hidden_endpoint
285
-     * }
286
-     */
287
-    public static function get_ee_route_data()
288
-    {
289
-        $ee_routes = array();
290
-        foreach (self::versions_served() as $version => $hidden_endpoints) {
291
-            $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
292
-                $version,
293
-                $hidden_endpoints
294
-            );
295
-        }
296
-        return $ee_routes;
297
-    }
298
-
299
-
300
-    /**
301
-     * Gets the EE route data from the wp options if it exists already,
302
-     * otherwise re-generates it and saves it to the option
303
-     *
304
-     * @param string  $version
305
-     * @param boolean $hidden_endpoints
306
-     * @return array
307
-     * @throws \EE_Error
308
-     */
309
-    protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
310
-    {
311
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
312
-        if (! $ee_routes || EED_Core_Rest_Api::debugMode()) {
313
-            $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
314
-        }
315
-        return $ee_routes;
316
-    }
317
-
318
-
319
-    /**
320
-     * Saves the EE REST API route data to a wp option and returns it
321
-     *
322
-     * @param string  $version
323
-     * @param boolean $hidden_endpoints
324
-     * @return mixed|null
325
-     * @throws \EE_Error
326
-     */
327
-    protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
328
-    {
329
-        $instance = self::instance();
330
-        $routes = apply_filters(
331
-            'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
332
-            array_replace_recursive(
333
-                $instance->_get_config_route_data_for_version($version, $hidden_endpoints),
334
-                $instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
335
-                $instance->_get_model_route_data_for_version($version, $hidden_endpoints),
336
-                $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
337
-            )
338
-        );
339
-        $option_name = self::saved_routes_option_names . $version;
340
-        if (get_option($option_name)) {
341
-            update_option($option_name, $routes, true);
342
-        } else {
343
-            add_option($option_name, $routes, null, 'no');
344
-        }
345
-        return $routes;
346
-    }
347
-
348
-
349
-    /**
350
-     * Calculates all the EE routes and saves it to a WordPress option so we don't
351
-     * need to calculate it on every request
352
-     *
353
-     * @deprecated since version 4.9.1
354
-     * @return void
355
-     */
356
-    public static function save_ee_routes()
357
-    {
358
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
359
-            $instance = self::instance();
360
-            $routes = apply_filters(
361
-                'EED_Core_Rest_Api__save_ee_routes__routes',
362
-                array_replace_recursive(
363
-                    $instance->_register_config_routes(),
364
-                    $instance->_register_meta_routes(),
365
-                    $instance->_register_model_routes(),
366
-                    $instance->_register_rpc_routes()
367
-                )
368
-            );
369
-            update_option(self::saved_routes_option_names, $routes, true);
370
-        }
371
-    }
372
-
373
-
374
-    /**
375
-     * Gets all the route information relating to EE models
376
-     *
377
-     * @return array @see get_ee_route_data
378
-     * @deprecated since version 4.9.1
379
-     */
380
-    protected function _register_model_routes()
381
-    {
382
-        $model_routes = array();
383
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
384
-            $model_routes[ EED_Core_Rest_Api::ee_api_namespace
385
-                           . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
386
-        }
387
-        return $model_routes;
388
-    }
389
-
390
-
391
-    /**
392
-     * Decides whether or not to add write endpoints for this model.
393
-     *
394
-     * Currently, this defaults to exclude all global tables and models
395
-     * which would allow inserting WP core data (we don't want to duplicate
396
-     * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
397
-     *
398
-     * @param EEM_Base $model
399
-     * @return bool
400
-     */
401
-    public static function should_have_write_endpoints(EEM_Base $model)
402
-    {
403
-        if ($model->is_wp_core_model()) {
404
-            return false;
405
-        }
406
-        foreach ($model->get_tables() as $table) {
407
-            if ($table->is_global()) {
408
-                return false;
409
-            }
410
-        }
411
-        return true;
412
-    }
413
-
414
-
415
-    /**
416
-     * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
417
-     * in this versioned namespace of EE4
418
-     *
419
-     * @param $version
420
-     * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
421
-     */
422
-    public static function model_names_with_plural_routes($version)
423
-    {
424
-        $model_version_info = new ModelVersionInfo($version);
425
-        $models_to_register = $model_version_info->modelsForRequestedVersion();
426
-        // let's not bother having endpoints for extra metas
427
-        unset(
428
-            $models_to_register['Extra_Meta'],
429
-            $models_to_register['Extra_Join'],
430
-            $models_to_register['Post_Meta']
431
-        );
432
-        return apply_filters(
433
-            'FHEE__EED_Core_REST_API___register_model_routes',
434
-            $models_to_register
435
-        );
436
-    }
437
-
438
-
439
-    /**
440
-     * Gets the route data for EE models in the specified version
441
-     *
442
-     * @param string  $version
443
-     * @param boolean $hidden_endpoint
444
-     * @return array
445
-     * @throws EE_Error
446
-     */
447
-    protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
448
-    {
449
-        $model_routes = array();
450
-        $model_version_info = new ModelVersionInfo($version);
451
-        foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
452
-            $model = \EE_Registry::instance()->load_model($model_name);
453
-            // if this isn't a valid model then let's skip iterate to the next item in the loop.
454
-            if (! $model instanceof EEM_Base) {
455
-                continue;
456
-            }
457
-            // yes we could just register one route for ALL models, but then they wouldn't show up in the index
458
-            $plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
459
-            $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
460
-            $model_routes[ $plural_model_route ] = array(
461
-                array(
462
-                    'callback'        => array(
463
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
464
-                        'handleRequestGetAll',
465
-                    ),
466
-                    'callback_args'   => array($version, $model_name),
467
-                    'methods'         => WP_REST_Server::READABLE,
468
-                    'hidden_endpoint' => $hidden_endpoint,
469
-                    'args'            => $this->_get_read_query_params($model, $version),
470
-                    '_links'          => array(
471
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
472
-                    ),
473
-                ),
474
-                'schema' => array(
475
-                    'schema_callback' => array(
476
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
477
-                        'handleSchemaRequest',
478
-                    ),
479
-                    'callback_args'   => array($version, $model_name),
480
-                ),
481
-            );
482
-            $model_routes[ $singular_model_route ] = array(
483
-                array(
484
-                    'callback'        => array(
485
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
486
-                        'handleRequestGetOne',
487
-                    ),
488
-                    'callback_args'   => array($version, $model_name),
489
-                    'methods'         => WP_REST_Server::READABLE,
490
-                    'hidden_endpoint' => $hidden_endpoint,
491
-                    'args'            => $this->_get_response_selection_query_params($model, $version, true),
492
-                ),
493
-            );
494
-            if (
495
-                apply_filters(
496
-                    'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
497
-                    EED_Core_Rest_Api::should_have_write_endpoints($model),
498
-                    $model
499
-                )
500
-            ) {
501
-                $model_routes[ $plural_model_route ][] = array(
502
-                    'callback'        => array(
503
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Write',
504
-                        'handleRequestInsert',
505
-                    ),
506
-                    'callback_args'   => array($version, $model_name),
507
-                    'methods'         => WP_REST_Server::CREATABLE,
508
-                    'hidden_endpoint' => $hidden_endpoint,
509
-                    'args'            => $this->_get_write_params($model_name, $model_version_info, true),
510
-                );
511
-                $model_routes[ $singular_model_route ] = array_merge(
512
-                    $model_routes[ $singular_model_route ],
513
-                    array(
514
-                        array(
515
-                            'callback'        => array(
516
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
517
-                                'handleRequestUpdate',
518
-                            ),
519
-                            'callback_args'   => array($version, $model_name),
520
-                            'methods'         => WP_REST_Server::EDITABLE,
521
-                            'hidden_endpoint' => $hidden_endpoint,
522
-                            'args'            => $this->_get_write_params($model_name, $model_version_info),
523
-                        ),
524
-                        array(
525
-                            'callback'        => array(
526
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
527
-                                'handleRequestDelete',
528
-                            ),
529
-                            'callback_args'   => array($version, $model_name),
530
-                            'methods'         => WP_REST_Server::DELETABLE,
531
-                            'hidden_endpoint' => $hidden_endpoint,
532
-                            'args'            => $this->_get_delete_query_params($model, $version),
533
-                        ),
534
-                    )
535
-                );
536
-            }
537
-            foreach ($model->relation_settings() as $relation_name => $relation_obj) {
538
-                $related_route = EED_Core_Rest_Api::get_relation_route_via(
539
-                    $model,
540
-                    '(?P<id>[^\/]+)',
541
-                    $relation_obj
542
-                );
543
-                $model_routes[ $related_route ] = array(
544
-                    array(
545
-                        'callback'        => array(
546
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
547
-                            'handleRequestGetRelated',
548
-                        ),
549
-                        'callback_args'   => array($version, $model_name, $relation_name),
550
-                        'methods'         => WP_REST_Server::READABLE,
551
-                        'hidden_endpoint' => $hidden_endpoint,
552
-                        'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
553
-                    ),
554
-                );
555
-
556
-                $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)';
557
-                $model_routes[ $related_write_route ] = array(
558
-                    array(
559
-                        'callback'        => array(
560
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Write',
561
-                            'handleRequestAddRelation',
562
-                        ),
563
-                        'callback_args'   => array($version, $model_name, $relation_name),
564
-                        'methods'         => WP_REST_Server::EDITABLE,
565
-                        'hidden_endpoint' => $hidden_endpoint,
566
-                        'args'            => $this->_get_add_relation_query_params($model, $relation_obj->get_other_model(), $version)
567
-                    ),
568
-                    array(
569
-                        'callback'        => array(
570
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Write',
571
-                            'handleRequestRemoveRelation',
572
-                        ),
573
-                        'callback_args'   => array($version, $model_name, $relation_name),
574
-                        'methods'         => WP_REST_Server::DELETABLE,
575
-                        'hidden_endpoint' => $hidden_endpoint,
576
-                        'args'            => array()
577
-                    ),
578
-                );
579
-            }
580
-        }
581
-        return $model_routes;
582
-    }
583
-
584
-
585
-    /**
586
-     * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
587
-     * excluding the preceding slash.
588
-     * Eg you pass get_plural_route_to('Event') = 'events'
589
-     *
590
-     * @param EEM_Base $model
591
-     * @return string
592
-     */
593
-    public static function get_collection_route(EEM_Base $model)
594
-    {
595
-        return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
596
-    }
597
-
598
-
599
-    /**
600
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
601
-     * excluding the preceding slash.
602
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
603
-     *
604
-     * @param EEM_Base $model eg Event or Venue
605
-     * @param string   $id
606
-     * @return string
607
-     */
608
-    public static function get_entity_route($model, $id)
609
-    {
610
-        return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
611
-    }
612
-
613
-
614
-    /**
615
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
616
-     * excluding the preceding slash.
617
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
618
-     *
619
-     * @param EEM_Base               $model eg Event or Venue
620
-     * @param string                 $id
621
-     * @param EE_Model_Relation_Base $relation_obj
622
-     * @return string
623
-     */
624
-    public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
625
-    {
626
-        $related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
627
-            $relation_obj->get_other_model()->get_this_model_name(),
628
-            $relation_obj
629
-        );
630
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
631
-    }
632
-
633
-
634
-    /**
635
-     * Adds onto the $relative_route the EE4 REST API versioned namespace.
636
-     * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
637
-     *
638
-     * @param string $relative_route
639
-     * @param string $version
640
-     * @return string
641
-     */
642
-    public static function get_versioned_route_to($relative_route, $version = '4.8.36')
643
-    {
644
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
645
-    }
646
-
647
-
648
-    /**
649
-     * Adds all the RPC-style routes (remote procedure call-like routes, ie
650
-     * routes that don't conform to the traditional REST CRUD-style).
651
-     *
652
-     * @deprecated since 4.9.1
653
-     */
654
-    protected function _register_rpc_routes()
655
-    {
656
-        $routes = array();
657
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
658
-            $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
659
-                $version,
660
-                $hidden_endpoint
661
-            );
662
-        }
663
-        return $routes;
664
-    }
665
-
666
-
667
-    /**
668
-     * @param string  $version
669
-     * @param boolean $hidden_endpoint
670
-     * @return array
671
-     */
672
-    protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
673
-    {
674
-        $this_versions_routes = array();
675
-        // checkin endpoint
676
-        $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
677
-            array(
678
-                'callback'        => array(
679
-                    'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
680
-                    'handleRequestToggleCheckin',
681
-                ),
682
-                'methods'         => WP_REST_Server::CREATABLE,
683
-                'hidden_endpoint' => $hidden_endpoint,
684
-                'args'            => array(
685
-                    'force' => array(
686
-                        'required'    => false,
687
-                        'default'     => false,
688
-                        'description' => esc_html__(
689
-                        // @codingStandardsIgnoreStart
690
-                            'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
691
-                            // @codingStandardsIgnoreEnd
692
-                            'event_espresso'
693
-                        ),
694
-                    ),
695
-                ),
696
-                'callback_args'   => array($version),
697
-            ),
698
-        );
699
-        return apply_filters(
700
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
701
-            $this_versions_routes,
702
-            $version,
703
-            $hidden_endpoint
704
-        );
705
-    }
706
-
707
-
708
-    /**
709
-     * Gets the query params that can be used when request one or many
710
-     *
711
-     * @param EEM_Base $model
712
-     * @param string   $version
713
-     * @return array
714
-     */
715
-    protected function _get_response_selection_query_params(\EEM_Base $model, $version, $single_only = false)
716
-    {
717
-        $query_params = array(
718
-            'include'   => array(
719
-                'required' => false,
720
-                'default'  => '*',
721
-                'type'     => 'string',
722
-            ),
723
-            'calculate' => array(
724
-                'required'          => false,
725
-                'default'           => '',
726
-                'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
727
-                'type'              => 'string',
728
-                // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
729
-                // freaks out. We'll just validate this argument while handling the request
730
-                'validate_callback' => null,
731
-                'sanitize_callback' => null,
732
-            ),
733
-            'password' => array(
734
-                'required' => false,
735
-                'default' => '',
736
-                'type' => 'string'
737
-            )
738
-        );
739
-        return apply_filters(
740
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
741
-            $query_params,
742
-            $model,
743
-            $version
744
-        );
745
-    }
746
-
747
-
748
-    /**
749
-     * Gets the parameters acceptable for delete requests
750
-     *
751
-     * @param \EEM_Base $model
752
-     * @param string    $version
753
-     * @return array
754
-     */
755
-    protected function _get_delete_query_params(\EEM_Base $model, $version)
756
-    {
757
-        $params_for_delete = array(
758
-            'allow_blocking' => array(
759
-                'required' => false,
760
-                'default'  => true,
761
-                'type'     => 'boolean',
762
-            ),
763
-        );
764
-        $params_for_delete['force'] = array(
765
-            'required' => false,
766
-            'default'  => false,
767
-            'type'     => 'boolean',
768
-        );
769
-        return apply_filters(
770
-            'FHEE__EED_Core_Rest_Api___get_delete_query_params',
771
-            $params_for_delete,
772
-            $model,
773
-            $version
774
-        );
775
-    }
776
-
777
-    protected function _get_add_relation_query_params(\EEM_Base $source_model, \EEM_Base $related_model, $version)
778
-    {
779
-        // if they're related through a HABTM relation, check for any non-FKs
780
-        $all_relation_settings = $source_model->relation_settings();
781
-        $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ];
782
-        $params = array();
783
-        if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) {
784
-            foreach ($relation_settings->getNonKeyFields() as $field) {
785
-                /* @var $field EE_Model_Field_Base */
786
-                $params[ $field->get_name() ] = array(
787
-                    'required' => ! $field->is_nullable(),
788
-                    'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version),
789
-                    'type' => $field->getSchemaType(),
790
-                    'validate_callbaack' => null,
791
-                    'sanitize_callback' => null
792
-                );
793
-            }
794
-        }
795
-        return $params;
796
-    }
797
-
798
-
799
-    /**
800
-     * Gets info about reading query params that are acceptable
801
-     *
802
-     * @param \EEM_Base $model eg 'Event' or 'Venue'
803
-     * @param  string   $version
804
-     * @return array    describing the args acceptable when querying this model
805
-     * @throws EE_Error
806
-     */
807
-    protected function _get_read_query_params(\EEM_Base $model, $version)
808
-    {
809
-        $default_orderby = array();
810
-        foreach ($model->get_combined_primary_key_fields() as $key_field) {
811
-            $default_orderby[ $key_field->get_name() ] = 'ASC';
812
-        }
813
-        return array_merge(
814
-            $this->_get_response_selection_query_params($model, $version),
815
-            array(
816
-                'where'    => array(
817
-                    'required'          => false,
818
-                    'default'           => array(),
819
-                    'type'              => 'object',
820
-                    // because we accept an almost infinite list of possible where conditions, WP
821
-                    // core validation and sanitization freaks out. We'll just validate this argument
822
-                    // while handling the request
823
-                    'validate_callback' => null,
824
-                    'sanitize_callback' => null,
825
-                ),
826
-                'limit'    => array(
827
-                    'required'          => false,
828
-                    'default'           => EED_Core_Rest_Api::get_default_query_limit(),
829
-                    'type'              => array(
830
-                        'array',
831
-                        'string',
832
-                        'integer',
833
-                    ),
834
-                    // because we accept a variety of types, WP core validation and sanitization
835
-                    // freaks out. We'll just validate this argument while handling the request
836
-                    'validate_callback' => null,
837
-                    'sanitize_callback' => null,
838
-                ),
839
-                'order_by' => array(
840
-                    'required'          => false,
841
-                    'default'           => $default_orderby,
842
-                    'type'              => array(
843
-                        'object',
844
-                        'string',
845
-                    ),// because we accept a variety of types, WP core validation and sanitization
846
-                    // freaks out. We'll just validate this argument while handling the request
847
-                    'validate_callback' => null,
848
-                    'sanitize_callback' => null,
849
-                ),
850
-                'group_by' => array(
851
-                    'required'          => false,
852
-                    'default'           => null,
853
-                    'type'              => array(
854
-                        'object',
855
-                        'string',
856
-                    ),
857
-                    // because we accept  an almost infinite list of possible groupings,
858
-                    // WP core validation and sanitization
859
-                    // freaks out. We'll just validate this argument while handling the request
860
-                    'validate_callback' => null,
861
-                    'sanitize_callback' => null,
862
-                ),
863
-                'having'   => array(
864
-                    'required'          => false,
865
-                    'default'           => null,
866
-                    'type'              => 'object',
867
-                    // because we accept an almost infinite list of possible where conditions, WP
868
-                    // core validation and sanitization freaks out. We'll just validate this argument
869
-                    // while handling the request
870
-                    'validate_callback' => null,
871
-                    'sanitize_callback' => null,
872
-                ),
873
-                'caps'     => array(
874
-                    'required' => false,
875
-                    'default'  => EEM_Base::caps_read,
876
-                    'type'     => 'string',
877
-                    'enum'     => array(
878
-                        EEM_Base::caps_read,
879
-                        EEM_Base::caps_read_admin,
880
-                        EEM_Base::caps_edit,
881
-                        EEM_Base::caps_delete,
882
-                    ),
883
-                ),
884
-            )
885
-        );
886
-    }
887
-
888
-
889
-    /**
890
-     * Gets parameter information for a model regarding writing data
891
-     *
892
-     * @param string           $model_name
893
-     * @param ModelVersionInfo $model_version_info
894
-     * @param boolean          $create                                       whether this is for request to create (in
895
-     *                                                                       which case we need all required params) or
896
-     *                                                                       just to update (in which case we don't
897
-     *                                                                       need those on every request)
898
-     * @return array
899
-     */
900
-    protected function _get_write_params(
901
-        $model_name,
902
-        ModelVersionInfo $model_version_info,
903
-        $create = false
904
-    ) {
905
-        $model = EE_Registry::instance()->load_model($model_name);
906
-        $fields = $model_version_info->fieldsOnModelInThisVersion($model);
907
-        $args_info = array();
908
-        foreach ($fields as $field_name => $field_obj) {
909
-            if ($field_obj->is_auto_increment()) {
910
-                // totally ignore auto increment IDs
911
-                continue;
912
-            }
913
-            $arg_info = $field_obj->getSchema();
914
-            $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
915
-            $arg_info['required'] = $required;
916
-            // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
917
-            unset($arg_info['readonly']);
918
-            $schema_properties = $field_obj->getSchemaProperties();
919
-            if (
920
-                isset($schema_properties['raw'])
921
-                && $field_obj->getSchemaType() === 'object'
922
-            ) {
923
-                // if there's a "raw" form of this argument, use those properties instead
924
-                $arg_info = array_replace(
925
-                    $arg_info,
926
-                    $schema_properties['raw']
927
-                );
928
-            }
929
-            $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
930
-                $field_obj,
931
-                $field_obj->get_default_value(),
932
-                $model_version_info->requestedVersion()
933
-            );
934
-            // we do our own validation and sanitization within the controller
935
-            if (function_exists('rest_validate_value_from_schema')) {
936
-                $sanitize_callback = array(
937
-                    'EED_Core_Rest_Api',
938
-                    'default_sanitize_callback',
939
-                );
940
-            } else {
941
-                $sanitize_callback = null;
942
-            }
943
-            $arg_info['sanitize_callback'] = $sanitize_callback;
944
-            $args_info[ $field_name ] = $arg_info;
945
-            if ($field_obj instanceof EE_Datetime_Field) {
946
-                $gmt_arg_info = $arg_info;
947
-                $gmt_arg_info['description'] = sprintf(
948
-                    esc_html__(
949
-                        '%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
950
-                        'event_espresso'
951
-                    ),
952
-                    $field_obj->get_nicename(),
953
-                    $field_name
954
-                );
955
-                $args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
956
-            }
957
-        }
958
-        return $args_info;
959
-    }
960
-
961
-
962
-    /**
963
-     * Replacement for WP API's 'rest_parse_request_arg'.
964
-     * If the value is blank but not required, don't bother validating it.
965
-     * Also, it uses our email validation instead of WP API's default.
966
-     *
967
-     * @param                 $value
968
-     * @param WP_REST_Request $request
969
-     * @param                 $param
970
-     * @return bool|true|WP_Error
971
-     * @throws InvalidArgumentException
972
-     * @throws InvalidInterfaceException
973
-     * @throws InvalidDataTypeException
974
-     */
975
-    public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
976
-    {
977
-        $attributes = $request->get_attributes();
978
-        if (
979
-            ! isset($attributes['args'][ $param ])
980
-            || ! is_array($attributes['args'][ $param ])
981
-        ) {
982
-            $validation_result = true;
983
-        } else {
984
-            $args = $attributes['args'][ $param ];
985
-            if (
986
-                (
987
-                    $value === ''
988
-                    || $value === null
989
-                )
990
-                && (! isset($args['required'])
991
-                    || $args['required'] === false
992
-                )
993
-            ) {
994
-                // not required and not provided? that's cool
995
-                $validation_result = true;
996
-            } elseif (
997
-                isset($args['format'])
998
-                      && $args['format'] === 'email'
999
-            ) {
1000
-                $validation_result = true;
1001
-                if (! self::_validate_email($value)) {
1002
-                    $validation_result = new WP_Error(
1003
-                        'rest_invalid_param',
1004
-                        esc_html__(
1005
-                            'The email address is not valid or does not exist.',
1006
-                            'event_espresso'
1007
-                        )
1008
-                    );
1009
-                }
1010
-            } else {
1011
-                $validation_result = rest_validate_value_from_schema($value, $args, $param);
1012
-            }
1013
-        }
1014
-        if (is_wp_error($validation_result)) {
1015
-            return $validation_result;
1016
-        }
1017
-        return rest_sanitize_request_arg($value, $request, $param);
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
1023
-     *
1024
-     * @param $email
1025
-     * @return bool
1026
-     * @throws InvalidArgumentException
1027
-     * @throws InvalidInterfaceException
1028
-     * @throws InvalidDataTypeException
1029
-     */
1030
-    protected static function _validate_email($email)
1031
-    {
1032
-        try {
1033
-            EmailAddressFactory::create($email);
1034
-            return true;
1035
-        } catch (EmailValidationException $e) {
1036
-            return false;
1037
-        }
1038
-    }
1039
-
1040
-
1041
-    /**
1042
-     * Gets routes for the config
1043
-     *
1044
-     * @return array @see _register_model_routes
1045
-     * @deprecated since version 4.9.1
1046
-     */
1047
-    protected function _register_config_routes()
1048
-    {
1049
-        $config_routes = array();
1050
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
1051
-            $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
1052
-                $version,
1053
-                $hidden_endpoint
1054
-            );
1055
-        }
1056
-        return $config_routes;
1057
-    }
1058
-
1059
-
1060
-    /**
1061
-     * Gets routes for the config for the specified version
1062
-     *
1063
-     * @param string  $version
1064
-     * @param boolean $hidden_endpoint
1065
-     * @return array
1066
-     */
1067
-    protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1068
-    {
1069
-        return array(
1070
-            'config'    => array(
1071
-                array(
1072
-                    'callback'        => array(
1073
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1074
-                        'handleRequest',
1075
-                    ),
1076
-                    'methods'         => WP_REST_Server::READABLE,
1077
-                    'hidden_endpoint' => $hidden_endpoint,
1078
-                    'callback_args'   => array($version),
1079
-                ),
1080
-            ),
1081
-            'site_info' => array(
1082
-                array(
1083
-                    'callback'        => array(
1084
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1085
-                        'handleRequestSiteInfo',
1086
-                    ),
1087
-                    'methods'         => WP_REST_Server::READABLE,
1088
-                    'hidden_endpoint' => $hidden_endpoint,
1089
-                    'callback_args'   => array($version),
1090
-                ),
1091
-            ),
1092
-        );
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * Gets the meta info routes
1098
-     *
1099
-     * @return array @see _register_model_routes
1100
-     * @deprecated since version 4.9.1
1101
-     */
1102
-    protected function _register_meta_routes()
1103
-    {
1104
-        $meta_routes = array();
1105
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
1106
-            $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1107
-                $version,
1108
-                $hidden_endpoint
1109
-            );
1110
-        }
1111
-        return $meta_routes;
1112
-    }
1113
-
1114
-
1115
-    /**
1116
-     * @param string  $version
1117
-     * @param boolean $hidden_endpoint
1118
-     * @return array
1119
-     */
1120
-    protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1121
-    {
1122
-        return array(
1123
-            'resources' => array(
1124
-                array(
1125
-                    'callback'        => array(
1126
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1127
-                        'handleRequestModelsMeta',
1128
-                    ),
1129
-                    'methods'         => WP_REST_Server::READABLE,
1130
-                    'hidden_endpoint' => $hidden_endpoint,
1131
-                    'callback_args'   => array($version),
1132
-                ),
1133
-            ),
1134
-        );
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     * Tries to hide old 4.6 endpoints from the
1140
-     *
1141
-     * @param array $route_data
1142
-     * @return array
1143
-     * @throws \EE_Error
1144
-     */
1145
-    public static function hide_old_endpoints($route_data)
1146
-    {
1147
-        // allow API clients to override which endpoints get hidden, in case
1148
-        // they want to discover particular endpoints
1149
-        // also, we don't have access to the request so we have to just grab it from the superglobal
1150
-        $force_show_ee_namespace = ltrim(
1151
-            EED_Core_Rest_Api::getRequest()->getRequestParam('force_show_ee_namespace'),
1152
-            '/'
1153
-        );
1154
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1155
-            foreach ($relative_urls as $resource_name => $endpoints) {
1156
-                foreach ($endpoints as $key => $endpoint) {
1157
-                    // skip schema and other route options
1158
-                    if (! is_numeric($key)) {
1159
-                        continue;
1160
-                    }
1161
-                    // by default, hide "hidden_endpoint"s, unless the request indicates
1162
-                    // to $force_show_ee_namespace, in which case only show that one
1163
-                    // namespace's endpoints (and hide all others)
1164
-                    if (
1165
-                        ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1166
-                        || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1167
-                    ) {
1168
-                        $full_route = '/' . ltrim($namespace, '/');
1169
-                        $full_route .= '/' . ltrim($resource_name, '/');
1170
-                        unset($route_data[ $full_route ]);
1171
-                    }
1172
-                }
1173
-            }
1174
-        }
1175
-        return $route_data;
1176
-    }
1177
-
1178
-
1179
-    /**
1180
-     * Returns an array describing which versions of core support serving requests for.
1181
-     * Keys are core versions' major and minor version, and values are the
1182
-     * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1183
-     * data by just removing a few models and fields from the responses. However, 4.15 might remove
1184
-     * the answers table entirely, in which case it would be very difficult for
1185
-     * it to serve 4.6-style responses.
1186
-     * Versions of core that are missing from this array are unknowns.
1187
-     * previous ver
1188
-     *
1189
-     * @return array
1190
-     */
1191
-    public static function version_compatibilities()
1192
-    {
1193
-        return apply_filters(
1194
-            'FHEE__EED_Core_REST_API__version_compatibilities',
1195
-            array(
1196
-                '4.8.29' => '4.8.29',
1197
-                '4.8.33' => '4.8.29',
1198
-                '4.8.34' => '4.8.29',
1199
-                '4.8.36' => '4.8.29',
1200
-            )
1201
-        );
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     * Gets the latest API version served. Eg if there
1207
-     * are two versions served of the API, 4.8.29 and 4.8.32, and
1208
-     * we are on core version 4.8.34, it will return the string "4.8.32"
1209
-     *
1210
-     * @return string
1211
-     */
1212
-    public static function latest_rest_api_version()
1213
-    {
1214
-        $versions_served = \EED_Core_Rest_Api::versions_served();
1215
-        $versions_served_keys = array_keys($versions_served);
1216
-        return end($versions_served_keys);
1217
-    }
1218
-
1219
-
1220
-    /**
1221
-     * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1222
-     * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1223
-     * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1224
-     * We also indicate whether or not this version should be put in the index or not
1225
-     *
1226
-     * @return array keys are API version numbers (just major and minor numbers), and values
1227
-     * are whether or not they should be hidden
1228
-     */
1229
-    public static function versions_served()
1230
-    {
1231
-        $versions_served = array();
1232
-        $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1233
-        $lowest_compatible_version = end($possibly_served_versions);
1234
-        reset($possibly_served_versions);
1235
-        $versions_served_historically = array_keys($possibly_served_versions);
1236
-        $latest_version = end($versions_served_historically);
1237
-        reset($versions_served_historically);
1238
-        // for each version of core we have ever served:
1239
-        foreach ($versions_served_historically as $key_versioned_endpoint) {
1240
-            // if it's not above the current core version, and it's compatible with the current version of core
1241
-
1242
-            if ($key_versioned_endpoint === $latest_version) {
1243
-                // don't hide the latest version in the index
1244
-                $versions_served[ $key_versioned_endpoint ] = false;
1245
-            } elseif (
1246
-                version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=')
1247
-                && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<')
1248
-            ) {
1249
-                // include, but hide, previous versions which are still supported
1250
-                $versions_served[ $key_versioned_endpoint ] = true;
1251
-            } elseif (
1252
-                apply_filters(
1253
-                    'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1254
-                    false,
1255
-                    $possibly_served_versions
1256
-                )
1257
-            ) {
1258
-                // if a version is no longer supported, don't include it in index or list of versions served
1259
-                $versions_served[ $key_versioned_endpoint ] = true;
1260
-            }
1261
-        }
1262
-        return $versions_served;
1263
-    }
1264
-
1265
-
1266
-    /**
1267
-     * Gets the major and minor version of EE core's version string
1268
-     *
1269
-     * @return string
1270
-     */
1271
-    public static function core_version()
1272
-    {
1273
-        return apply_filters(
1274
-            'FHEE__EED_Core_REST_API__core_version',
1275
-            implode(
1276
-                '.',
1277
-                array_slice(
1278
-                    explode(
1279
-                        '.',
1280
-                        espresso_version()
1281
-                    ),
1282
-                    0,
1283
-                    3
1284
-                )
1285
-            )
1286
-        );
1287
-    }
1288
-
1289
-
1290
-    /**
1291
-     * Gets the default limit that should be used when querying for resources
1292
-     *
1293
-     * @return int
1294
-     */
1295
-    public static function get_default_query_limit()
1296
-    {
1297
-        // we actually don't use a const because we want folks to always use
1298
-        // this method, not the const directly
1299
-        return apply_filters(
1300
-            'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1301
-            50
1302
-        );
1303
-    }
1304
-
1305
-
1306
-    /**
1307
-     *
1308
-     * @param string $version api version string (i.e. '4.8.36')
1309
-     * @return array
1310
-     */
1311
-    public static function getCollectionRoutesIndexedByModelName($version = '')
1312
-    {
1313
-        $version = empty($version) ? self::latest_rest_api_version() : $version;
1314
-        $model_names = self::model_names_with_plural_routes($version);
1315
-        $collection_routes = array();
1316
-        foreach ($model_names as $model_name => $model_class_name) {
1317
-            $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/'
1318
-                                                            . EEH_Inflector::pluralize_and_lower($model_name);
1319
-        }
1320
-        return $collection_routes;
1321
-    }
1322
-
1323
-
1324
-    /**
1325
-     * Returns an array of primary key names indexed by model names.
1326
-     * @param string $version
1327
-     * @return array
1328
-     */
1329
-    public static function getPrimaryKeyNamesIndexedByModelName($version = '')
1330
-    {
1331
-        $version = empty($version) ? self::latest_rest_api_version() : $version;
1332
-        $model_names = self::model_names_with_plural_routes($version);
1333
-        $primary_key_items = array();
1334
-        foreach ($model_names as $model_name => $model_class_name) {
1335
-            $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields();
1336
-            foreach ($primary_keys as $primary_key_name => $primary_key_field) {
1337
-                if (count($primary_keys) > 1) {
1338
-                    $primary_key_items[ strtolower($model_name) ][] = $primary_key_name;
1339
-                } else {
1340
-                    $primary_key_items[ strtolower($model_name) ] = $primary_key_name;
1341
-                }
1342
-            }
1343
-        }
1344
-        return $primary_key_items;
1345
-    }
1346
-
1347
-    /**
1348
-     * Determines the EE REST API debug mode is activated, or not.
1349
-     * @since 4.9.76.p
1350
-     * @return bool
1351
-     */
1352
-    public static function debugMode()
1353
-    {
1354
-        static $debug_mode = null; // could be class prop
1355
-        if ($debug_mode === null) {
1356
-            $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE;
1357
-        }
1358
-        return $debug_mode;
1359
-    }
1360
-
1361
-
1362
-
1363
-    /**
1364
-     *    run - initial module setup
1365
-     *
1366
-     * @access    public
1367
-     * @param  WP $WP
1368
-     * @return    void
1369
-     */
1370
-    public function run($WP)
1371
-    {
1372
-    }
25
+	const ee_api_namespace = Domain::API_NAMESPACE;
26
+
27
+	const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
28
+
29
+	const saved_routes_option_names = 'ee_core_routes';
30
+
31
+	/**
32
+	 * string used in _links response bodies to make them globally unique.
33
+	 *
34
+	 * @see http://v2.wp-api.org/extending/linking/
35
+	 */
36
+	const ee_api_link_namespace = 'https://api.eventespresso.com/';
37
+
38
+	/**
39
+	 * @var CalculatedModelFields
40
+	 */
41
+	protected static $_field_calculator;
42
+
43
+
44
+	/**
45
+	 * @return EED_Core_Rest_Api|EED_Module
46
+	 */
47
+	public static function instance()
48
+	{
49
+		self::$_field_calculator = LoaderFactory::getLoader()->load('EventEspresso\core\libraries\rest_api\CalculatedModelFields');
50
+		return parent::get_instance(__CLASS__);
51
+	}
52
+
53
+
54
+	/**
55
+	 *    set_hooks - for hooking into EE Core, other modules, etc
56
+	 *
57
+	 * @access    public
58
+	 * @return    void
59
+	 */
60
+	public static function set_hooks()
61
+	{
62
+		self::set_hooks_both();
63
+	}
64
+
65
+
66
+	/**
67
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
68
+	 *
69
+	 * @access    public
70
+	 * @return    void
71
+	 */
72
+	public static function set_hooks_admin()
73
+	{
74
+		self::set_hooks_both();
75
+	}
76
+
77
+
78
+	public static function set_hooks_both()
79
+	{
80
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
81
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
82
+		add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
83
+		add_filter(
84
+			'rest_index',
85
+			array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')
86
+		);
87
+		EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
88
+	}
89
+
90
+
91
+	/**
92
+	 * sets up hooks which only need to be included as part of REST API requests;
93
+	 * other requests like to the frontend or admin etc don't need them
94
+	 *
95
+	 * @throws \EE_Error
96
+	 */
97
+	public static function set_hooks_rest_api()
98
+	{
99
+		// set hooks which account for changes made to the API
100
+		EED_Core_Rest_Api::_set_hooks_for_changes();
101
+	}
102
+
103
+
104
+	/**
105
+	 * public wrapper of _set_hooks_for_changes.
106
+	 * Loads all the hooks which make requests to old versions of the API
107
+	 * appear the same as they always did
108
+	 *
109
+	 * @throws EE_Error
110
+	 */
111
+	public static function set_hooks_for_changes()
112
+	{
113
+		self::_set_hooks_for_changes();
114
+	}
115
+
116
+
117
+	/**
118
+	 * Loads all the hooks which make requests to old versions of the API
119
+	 * appear the same as they always did
120
+	 *
121
+	 * @throws EE_Error
122
+	 */
123
+	protected static function _set_hooks_for_changes()
124
+	{
125
+		$folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false);
126
+		foreach ($folder_contents as $classname_in_namespace => $filepath) {
127
+			// ignore the base parent class
128
+			// and legacy named classes
129
+			if (
130
+				$classname_in_namespace === 'ChangesInBase'
131
+				|| strpos($classname_in_namespace, 'Changes_In_') === 0
132
+			) {
133
+				continue;
134
+			}
135
+			$full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
136
+			if (class_exists($full_classname)) {
137
+				$instance_of_class = new $full_classname();
138
+				if ($instance_of_class instanceof ChangesInBase) {
139
+					$instance_of_class->setHooks();
140
+				}
141
+			}
142
+		}
143
+	}
144
+
145
+
146
+	/**
147
+	 * Filters the WP routes to add our EE-related ones. This takes a bit of time
148
+	 * so we actually prefer to only do it when an EE plugin is activated or upgraded
149
+	 *
150
+	 * @throws \EE_Error
151
+	 */
152
+	public static function register_routes()
153
+	{
154
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
155
+			foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
156
+				/**
157
+				 * @var array     $data_for_multiple_endpoints numerically indexed array
158
+				 *                                         but can also contain route options like {
159
+				 * @type array    $schema                      {
160
+				 * @type callable $schema_callback
161
+				 * @type array    $callback_args               arguments that will be passed to the callback, after the
162
+				 * WP_REST_Request of course
163
+				 * }
164
+				 * }
165
+				 */
166
+				// when registering routes, register all the endpoints' data at the same time
167
+				$multiple_endpoint_args = array();
168
+				foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
169
+					/**
170
+					 * @var array     $data_for_single_endpoint {
171
+					 * @type callable $callback
172
+					 * @type string methods
173
+					 * @type array args
174
+					 * @type array _links
175
+					 * @type array    $callback_args            arguments that will be passed to the callback, after the
176
+					 * WP_REST_Request of course
177
+					 * }
178
+					 */
179
+					// skip route options
180
+					if (! is_numeric($endpoint_key)) {
181
+						continue;
182
+					}
183
+					if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
184
+						throw new EE_Error(
185
+							esc_html__(
186
+							// @codingStandardsIgnoreStart
187
+								'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
188
+								// @codingStandardsIgnoreEnd
189
+								'event_espresso'
190
+							)
191
+						);
192
+					}
193
+					$callback = $data_for_single_endpoint['callback'];
194
+					$single_endpoint_args = array(
195
+						'methods' => $data_for_single_endpoint['methods'],
196
+						'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
197
+							: array(),
198
+					);
199
+					if (isset($data_for_single_endpoint['_links'])) {
200
+						$single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
201
+					}
202
+					if (isset($data_for_single_endpoint['callback_args'])) {
203
+						$callback_args = $data_for_single_endpoint['callback_args'];
204
+						$single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
205
+							$callback,
206
+							$callback_args
207
+						) {
208
+							array_unshift($callback_args, $request);
209
+							return call_user_func_array(
210
+								$callback,
211
+								$callback_args
212
+							);
213
+						};
214
+					} else {
215
+						$single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
216
+					}
217
+					// As of WordPress 5.5, if a permission_callback is not provided,
218
+					// the REST API will issue a _doing_it_wrong notice.
219
+					// Since the EE REST API defers capabilities to the db model system,
220
+					// we will just use the generic WP callback for public endpoints
221
+					if (! isset($single_endpoint_args['permission_callback'])) {
222
+						$single_endpoint_args['permission_callback'] = '__return_true';
223
+					}
224
+					$multiple_endpoint_args[] = $single_endpoint_args;
225
+				}
226
+				if (isset($data_for_multiple_endpoints['schema'])) {
227
+					$schema_route_data = $data_for_multiple_endpoints['schema'];
228
+					$schema_callback = $schema_route_data['schema_callback'];
229
+					$callback_args = $schema_route_data['callback_args'];
230
+					$multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
231
+						return call_user_func_array(
232
+							$schema_callback,
233
+							$callback_args
234
+						);
235
+					};
236
+				}
237
+				register_rest_route(
238
+					$namespace,
239
+					$relative_route,
240
+					$multiple_endpoint_args
241
+				);
242
+			}
243
+		}
244
+	}
245
+
246
+
247
+	/**
248
+	 * Checks if there was a version change or something that merits invalidating the cached
249
+	 * route data. If so, invalidates the cached route data so that it gets refreshed
250
+	 * next time the WP API is used
251
+	 */
252
+	public static function invalidate_cached_route_data_on_version_change()
253
+	{
254
+		if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
255
+			EED_Core_Rest_Api::invalidate_cached_route_data();
256
+		}
257
+		foreach (EE_Registry::instance()->addons as $addon) {
258
+			if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
259
+				EED_Core_Rest_Api::invalidate_cached_route_data();
260
+			}
261
+		}
262
+	}
263
+
264
+
265
+	/**
266
+	 * Removes the cached route data so it will get refreshed next time the WP API is used
267
+	 */
268
+	public static function invalidate_cached_route_data()
269
+	{
270
+		// delete the saved EE REST API routes
271
+		foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
272
+			delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
273
+		}
274
+	}
275
+
276
+
277
+	/**
278
+	 * Gets the EE route data
279
+	 *
280
+	 * @return array top-level key is the namespace, next-level key is the route and its value is array{
281
+	 * @throws \EE_Error
282
+	 * @type string|array $callback
283
+	 * @type string       $methods
284
+	 * @type boolean      $hidden_endpoint
285
+	 * }
286
+	 */
287
+	public static function get_ee_route_data()
288
+	{
289
+		$ee_routes = array();
290
+		foreach (self::versions_served() as $version => $hidden_endpoints) {
291
+			$ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
292
+				$version,
293
+				$hidden_endpoints
294
+			);
295
+		}
296
+		return $ee_routes;
297
+	}
298
+
299
+
300
+	/**
301
+	 * Gets the EE route data from the wp options if it exists already,
302
+	 * otherwise re-generates it and saves it to the option
303
+	 *
304
+	 * @param string  $version
305
+	 * @param boolean $hidden_endpoints
306
+	 * @return array
307
+	 * @throws \EE_Error
308
+	 */
309
+	protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
310
+	{
311
+		$ee_routes = get_option(self::saved_routes_option_names . $version, null);
312
+		if (! $ee_routes || EED_Core_Rest_Api::debugMode()) {
313
+			$ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
314
+		}
315
+		return $ee_routes;
316
+	}
317
+
318
+
319
+	/**
320
+	 * Saves the EE REST API route data to a wp option and returns it
321
+	 *
322
+	 * @param string  $version
323
+	 * @param boolean $hidden_endpoints
324
+	 * @return mixed|null
325
+	 * @throws \EE_Error
326
+	 */
327
+	protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
328
+	{
329
+		$instance = self::instance();
330
+		$routes = apply_filters(
331
+			'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
332
+			array_replace_recursive(
333
+				$instance->_get_config_route_data_for_version($version, $hidden_endpoints),
334
+				$instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
335
+				$instance->_get_model_route_data_for_version($version, $hidden_endpoints),
336
+				$instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
337
+			)
338
+		);
339
+		$option_name = self::saved_routes_option_names . $version;
340
+		if (get_option($option_name)) {
341
+			update_option($option_name, $routes, true);
342
+		} else {
343
+			add_option($option_name, $routes, null, 'no');
344
+		}
345
+		return $routes;
346
+	}
347
+
348
+
349
+	/**
350
+	 * Calculates all the EE routes and saves it to a WordPress option so we don't
351
+	 * need to calculate it on every request
352
+	 *
353
+	 * @deprecated since version 4.9.1
354
+	 * @return void
355
+	 */
356
+	public static function save_ee_routes()
357
+	{
358
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
359
+			$instance = self::instance();
360
+			$routes = apply_filters(
361
+				'EED_Core_Rest_Api__save_ee_routes__routes',
362
+				array_replace_recursive(
363
+					$instance->_register_config_routes(),
364
+					$instance->_register_meta_routes(),
365
+					$instance->_register_model_routes(),
366
+					$instance->_register_rpc_routes()
367
+				)
368
+			);
369
+			update_option(self::saved_routes_option_names, $routes, true);
370
+		}
371
+	}
372
+
373
+
374
+	/**
375
+	 * Gets all the route information relating to EE models
376
+	 *
377
+	 * @return array @see get_ee_route_data
378
+	 * @deprecated since version 4.9.1
379
+	 */
380
+	protected function _register_model_routes()
381
+	{
382
+		$model_routes = array();
383
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
384
+			$model_routes[ EED_Core_Rest_Api::ee_api_namespace
385
+						   . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
386
+		}
387
+		return $model_routes;
388
+	}
389
+
390
+
391
+	/**
392
+	 * Decides whether or not to add write endpoints for this model.
393
+	 *
394
+	 * Currently, this defaults to exclude all global tables and models
395
+	 * which would allow inserting WP core data (we don't want to duplicate
396
+	 * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
397
+	 *
398
+	 * @param EEM_Base $model
399
+	 * @return bool
400
+	 */
401
+	public static function should_have_write_endpoints(EEM_Base $model)
402
+	{
403
+		if ($model->is_wp_core_model()) {
404
+			return false;
405
+		}
406
+		foreach ($model->get_tables() as $table) {
407
+			if ($table->is_global()) {
408
+				return false;
409
+			}
410
+		}
411
+		return true;
412
+	}
413
+
414
+
415
+	/**
416
+	 * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
417
+	 * in this versioned namespace of EE4
418
+	 *
419
+	 * @param $version
420
+	 * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
421
+	 */
422
+	public static function model_names_with_plural_routes($version)
423
+	{
424
+		$model_version_info = new ModelVersionInfo($version);
425
+		$models_to_register = $model_version_info->modelsForRequestedVersion();
426
+		// let's not bother having endpoints for extra metas
427
+		unset(
428
+			$models_to_register['Extra_Meta'],
429
+			$models_to_register['Extra_Join'],
430
+			$models_to_register['Post_Meta']
431
+		);
432
+		return apply_filters(
433
+			'FHEE__EED_Core_REST_API___register_model_routes',
434
+			$models_to_register
435
+		);
436
+	}
437
+
438
+
439
+	/**
440
+	 * Gets the route data for EE models in the specified version
441
+	 *
442
+	 * @param string  $version
443
+	 * @param boolean $hidden_endpoint
444
+	 * @return array
445
+	 * @throws EE_Error
446
+	 */
447
+	protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
448
+	{
449
+		$model_routes = array();
450
+		$model_version_info = new ModelVersionInfo($version);
451
+		foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
452
+			$model = \EE_Registry::instance()->load_model($model_name);
453
+			// if this isn't a valid model then let's skip iterate to the next item in the loop.
454
+			if (! $model instanceof EEM_Base) {
455
+				continue;
456
+			}
457
+			// yes we could just register one route for ALL models, but then they wouldn't show up in the index
458
+			$plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
459
+			$singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
460
+			$model_routes[ $plural_model_route ] = array(
461
+				array(
462
+					'callback'        => array(
463
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
464
+						'handleRequestGetAll',
465
+					),
466
+					'callback_args'   => array($version, $model_name),
467
+					'methods'         => WP_REST_Server::READABLE,
468
+					'hidden_endpoint' => $hidden_endpoint,
469
+					'args'            => $this->_get_read_query_params($model, $version),
470
+					'_links'          => array(
471
+						'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
472
+					),
473
+				),
474
+				'schema' => array(
475
+					'schema_callback' => array(
476
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
477
+						'handleSchemaRequest',
478
+					),
479
+					'callback_args'   => array($version, $model_name),
480
+				),
481
+			);
482
+			$model_routes[ $singular_model_route ] = array(
483
+				array(
484
+					'callback'        => array(
485
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
486
+						'handleRequestGetOne',
487
+					),
488
+					'callback_args'   => array($version, $model_name),
489
+					'methods'         => WP_REST_Server::READABLE,
490
+					'hidden_endpoint' => $hidden_endpoint,
491
+					'args'            => $this->_get_response_selection_query_params($model, $version, true),
492
+				),
493
+			);
494
+			if (
495
+				apply_filters(
496
+					'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
497
+					EED_Core_Rest_Api::should_have_write_endpoints($model),
498
+					$model
499
+				)
500
+			) {
501
+				$model_routes[ $plural_model_route ][] = array(
502
+					'callback'        => array(
503
+						'EventEspresso\core\libraries\rest_api\controllers\model\Write',
504
+						'handleRequestInsert',
505
+					),
506
+					'callback_args'   => array($version, $model_name),
507
+					'methods'         => WP_REST_Server::CREATABLE,
508
+					'hidden_endpoint' => $hidden_endpoint,
509
+					'args'            => $this->_get_write_params($model_name, $model_version_info, true),
510
+				);
511
+				$model_routes[ $singular_model_route ] = array_merge(
512
+					$model_routes[ $singular_model_route ],
513
+					array(
514
+						array(
515
+							'callback'        => array(
516
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
517
+								'handleRequestUpdate',
518
+							),
519
+							'callback_args'   => array($version, $model_name),
520
+							'methods'         => WP_REST_Server::EDITABLE,
521
+							'hidden_endpoint' => $hidden_endpoint,
522
+							'args'            => $this->_get_write_params($model_name, $model_version_info),
523
+						),
524
+						array(
525
+							'callback'        => array(
526
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
527
+								'handleRequestDelete',
528
+							),
529
+							'callback_args'   => array($version, $model_name),
530
+							'methods'         => WP_REST_Server::DELETABLE,
531
+							'hidden_endpoint' => $hidden_endpoint,
532
+							'args'            => $this->_get_delete_query_params($model, $version),
533
+						),
534
+					)
535
+				);
536
+			}
537
+			foreach ($model->relation_settings() as $relation_name => $relation_obj) {
538
+				$related_route = EED_Core_Rest_Api::get_relation_route_via(
539
+					$model,
540
+					'(?P<id>[^\/]+)',
541
+					$relation_obj
542
+				);
543
+				$model_routes[ $related_route ] = array(
544
+					array(
545
+						'callback'        => array(
546
+							'EventEspresso\core\libraries\rest_api\controllers\model\Read',
547
+							'handleRequestGetRelated',
548
+						),
549
+						'callback_args'   => array($version, $model_name, $relation_name),
550
+						'methods'         => WP_REST_Server::READABLE,
551
+						'hidden_endpoint' => $hidden_endpoint,
552
+						'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
553
+					),
554
+				);
555
+
556
+				$related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)';
557
+				$model_routes[ $related_write_route ] = array(
558
+					array(
559
+						'callback'        => array(
560
+							'EventEspresso\core\libraries\rest_api\controllers\model\Write',
561
+							'handleRequestAddRelation',
562
+						),
563
+						'callback_args'   => array($version, $model_name, $relation_name),
564
+						'methods'         => WP_REST_Server::EDITABLE,
565
+						'hidden_endpoint' => $hidden_endpoint,
566
+						'args'            => $this->_get_add_relation_query_params($model, $relation_obj->get_other_model(), $version)
567
+					),
568
+					array(
569
+						'callback'        => array(
570
+							'EventEspresso\core\libraries\rest_api\controllers\model\Write',
571
+							'handleRequestRemoveRelation',
572
+						),
573
+						'callback_args'   => array($version, $model_name, $relation_name),
574
+						'methods'         => WP_REST_Server::DELETABLE,
575
+						'hidden_endpoint' => $hidden_endpoint,
576
+						'args'            => array()
577
+					),
578
+				);
579
+			}
580
+		}
581
+		return $model_routes;
582
+	}
583
+
584
+
585
+	/**
586
+	 * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
587
+	 * excluding the preceding slash.
588
+	 * Eg you pass get_plural_route_to('Event') = 'events'
589
+	 *
590
+	 * @param EEM_Base $model
591
+	 * @return string
592
+	 */
593
+	public static function get_collection_route(EEM_Base $model)
594
+	{
595
+		return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
596
+	}
597
+
598
+
599
+	/**
600
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
601
+	 * excluding the preceding slash.
602
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
603
+	 *
604
+	 * @param EEM_Base $model eg Event or Venue
605
+	 * @param string   $id
606
+	 * @return string
607
+	 */
608
+	public static function get_entity_route($model, $id)
609
+	{
610
+		return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
611
+	}
612
+
613
+
614
+	/**
615
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
616
+	 * excluding the preceding slash.
617
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
618
+	 *
619
+	 * @param EEM_Base               $model eg Event or Venue
620
+	 * @param string                 $id
621
+	 * @param EE_Model_Relation_Base $relation_obj
622
+	 * @return string
623
+	 */
624
+	public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
625
+	{
626
+		$related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
627
+			$relation_obj->get_other_model()->get_this_model_name(),
628
+			$relation_obj
629
+		);
630
+		return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
631
+	}
632
+
633
+
634
+	/**
635
+	 * Adds onto the $relative_route the EE4 REST API versioned namespace.
636
+	 * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
637
+	 *
638
+	 * @param string $relative_route
639
+	 * @param string $version
640
+	 * @return string
641
+	 */
642
+	public static function get_versioned_route_to($relative_route, $version = '4.8.36')
643
+	{
644
+		return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
645
+	}
646
+
647
+
648
+	/**
649
+	 * Adds all the RPC-style routes (remote procedure call-like routes, ie
650
+	 * routes that don't conform to the traditional REST CRUD-style).
651
+	 *
652
+	 * @deprecated since 4.9.1
653
+	 */
654
+	protected function _register_rpc_routes()
655
+	{
656
+		$routes = array();
657
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
658
+			$routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
659
+				$version,
660
+				$hidden_endpoint
661
+			);
662
+		}
663
+		return $routes;
664
+	}
665
+
666
+
667
+	/**
668
+	 * @param string  $version
669
+	 * @param boolean $hidden_endpoint
670
+	 * @return array
671
+	 */
672
+	protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
673
+	{
674
+		$this_versions_routes = array();
675
+		// checkin endpoint
676
+		$this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
677
+			array(
678
+				'callback'        => array(
679
+					'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
680
+					'handleRequestToggleCheckin',
681
+				),
682
+				'methods'         => WP_REST_Server::CREATABLE,
683
+				'hidden_endpoint' => $hidden_endpoint,
684
+				'args'            => array(
685
+					'force' => array(
686
+						'required'    => false,
687
+						'default'     => false,
688
+						'description' => esc_html__(
689
+						// @codingStandardsIgnoreStart
690
+							'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
691
+							// @codingStandardsIgnoreEnd
692
+							'event_espresso'
693
+						),
694
+					),
695
+				),
696
+				'callback_args'   => array($version),
697
+			),
698
+		);
699
+		return apply_filters(
700
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
701
+			$this_versions_routes,
702
+			$version,
703
+			$hidden_endpoint
704
+		);
705
+	}
706
+
707
+
708
+	/**
709
+	 * Gets the query params that can be used when request one or many
710
+	 *
711
+	 * @param EEM_Base $model
712
+	 * @param string   $version
713
+	 * @return array
714
+	 */
715
+	protected function _get_response_selection_query_params(\EEM_Base $model, $version, $single_only = false)
716
+	{
717
+		$query_params = array(
718
+			'include'   => array(
719
+				'required' => false,
720
+				'default'  => '*',
721
+				'type'     => 'string',
722
+			),
723
+			'calculate' => array(
724
+				'required'          => false,
725
+				'default'           => '',
726
+				'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
727
+				'type'              => 'string',
728
+				// because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
729
+				// freaks out. We'll just validate this argument while handling the request
730
+				'validate_callback' => null,
731
+				'sanitize_callback' => null,
732
+			),
733
+			'password' => array(
734
+				'required' => false,
735
+				'default' => '',
736
+				'type' => 'string'
737
+			)
738
+		);
739
+		return apply_filters(
740
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
741
+			$query_params,
742
+			$model,
743
+			$version
744
+		);
745
+	}
746
+
747
+
748
+	/**
749
+	 * Gets the parameters acceptable for delete requests
750
+	 *
751
+	 * @param \EEM_Base $model
752
+	 * @param string    $version
753
+	 * @return array
754
+	 */
755
+	protected function _get_delete_query_params(\EEM_Base $model, $version)
756
+	{
757
+		$params_for_delete = array(
758
+			'allow_blocking' => array(
759
+				'required' => false,
760
+				'default'  => true,
761
+				'type'     => 'boolean',
762
+			),
763
+		);
764
+		$params_for_delete['force'] = array(
765
+			'required' => false,
766
+			'default'  => false,
767
+			'type'     => 'boolean',
768
+		);
769
+		return apply_filters(
770
+			'FHEE__EED_Core_Rest_Api___get_delete_query_params',
771
+			$params_for_delete,
772
+			$model,
773
+			$version
774
+		);
775
+	}
776
+
777
+	protected function _get_add_relation_query_params(\EEM_Base $source_model, \EEM_Base $related_model, $version)
778
+	{
779
+		// if they're related through a HABTM relation, check for any non-FKs
780
+		$all_relation_settings = $source_model->relation_settings();
781
+		$relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ];
782
+		$params = array();
783
+		if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) {
784
+			foreach ($relation_settings->getNonKeyFields() as $field) {
785
+				/* @var $field EE_Model_Field_Base */
786
+				$params[ $field->get_name() ] = array(
787
+					'required' => ! $field->is_nullable(),
788
+					'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version),
789
+					'type' => $field->getSchemaType(),
790
+					'validate_callbaack' => null,
791
+					'sanitize_callback' => null
792
+				);
793
+			}
794
+		}
795
+		return $params;
796
+	}
797
+
798
+
799
+	/**
800
+	 * Gets info about reading query params that are acceptable
801
+	 *
802
+	 * @param \EEM_Base $model eg 'Event' or 'Venue'
803
+	 * @param  string   $version
804
+	 * @return array    describing the args acceptable when querying this model
805
+	 * @throws EE_Error
806
+	 */
807
+	protected function _get_read_query_params(\EEM_Base $model, $version)
808
+	{
809
+		$default_orderby = array();
810
+		foreach ($model->get_combined_primary_key_fields() as $key_field) {
811
+			$default_orderby[ $key_field->get_name() ] = 'ASC';
812
+		}
813
+		return array_merge(
814
+			$this->_get_response_selection_query_params($model, $version),
815
+			array(
816
+				'where'    => array(
817
+					'required'          => false,
818
+					'default'           => array(),
819
+					'type'              => 'object',
820
+					// because we accept an almost infinite list of possible where conditions, WP
821
+					// core validation and sanitization freaks out. We'll just validate this argument
822
+					// while handling the request
823
+					'validate_callback' => null,
824
+					'sanitize_callback' => null,
825
+				),
826
+				'limit'    => array(
827
+					'required'          => false,
828
+					'default'           => EED_Core_Rest_Api::get_default_query_limit(),
829
+					'type'              => array(
830
+						'array',
831
+						'string',
832
+						'integer',
833
+					),
834
+					// because we accept a variety of types, WP core validation and sanitization
835
+					// freaks out. We'll just validate this argument while handling the request
836
+					'validate_callback' => null,
837
+					'sanitize_callback' => null,
838
+				),
839
+				'order_by' => array(
840
+					'required'          => false,
841
+					'default'           => $default_orderby,
842
+					'type'              => array(
843
+						'object',
844
+						'string',
845
+					),// because we accept a variety of types, WP core validation and sanitization
846
+					// freaks out. We'll just validate this argument while handling the request
847
+					'validate_callback' => null,
848
+					'sanitize_callback' => null,
849
+				),
850
+				'group_by' => array(
851
+					'required'          => false,
852
+					'default'           => null,
853
+					'type'              => array(
854
+						'object',
855
+						'string',
856
+					),
857
+					// because we accept  an almost infinite list of possible groupings,
858
+					// WP core validation and sanitization
859
+					// freaks out. We'll just validate this argument while handling the request
860
+					'validate_callback' => null,
861
+					'sanitize_callback' => null,
862
+				),
863
+				'having'   => array(
864
+					'required'          => false,
865
+					'default'           => null,
866
+					'type'              => 'object',
867
+					// because we accept an almost infinite list of possible where conditions, WP
868
+					// core validation and sanitization freaks out. We'll just validate this argument
869
+					// while handling the request
870
+					'validate_callback' => null,
871
+					'sanitize_callback' => null,
872
+				),
873
+				'caps'     => array(
874
+					'required' => false,
875
+					'default'  => EEM_Base::caps_read,
876
+					'type'     => 'string',
877
+					'enum'     => array(
878
+						EEM_Base::caps_read,
879
+						EEM_Base::caps_read_admin,
880
+						EEM_Base::caps_edit,
881
+						EEM_Base::caps_delete,
882
+					),
883
+				),
884
+			)
885
+		);
886
+	}
887
+
888
+
889
+	/**
890
+	 * Gets parameter information for a model regarding writing data
891
+	 *
892
+	 * @param string           $model_name
893
+	 * @param ModelVersionInfo $model_version_info
894
+	 * @param boolean          $create                                       whether this is for request to create (in
895
+	 *                                                                       which case we need all required params) or
896
+	 *                                                                       just to update (in which case we don't
897
+	 *                                                                       need those on every request)
898
+	 * @return array
899
+	 */
900
+	protected function _get_write_params(
901
+		$model_name,
902
+		ModelVersionInfo $model_version_info,
903
+		$create = false
904
+	) {
905
+		$model = EE_Registry::instance()->load_model($model_name);
906
+		$fields = $model_version_info->fieldsOnModelInThisVersion($model);
907
+		$args_info = array();
908
+		foreach ($fields as $field_name => $field_obj) {
909
+			if ($field_obj->is_auto_increment()) {
910
+				// totally ignore auto increment IDs
911
+				continue;
912
+			}
913
+			$arg_info = $field_obj->getSchema();
914
+			$required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
915
+			$arg_info['required'] = $required;
916
+			// remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
917
+			unset($arg_info['readonly']);
918
+			$schema_properties = $field_obj->getSchemaProperties();
919
+			if (
920
+				isset($schema_properties['raw'])
921
+				&& $field_obj->getSchemaType() === 'object'
922
+			) {
923
+				// if there's a "raw" form of this argument, use those properties instead
924
+				$arg_info = array_replace(
925
+					$arg_info,
926
+					$schema_properties['raw']
927
+				);
928
+			}
929
+			$arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
930
+				$field_obj,
931
+				$field_obj->get_default_value(),
932
+				$model_version_info->requestedVersion()
933
+			);
934
+			// we do our own validation and sanitization within the controller
935
+			if (function_exists('rest_validate_value_from_schema')) {
936
+				$sanitize_callback = array(
937
+					'EED_Core_Rest_Api',
938
+					'default_sanitize_callback',
939
+				);
940
+			} else {
941
+				$sanitize_callback = null;
942
+			}
943
+			$arg_info['sanitize_callback'] = $sanitize_callback;
944
+			$args_info[ $field_name ] = $arg_info;
945
+			if ($field_obj instanceof EE_Datetime_Field) {
946
+				$gmt_arg_info = $arg_info;
947
+				$gmt_arg_info['description'] = sprintf(
948
+					esc_html__(
949
+						'%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
950
+						'event_espresso'
951
+					),
952
+					$field_obj->get_nicename(),
953
+					$field_name
954
+				);
955
+				$args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
956
+			}
957
+		}
958
+		return $args_info;
959
+	}
960
+
961
+
962
+	/**
963
+	 * Replacement for WP API's 'rest_parse_request_arg'.
964
+	 * If the value is blank but not required, don't bother validating it.
965
+	 * Also, it uses our email validation instead of WP API's default.
966
+	 *
967
+	 * @param                 $value
968
+	 * @param WP_REST_Request $request
969
+	 * @param                 $param
970
+	 * @return bool|true|WP_Error
971
+	 * @throws InvalidArgumentException
972
+	 * @throws InvalidInterfaceException
973
+	 * @throws InvalidDataTypeException
974
+	 */
975
+	public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
976
+	{
977
+		$attributes = $request->get_attributes();
978
+		if (
979
+			! isset($attributes['args'][ $param ])
980
+			|| ! is_array($attributes['args'][ $param ])
981
+		) {
982
+			$validation_result = true;
983
+		} else {
984
+			$args = $attributes['args'][ $param ];
985
+			if (
986
+				(
987
+					$value === ''
988
+					|| $value === null
989
+				)
990
+				&& (! isset($args['required'])
991
+					|| $args['required'] === false
992
+				)
993
+			) {
994
+				// not required and not provided? that's cool
995
+				$validation_result = true;
996
+			} elseif (
997
+				isset($args['format'])
998
+					  && $args['format'] === 'email'
999
+			) {
1000
+				$validation_result = true;
1001
+				if (! self::_validate_email($value)) {
1002
+					$validation_result = new WP_Error(
1003
+						'rest_invalid_param',
1004
+						esc_html__(
1005
+							'The email address is not valid or does not exist.',
1006
+							'event_espresso'
1007
+						)
1008
+					);
1009
+				}
1010
+			} else {
1011
+				$validation_result = rest_validate_value_from_schema($value, $args, $param);
1012
+			}
1013
+		}
1014
+		if (is_wp_error($validation_result)) {
1015
+			return $validation_result;
1016
+		}
1017
+		return rest_sanitize_request_arg($value, $request, $param);
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
1023
+	 *
1024
+	 * @param $email
1025
+	 * @return bool
1026
+	 * @throws InvalidArgumentException
1027
+	 * @throws InvalidInterfaceException
1028
+	 * @throws InvalidDataTypeException
1029
+	 */
1030
+	protected static function _validate_email($email)
1031
+	{
1032
+		try {
1033
+			EmailAddressFactory::create($email);
1034
+			return true;
1035
+		} catch (EmailValidationException $e) {
1036
+			return false;
1037
+		}
1038
+	}
1039
+
1040
+
1041
+	/**
1042
+	 * Gets routes for the config
1043
+	 *
1044
+	 * @return array @see _register_model_routes
1045
+	 * @deprecated since version 4.9.1
1046
+	 */
1047
+	protected function _register_config_routes()
1048
+	{
1049
+		$config_routes = array();
1050
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
1051
+			$config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
1052
+				$version,
1053
+				$hidden_endpoint
1054
+			);
1055
+		}
1056
+		return $config_routes;
1057
+	}
1058
+
1059
+
1060
+	/**
1061
+	 * Gets routes for the config for the specified version
1062
+	 *
1063
+	 * @param string  $version
1064
+	 * @param boolean $hidden_endpoint
1065
+	 * @return array
1066
+	 */
1067
+	protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1068
+	{
1069
+		return array(
1070
+			'config'    => array(
1071
+				array(
1072
+					'callback'        => array(
1073
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1074
+						'handleRequest',
1075
+					),
1076
+					'methods'         => WP_REST_Server::READABLE,
1077
+					'hidden_endpoint' => $hidden_endpoint,
1078
+					'callback_args'   => array($version),
1079
+				),
1080
+			),
1081
+			'site_info' => array(
1082
+				array(
1083
+					'callback'        => array(
1084
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1085
+						'handleRequestSiteInfo',
1086
+					),
1087
+					'methods'         => WP_REST_Server::READABLE,
1088
+					'hidden_endpoint' => $hidden_endpoint,
1089
+					'callback_args'   => array($version),
1090
+				),
1091
+			),
1092
+		);
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * Gets the meta info routes
1098
+	 *
1099
+	 * @return array @see _register_model_routes
1100
+	 * @deprecated since version 4.9.1
1101
+	 */
1102
+	protected function _register_meta_routes()
1103
+	{
1104
+		$meta_routes = array();
1105
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
1106
+			$meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1107
+				$version,
1108
+				$hidden_endpoint
1109
+			);
1110
+		}
1111
+		return $meta_routes;
1112
+	}
1113
+
1114
+
1115
+	/**
1116
+	 * @param string  $version
1117
+	 * @param boolean $hidden_endpoint
1118
+	 * @return array
1119
+	 */
1120
+	protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1121
+	{
1122
+		return array(
1123
+			'resources' => array(
1124
+				array(
1125
+					'callback'        => array(
1126
+						'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1127
+						'handleRequestModelsMeta',
1128
+					),
1129
+					'methods'         => WP_REST_Server::READABLE,
1130
+					'hidden_endpoint' => $hidden_endpoint,
1131
+					'callback_args'   => array($version),
1132
+				),
1133
+			),
1134
+		);
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 * Tries to hide old 4.6 endpoints from the
1140
+	 *
1141
+	 * @param array $route_data
1142
+	 * @return array
1143
+	 * @throws \EE_Error
1144
+	 */
1145
+	public static function hide_old_endpoints($route_data)
1146
+	{
1147
+		// allow API clients to override which endpoints get hidden, in case
1148
+		// they want to discover particular endpoints
1149
+		// also, we don't have access to the request so we have to just grab it from the superglobal
1150
+		$force_show_ee_namespace = ltrim(
1151
+			EED_Core_Rest_Api::getRequest()->getRequestParam('force_show_ee_namespace'),
1152
+			'/'
1153
+		);
1154
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1155
+			foreach ($relative_urls as $resource_name => $endpoints) {
1156
+				foreach ($endpoints as $key => $endpoint) {
1157
+					// skip schema and other route options
1158
+					if (! is_numeric($key)) {
1159
+						continue;
1160
+					}
1161
+					// by default, hide "hidden_endpoint"s, unless the request indicates
1162
+					// to $force_show_ee_namespace, in which case only show that one
1163
+					// namespace's endpoints (and hide all others)
1164
+					if (
1165
+						($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1166
+						|| ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1167
+					) {
1168
+						$full_route = '/' . ltrim($namespace, '/');
1169
+						$full_route .= '/' . ltrim($resource_name, '/');
1170
+						unset($route_data[ $full_route ]);
1171
+					}
1172
+				}
1173
+			}
1174
+		}
1175
+		return $route_data;
1176
+	}
1177
+
1178
+
1179
+	/**
1180
+	 * Returns an array describing which versions of core support serving requests for.
1181
+	 * Keys are core versions' major and minor version, and values are the
1182
+	 * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1183
+	 * data by just removing a few models and fields from the responses. However, 4.15 might remove
1184
+	 * the answers table entirely, in which case it would be very difficult for
1185
+	 * it to serve 4.6-style responses.
1186
+	 * Versions of core that are missing from this array are unknowns.
1187
+	 * previous ver
1188
+	 *
1189
+	 * @return array
1190
+	 */
1191
+	public static function version_compatibilities()
1192
+	{
1193
+		return apply_filters(
1194
+			'FHEE__EED_Core_REST_API__version_compatibilities',
1195
+			array(
1196
+				'4.8.29' => '4.8.29',
1197
+				'4.8.33' => '4.8.29',
1198
+				'4.8.34' => '4.8.29',
1199
+				'4.8.36' => '4.8.29',
1200
+			)
1201
+		);
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 * Gets the latest API version served. Eg if there
1207
+	 * are two versions served of the API, 4.8.29 and 4.8.32, and
1208
+	 * we are on core version 4.8.34, it will return the string "4.8.32"
1209
+	 *
1210
+	 * @return string
1211
+	 */
1212
+	public static function latest_rest_api_version()
1213
+	{
1214
+		$versions_served = \EED_Core_Rest_Api::versions_served();
1215
+		$versions_served_keys = array_keys($versions_served);
1216
+		return end($versions_served_keys);
1217
+	}
1218
+
1219
+
1220
+	/**
1221
+	 * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1222
+	 * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1223
+	 * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1224
+	 * We also indicate whether or not this version should be put in the index or not
1225
+	 *
1226
+	 * @return array keys are API version numbers (just major and minor numbers), and values
1227
+	 * are whether or not they should be hidden
1228
+	 */
1229
+	public static function versions_served()
1230
+	{
1231
+		$versions_served = array();
1232
+		$possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1233
+		$lowest_compatible_version = end($possibly_served_versions);
1234
+		reset($possibly_served_versions);
1235
+		$versions_served_historically = array_keys($possibly_served_versions);
1236
+		$latest_version = end($versions_served_historically);
1237
+		reset($versions_served_historically);
1238
+		// for each version of core we have ever served:
1239
+		foreach ($versions_served_historically as $key_versioned_endpoint) {
1240
+			// if it's not above the current core version, and it's compatible with the current version of core
1241
+
1242
+			if ($key_versioned_endpoint === $latest_version) {
1243
+				// don't hide the latest version in the index
1244
+				$versions_served[ $key_versioned_endpoint ] = false;
1245
+			} elseif (
1246
+				version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=')
1247
+				&& version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<')
1248
+			) {
1249
+				// include, but hide, previous versions which are still supported
1250
+				$versions_served[ $key_versioned_endpoint ] = true;
1251
+			} elseif (
1252
+				apply_filters(
1253
+					'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1254
+					false,
1255
+					$possibly_served_versions
1256
+				)
1257
+			) {
1258
+				// if a version is no longer supported, don't include it in index or list of versions served
1259
+				$versions_served[ $key_versioned_endpoint ] = true;
1260
+			}
1261
+		}
1262
+		return $versions_served;
1263
+	}
1264
+
1265
+
1266
+	/**
1267
+	 * Gets the major and minor version of EE core's version string
1268
+	 *
1269
+	 * @return string
1270
+	 */
1271
+	public static function core_version()
1272
+	{
1273
+		return apply_filters(
1274
+			'FHEE__EED_Core_REST_API__core_version',
1275
+			implode(
1276
+				'.',
1277
+				array_slice(
1278
+					explode(
1279
+						'.',
1280
+						espresso_version()
1281
+					),
1282
+					0,
1283
+					3
1284
+				)
1285
+			)
1286
+		);
1287
+	}
1288
+
1289
+
1290
+	/**
1291
+	 * Gets the default limit that should be used when querying for resources
1292
+	 *
1293
+	 * @return int
1294
+	 */
1295
+	public static function get_default_query_limit()
1296
+	{
1297
+		// we actually don't use a const because we want folks to always use
1298
+		// this method, not the const directly
1299
+		return apply_filters(
1300
+			'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1301
+			50
1302
+		);
1303
+	}
1304
+
1305
+
1306
+	/**
1307
+	 *
1308
+	 * @param string $version api version string (i.e. '4.8.36')
1309
+	 * @return array
1310
+	 */
1311
+	public static function getCollectionRoutesIndexedByModelName($version = '')
1312
+	{
1313
+		$version = empty($version) ? self::latest_rest_api_version() : $version;
1314
+		$model_names = self::model_names_with_plural_routes($version);
1315
+		$collection_routes = array();
1316
+		foreach ($model_names as $model_name => $model_class_name) {
1317
+			$collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/'
1318
+															. EEH_Inflector::pluralize_and_lower($model_name);
1319
+		}
1320
+		return $collection_routes;
1321
+	}
1322
+
1323
+
1324
+	/**
1325
+	 * Returns an array of primary key names indexed by model names.
1326
+	 * @param string $version
1327
+	 * @return array
1328
+	 */
1329
+	public static function getPrimaryKeyNamesIndexedByModelName($version = '')
1330
+	{
1331
+		$version = empty($version) ? self::latest_rest_api_version() : $version;
1332
+		$model_names = self::model_names_with_plural_routes($version);
1333
+		$primary_key_items = array();
1334
+		foreach ($model_names as $model_name => $model_class_name) {
1335
+			$primary_keys = $model_class_name::instance()->get_combined_primary_key_fields();
1336
+			foreach ($primary_keys as $primary_key_name => $primary_key_field) {
1337
+				if (count($primary_keys) > 1) {
1338
+					$primary_key_items[ strtolower($model_name) ][] = $primary_key_name;
1339
+				} else {
1340
+					$primary_key_items[ strtolower($model_name) ] = $primary_key_name;
1341
+				}
1342
+			}
1343
+		}
1344
+		return $primary_key_items;
1345
+	}
1346
+
1347
+	/**
1348
+	 * Determines the EE REST API debug mode is activated, or not.
1349
+	 * @since 4.9.76.p
1350
+	 * @return bool
1351
+	 */
1352
+	public static function debugMode()
1353
+	{
1354
+		static $debug_mode = null; // could be class prop
1355
+		if ($debug_mode === null) {
1356
+			$debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE;
1357
+		}
1358
+		return $debug_mode;
1359
+	}
1360
+
1361
+
1362
+
1363
+	/**
1364
+	 *    run - initial module setup
1365
+	 *
1366
+	 * @access    public
1367
+	 * @param  WP $WP
1368
+	 * @return    void
1369
+	 */
1370
+	public function run($WP)
1371
+	{
1372
+	}
1373 1373
 }
Please login to merge, or discard this patch.