Completed
Branch FET-9046-messages-queue (ac2959)
by
unknown
635:08 queued 618:09
created
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 */
36 36
 	public static function instance() {
37 37
 		// check if class object is instantiated, and instantiated properly
38
-		if ( ! self::$_instance instanceof EE_Payment_Method_Manager ) {
38
+		if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
39 39
 			self::$_instance = new self();
40 40
 		}
41 41
 		EE_Registry::instance()->load_lib('PMT_Base');
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 * Resets the instance and returns a new one
47 47
 	 * @return EE_Payment_Method_Manager
48 48
 	 */
49
-	public static function reset(){
49
+	public static function reset() {
50 50
 		self::$_instance = NULL;
51 51
 		return self::instance();
52 52
 	}
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 	 * or just re-use the PMTs we found last time we checked during this request (if
58 58
 	 * we have not yet checked during this request, then we need to check anyways)
59 59
 	 */
60
-	public function maybe_register_payment_methods( $force_recheck = FALSE ){
61
-		if( ! $this->_payment_method_types || $force_recheck ){
60
+	public function maybe_register_payment_methods($force_recheck = FALSE) {
61
+		if ( ! $this->_payment_method_types || $force_recheck) {
62 62
 			$this->_register_payment_methods();
63 63
 			//if in admin lets ensure caps are set.
64
-			if ( is_admin() ) {
65
-				add_filter( 'FHEE__EE_Capabilities__init_caps_map__caps', array( $this, 'add_payment_method_caps' ) );
64
+			if (is_admin()) {
65
+				add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
66 66
 				EE_Registry::instance()->CAP->init_caps();
67 67
 			}
68 68
 		}
@@ -75,19 +75,19 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	protected function _register_payment_methods() {
77 77
 		// grab list of installed modules
78
-		$pm_to_register = glob( EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR );
78
+		$pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR);
79 79
 		// filter list of modules to register
80
-		$pm_to_register = apply_filters( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', $pm_to_register );
80
+		$pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', $pm_to_register);
81 81
 
82 82
 		// loop through folders
83
-		foreach ( $pm_to_register as $pm_path ) {
84
-				$this->register_payment_method( $pm_path );
83
+		foreach ($pm_to_register as $pm_path) {
84
+				$this->register_payment_method($pm_path);
85 85
 		}
86
-		do_action( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods' );
86
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
87 87
 		// filter list of installed modules
88 88
 		//keep them organized alphabetically by the payment method type's name
89
-		ksort( $this->_payment_method_types );
90
-		return apply_filters( 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', $this->_payment_method_types );
89
+		ksort($this->_payment_method_types);
90
+		return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', $this->_payment_method_types);
91 91
 	}
92 92
 
93 93
 
@@ -99,35 +99,35 @@  discard block
 block discarded – undo
99 99
 	 * @param string $payment_method_path - full path up to and including payment method folder
100 100
 	 * @return boolean
101 101
 	 */
102
-	public function register_payment_method( $payment_method_path = '' ) {
103
-		do_action( 'AHEE__EE_Payment_Method_Manager__register_payment_method__begin',$payment_method_path );
102
+	public function register_payment_method($payment_method_path = '') {
103
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
104 104
 		$module_ext = '.pm.php';
105 105
 		// make all separators match
106
-		$payment_method_path = rtrim( str_replace( '/\\', DS, $payment_method_path ), DS );
106
+		$payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
107 107
 		// grab and sanitize module name
108
-		$module_dir = basename( $payment_method_path );
108
+		$module_dir = basename($payment_method_path);
109 109
 		// create classname from module directory name
110
-		$module = str_replace( ' ', '_', str_replace( '_', ' ', $module_dir ));
110
+		$module = str_replace(' ', '_', str_replace('_', ' ', $module_dir));
111 111
 		// add class prefix
112
-		$module_class = 'EE_PMT_' . $module;
112
+		$module_class = 'EE_PMT_'.$module;
113 113
 		// does the module exist ?
114
-		if ( ! is_readable( $payment_method_path . DS . $module_class . $module_ext )) {
115
-			$msg = sprintf( __( 'The requested %s payment method file could not be found or is not readable due to file permissions.', 'event_espresso' ), $module );
116
-			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
114
+		if ( ! is_readable($payment_method_path.DS.$module_class.$module_ext)) {
115
+			$msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', 'event_espresso'), $module);
116
+			EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
117 117
 			return FALSE;
118 118
 		}
119
-		if ( WP_DEBUG === TRUE ) { EEH_Debug_Tools::instance()->start_timer(); }
119
+		if (WP_DEBUG === TRUE) { EEH_Debug_Tools::instance()->start_timer(); }
120 120
 		// load the module class file
121
-		require_once( $payment_method_path . DS . $module_class . $module_ext );
122
-		if ( WP_DEBUG === TRUE ) { EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); }
121
+		require_once($payment_method_path.DS.$module_class.$module_ext);
122
+		if (WP_DEBUG === TRUE) { EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); }
123 123
 		// verify that class exists
124
-		if ( ! class_exists( $module_class )) {
125
-			$msg = sprintf( __( 'The requested %s module class does not exist.', 'event_espresso' ), $module_class );
126
-			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
124
+		if ( ! class_exists($module_class)) {
125
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
126
+			EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
127 127
 			return FALSE;
128 128
 		}
129 129
 		// add to array of registered modules
130
-		$this->_payment_method_types[ $module ] = $payment_method_path . DS . $module_class . $module_ext;
130
+		$this->_payment_method_types[$module] = $payment_method_path.DS.$module_class.$module_ext;
131 131
 		return TRUE;
132 132
 	}
133 133
 	/**
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 	 * @param boolean $force_recheck whether to force re-checking for new payment method types
137 137
 	 * @return boolean
138 138
 	 */
139
-	public function payment_method_type_exists($payment_method_name, $force_recheck = FALSE){
140
-		if ( ! is_array( $this->_payment_method_types ) || ! isset( $this->_payment_method_types[$payment_method_name] )
141
-				|| $force_recheck ) {
139
+	public function payment_method_type_exists($payment_method_name, $force_recheck = FALSE) {
140
+		if ( ! is_array($this->_payment_method_types) || ! isset($this->_payment_method_types[$payment_method_name])
141
+				|| $force_recheck) {
142 142
 			$this->maybe_register_payment_methods($force_recheck);
143 143
 		}
144
-		if(isset($this->_payment_method_types[$payment_method_name])){
144
+		if (isset($this->_payment_method_types[$payment_method_name])) {
145 145
 			require_once($this->_payment_method_types[$payment_method_name]);
146 146
 			return true;
147
-		}else{
147
+		} else {
148 148
 			return false;
149 149
 		}
150 150
 	}
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 	 * @param boolean $force_recheck whether to force re-checking for new payment method types
156 156
 	 * @return array
157 157
 	 */
158
-	public function payment_method_type_names($with_prefixes = FALSE, $force_recheck = FALSE ){
158
+	public function payment_method_type_names($with_prefixes = FALSE, $force_recheck = FALSE) {
159 159
 		$this->maybe_register_payment_methods($force_recheck);
160
-		if($with_prefixes){
160
+		if ($with_prefixes) {
161 161
 			$classnames = array_keys($this->_payment_method_types);
162 162
 			$payment_methods = array();
163
-			foreach($classnames as $classname){
163
+			foreach ($classnames as $classname) {
164 164
 				$payment_methods[] = $this->payment_method_class_from_type($classname);
165 165
 			}
166 166
 			return $payment_methods;
167
-		}else{
167
+		} else {
168 168
 			return array_keys($this->_payment_method_types);
169 169
 		}
170 170
 	}
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 	 * @param boolean $force_recheck whether to force re-checking for new payment method types
175 175
 	 * @return EE_PMT_Base[]
176 176
 	 */
177
-	public function payment_method_types( $force_recheck = FALSE ){
177
+	public function payment_method_types($force_recheck = FALSE) {
178 178
 		$this->maybe_register_payment_methods($force_recheck);
179 179
 		$pmt_objs = array();
180
-		foreach($this->payment_method_type_names(true) as $classname){
180
+		foreach ($this->payment_method_type_names(true) as $classname) {
181 181
 			$pmt_objs[] = new $classname;
182 182
 		}
183 183
 		return $pmt_objs;
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 	 * @param string $classname
190 190
 	 * @return string
191 191
 	 */
192
-	public function payment_method_type_sans_class_prefix($classname){
193
-		$pmt_name = str_replace("EE_PMT_","",$classname);
192
+	public function payment_method_type_sans_class_prefix($classname) {
193
+		$pmt_name = str_replace("EE_PMT_", "", $classname);
194 194
 		return $pmt_name;
195 195
 	}
196 196
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 * @param string $type
200 200
 	 * @return string
201 201
 	 */
202
-	public function payment_method_class_from_type($type){
202
+	public function payment_method_class_from_type($type) {
203 203
 		$this->maybe_register_payment_methods();
204 204
 		return "EE_PMT_".$type;
205 205
 	}
@@ -213,39 +213,39 @@  discard block
 block discarded – undo
213 213
 	 * @return \EE_Payment_Method
214 214
 	 * @throws \EE_Error
215 215
 	 */
216
-	public function activate_a_payment_method_of_type( $payment_method_type ){
216
+	public function activate_a_payment_method_of_type($payment_method_type) {
217 217
 		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
218
-		if( ! $payment_method instanceof EE_Payment_Method ){
218
+		if ( ! $payment_method instanceof EE_Payment_Method) {
219 219
 			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
220
-			if(class_exists($pm_type_class)){
220
+			if (class_exists($pm_type_class)) {
221 221
 				/** @var $pm_type_obj EE_PMT_Base */
222 222
 				$pm_type_obj = new $pm_type_class;
223 223
 				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
224
-				if( ! $payment_method){
225
-					$payment_method = $this->create_payment_method_of_type( $pm_type_obj );
224
+				if ( ! $payment_method) {
225
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
226 226
 				}
227
-				$payment_method->set_type( $payment_method_type );
228
-				$this->initialize_payment_method( $payment_method );
227
+				$payment_method->set_type($payment_method_type);
228
+				$this->initialize_payment_method($payment_method);
229 229
 			} else {
230 230
 				throw new EE_Error(
231 231
 					sprintf(
232
-						__( 'There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
232
+						__('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'),
233 233
 						$pm_type_class )
234 234
 				);
235 235
 			}
236 236
 		}
237 237
 		$payment_method->set_active();
238 238
 		$payment_method->save();
239
-		$this->set_usable_currencies_on_payment_method( $payment_method );
240
-		if( $payment_method->type() == 'Invoice' ){
239
+		$this->set_usable_currencies_on_payment_method($payment_method);
240
+		if ($payment_method->type() == 'Invoice') {
241 241
 			/** @type EE_Messages $messages_controller */
242
-			$messages_controller = EE_Registry::instance()->load_lib( 'messages' );
243
-			$messages_controller->ensure_message_type_is_active( 'invoice', 'html' );
244
-			$messages_controller->ensure_messenger_is_active( 'pdf' );
242
+			$messages_controller = EE_Registry::instance()->load_lib('messages');
243
+			$messages_controller->ensure_message_type_is_active('invoice', 'html');
244
+			$messages_controller->ensure_messenger_is_active('pdf');
245 245
 			EE_Error::add_attention(
246 246
 				sprintf(
247
-					__( 'Note, when the invoice payment method is activated, the invoice message type, html messenger, and pdf messenger are activated as well for the %1$smessages system%2$s.', 'event_espresso' ),
248
-					'<a href="' . admin_url( 'admin.php?page=espresso_messages') . '">',
247
+					__('Note, when the invoice payment method is activated, the invoice message type, html messenger, and pdf messenger are activated as well for the %1$smessages system%2$s.', 'event_espresso'),
248
+					'<a href="'.admin_url('admin.php?page=espresso_messages').'">',
249 249
 					'</a>'
250 250
 				)
251 251
 			);
@@ -259,17 +259,17 @@  discard block
 block discarded – undo
259 259
 	 * @param EE_PMT_Base $pm_type_obj
260 260
 	 * @return EE_Payment_Method
261 261
 	 */
262
-	public function create_payment_method_of_type( $pm_type_obj ) {
262
+	public function create_payment_method_of_type($pm_type_obj) {
263 263
 		global $current_user;
264 264
 		$payment_method = EE_Payment_Method::new_instance(
265 265
 			array(
266 266
 				'PMD_type' 		 => $pm_type_obj->system_name(),
267 267
 				'PMD_name' 		 => $pm_type_obj->pretty_name(),
268 268
 				'PMD_admin_name' => $pm_type_obj->pretty_name(),
269
-				'PMD_slug' 		 => $pm_type_obj->system_name(),//automatically converted to slug
269
+				'PMD_slug' 		 => $pm_type_obj->system_name(), //automatically converted to slug
270 270
 				'PMD_wp_user' 	 => $current_user->ID,
271 271
 				'PMD_order' 	 => EEM_Payment_Method::instance()->count(
272
-					array( array( 'PMD_type' => array( '!=', 'Admin_Only' )))
272
+					array(array('PMD_type' => array('!=', 'Admin_Only')))
273 273
 				) * 10,
274 274
 			)
275 275
 		);
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 	 * @param EE_Payment_Method $payment_method
282 282
 	 * @return EE_Payment_Method
283 283
 	 */
284
-	public function initialize_payment_method( $payment_method ) {
284
+	public function initialize_payment_method($payment_method) {
285 285
 		$pm_type_obj = $payment_method->type_obj();
286
-		$payment_method->set_description( $pm_type_obj->default_description() );
287
-		if( ! $payment_method->button_url() ){
288
-			$payment_method->set_button_url( $pm_type_obj->default_button_url() );
286
+		$payment_method->set_description($pm_type_obj->default_description());
287
+		if ( ! $payment_method->button_url()) {
288
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
289 289
 		}
290 290
 		//now add setup its default extra meta properties
291 291
 		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
292
-		foreach( $extra_metas as $meta_name => $input ){
293
-			$payment_method->update_extra_meta($meta_name, $input->raw_value() );
292
+		foreach ($extra_metas as $meta_name => $input) {
293
+			$payment_method->update_extra_meta($meta_name, $input->raw_value());
294 294
 		}
295 295
 		return $payment_method;
296 296
 	}
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	 * @param EE_Payment_Method $payment_method
301 301
 	 * @return EE_Payment_Method
302 302
 	 */
303
-	public function set_usable_currencies_on_payment_method( $payment_method ) {
304
-		foreach($payment_method->get_all_usable_currencies() as $currency_obj){
303
+	public function set_usable_currencies_on_payment_method($payment_method) {
304
+		foreach ($payment_method->get_all_usable_currencies() as $currency_obj) {
305 305
 			$payment_method->_add_relation_to($currency_obj, 'Currency');
306 306
 		}
307 307
 		return $payment_method;
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
 	 *
320 320
 	 * @return int count of rows updated.
321 321
 	 */
322
-	public function deactivate_payment_method( $payment_method_slug ) {
323
-		$count_updated = EEM_Payment_Method::instance()->update(array('PMD_scope'=>array()),array(array('PMD_slug'=>$payment_method_slug)));
322
+	public function deactivate_payment_method($payment_method_slug) {
323
+		$count_updated = EEM_Payment_Method::instance()->update(array('PMD_scope'=>array()), array(array('PMD_slug'=>$payment_method_slug)));
324 324
 		return $count_updated;
325 325
 	}
326 326
 
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @param array $caps capabilities being filtered
334 334
 	 * @return array
335 335
 	 */
336
-	public function add_payment_method_caps( $caps ) {
336
+	public function add_payment_method_caps($caps) {
337 337
 		/* add dynamic caps from payment methods
338 338
 		 * at the time of writing, october 20 2014, these are the caps added:
339 339
 		 * ee_payment_method_admin_only
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 		 * their related capability automatically added too, so long as they are
349 349
 		 * registered properly using EE_Register_Payment_Method::register()
350 350
 		 */
351
-		foreach( $this->payment_method_types() as $payment_method_type_obj ){
351
+		foreach ($this->payment_method_types() as $payment_method_type_obj) {
352 352
 			$caps['administrator'][] = $payment_method_type_obj->cap_name();
353 353
 		}
354 354
 		return $caps;
Please login to merge, or discard this patch.