Completed
Branch BUG-9623-config-log (1352ef)
by
unknown
446:14 queued 431:00
created

EE_PMT_Aim   B

Complexity

Total Complexity 17

Size/Duplication

Total Lines 254
Duplicated Lines 2.76 %

Coupling/Cohesion

Components 2
Dependencies 16

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 17
c 3
b 0
f 0
lcom 2
cbo 16
dl 7
loc 254
rs 8.4614

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A _setup_properties() 7 7 1
B generate_new_billing_form() 0 55 5
A apply_billing_form_debug_settings() 0 18 4
A generate_new_settings_form() 0 62 1
A billing_input_names() 0 17 1
A _get_billing_values_from_form() 0 10 2
A help_tabs_config() 0 8 1
A payment_information() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
if (!defined('EVENT_ESPRESSO_VERSION'))
4
	exit('No direct script access allowed');
5
6
/**
7
 * Event Espresso
8
 *
9
 * Event Registration and Management Plugin for WordPress
10
 *
11
 * @ package			Event Espresso
12
 * @ author			Seth Shoultes
13
 * @ copyright		(c) 2008-2011 Event Espresso  All Rights Reserved.
14
 * @ license			http://eventespresso.com/support/terms-conditions/   * see Plugin Licensing *
15
 * @ link					http://www.eventespresso.com
16
 * @ version		 	4.3
17
 *
18
 * ------------------------------------------------------------------------
19
 *
20
 * EE_PMT_Aim
21
 *
22
 * @package			Event Espresso
23
 * @subpackage
24
 * @author				Mike Nelson
25
 *
26
 * ------------------------------------------------------------------------
27
 */
28
class EE_PMT_Aim extends EE_PMT_Base{
29
30
	
31
	/**
32
	 *
33
	 * @param EE_Payment_Method $pm_instance
34
	 * @return EE_PMT_Aim
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
35
	 */
36
	public function __construct($pm_instance = NULL) {
37
		$this->_setup_properties();
38
		parent::__construct($pm_instance);
39
	}
40
	
41
	/**
42
	 * Sets up payment method type properties for this gateway, which is normally
43
	 * done in the constructor, but we want this to be easy for similar gateways to override
44
	 * while still calling the parent constructor.
45
	 * So children should override this method instead of __construct
46
	 */
47 View Code Duplication
	protected function _setup_properties() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
		require_once($this->file_folder().'EEG_Aim.gateway.php');
49
		$this->_gateway = new EEG_AIM();
50
		$this->_pretty_name = __("Authorize.net AIM", 'event_espresso');
51
		$this->_default_description = __( 'Please provide the following billing information.', 'event_espresso' );
52
		$this->_requires_https = true;
53
	}
54
55
	/**
56
	 * Creates the billing form for this payment method type
57
	 * @param \EE_Transaction $transaction
58
	 * @return EE_Billing_Info_Form
59
	 */
60
	public function generate_new_billing_form( EE_Transaction $transaction = NULL ) {
61
		$billing_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance,array(
62
			'name'=>'AIM_Form',
63
			'subsections'=>array(
64
				'credit_card'=>new EE_Credit_Card_Input(array(
65
					'required'=>true,
66
					'html_label_text' => __( 'Card Number', 'event_espresso' )
67
				)),
68
				'exp_month'=>new EE_Credit_Card_Month_Input(true, array(
69
					'required'=>true,
70
					'html_label_text' => __( 'Expiry Month', 'event_espresso' )
71
				)),
72
				'exp_year'=>new EE_Credit_Card_Year_Input( array( 
73
					'required'=>true,
74
					'html_label_text' => __( 'Expiry Year', 'event_espresso' ) 
75
				)),
76
				'cvv'=>new EE_CVV_Input( array(
77
					'required'=>true,
78
					'html_label_text' => __( 'CVV', 'event_espresso' ) ) ),
79
			)
80
		));
81
		$billing_form->add_subsections( array(
82
			'company' => new EE_Text_Input( array(
83
				'html_label_text' => __('Company', 'event_espresso')
84
			))
85
		), 'email', false );
86
		$billing_form->add_subsections( 
87
				array(
88
					'fax' => new EE_Text_Input( array(
89
						'html_label_text' => __('Fax', 'event_espresso')
90
					))
91
				), 
92
				'phone', 
93
				false );
94
		$settings_form = $this->settings_form();
95
		if( $settings_form->get_input( 'excluded_billing_inputs' ) instanceof EE_Checkbox_Multi_Input ) {
96
				$billing_form->exclude( $settings_form->get_input( 'excluded_billing_inputs' )->normalized_value() );
97
		}
98
		if( $settings_form->get_input( 'required_billing_inputs' ) instanceof EE_Checkbox_Multi_Input ) {
99
			$required_inputs = $settings_form->get_input( 'required_billing_inputs' )->normalized_value();
100
			//only change the requirement of inputs which are allowed to be changed
101
			$inputs_to_evaluate = array_intersect_key( 
102
				$billing_form->inputs(), 
103
				$this->billing_input_names()
104
			);
105
			foreach( $inputs_to_evaluate as $input_name => $input ) {
106
				if( in_array( $input_name, $required_inputs ) ) {
107
					$input->set_required( true );
108
				} else {
109
					$input->set_required( false );
110
				}
111
			}
112
		}
113
		return $this->apply_billing_form_debug_settings( $billing_form );
114
	}
115
116
117
118
	/**
119
	 * apply_billing_form_debug_settings
120
	 * applies debug data to the form
121
	 *
122
	 * @param \EE_Billing_Info_Form $billing_form
123
	 * @return \EE_Billing_Info_Form
124
	 */
125
	public function apply_billing_form_debug_settings( EE_Billing_Info_Form $billing_form ) {
126
		if ( $this->_pm_instance->debug_mode() || $this->_pm_instance->get_extra_meta( 'test_transactions', TRUE, FALSE )) {
127
			$billing_form->get_input( 'credit_card' )->set_default( '4007000000027' );
128
			$billing_form->get_input( 'exp_year' )->set_default( '2020' );
129
			if( $billing_form->get_subsection( 'cvv' ) instanceof EE_Form_Input_Base ) {
130
				$billing_form->get_input( 'cvv' )->set_default(( '123' ));
131
			}
132
			$billing_form->add_subsections(
133
				array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ),
134
				'credit_card'
135
			);
136
			$billing_form->add_subsections(
137
				array( 'debug_content' => new EE_Form_Section_HTML_From_Template( dirname(__FILE__).DS.'templates'.DS.'authorize_net_aim_debug_info.template.php' )),
138
				'first_name'
139
			);
140
		}
141
		return $billing_form;
142
	}
143
144
145
146
	/**
147
	 * Gets the form for all the settings related to this payment method type
148
	 * @return EE_Payment_Method_Form
149
	 */
150
	public function generate_new_settings_form() {
151
		$billing_input_names = $this->billing_input_names();
152
		return new EE_Payment_Method_Form(
153
			array(
154
				'extra_meta_inputs'=>array(
155
					'login_id'=>new EE_Text_Input(
156
						array(
157
							'html_label_text'=>  sprintf( __("Authorize.net API Login ID %s", "event_espresso"),  $this->get_help_tab_link() ),
158
							'required' => true )
159
					),
160
					'transaction_key'=>new EE_Text_Input(
161
						array(
162
							'html_label_text'=> sprintf( __("Authorize.net Transaction Key %s", "event_espresso"), $this->get_help_tab_link() ),
163
							'required' => true )
164
					),
165
					'test_transactions'=>new EE_Yes_No_Input(
166
						array(
167
							'html_label_text'=>  sprintf( __("Send test transactions? %s", 'event_espresso'),  $this->get_help_tab_link() ),
168
							'html_help_text'=>  __("Send test transactions, even to live server", 'event_espresso'),
169
							'default' => false,
170
							'required' => true
171
						)
172
					),
173
					'excluded_billing_inputs' => new EE_Checkbox_Multi_Input( 
174
							$billing_input_names,
175
					array( 
176
						'html_label_text' => sprintf( __("Excluded Payment Form Fields %s", 'event_espresso'),  $this->get_help_tab_link() ),
177
						'default' => array(
178
							'company',
179
							'fax',
180
						)
181
					)),
182
					'required_billing_inputs' => new EE_Checkbox_Multi_Input( 
183
						$billing_input_names,
184
						array(
185
							'html_label_text' => sprintf( __("Required Payment Form Fields %s", 'event_espresso'),  $this->get_help_tab_link() ),
186
							'default' => array_diff(
187
										array_keys( $billing_input_names ),
188
										array( 'address2', 'phone', 'company', 'fax' )
189
							),
190
							'html_help_text' => __('Note: if fields are excluded they cannot be required.', 'event_espresso')
191
						)
192
					),
193
					'server' => new EE_Select_Input(
194
						apply_filters(
195
							'FHEE__EE_PMT_Aim__generate_new_settings_form__server_select_input__options',
196
							array(
197
								'authorize.net' => __( 'Authorize.net (default)', 'event_espresso' ),
198
								'akamai' => __( 'Authorize.net/Akamai', 'event_espresso' )
199
							),
200
							$this
201
						),
202
						array(
203
							'html_label_text' => __( 'Server', 'event_espresso' ),
204
							'html_help_text' => __( 'The Gateway Server where payment requests will be sent', 'event_espresso' )
205
						)
206
					)
207
						
208
				)
209
			)
210
		);
211
	}
212
	
213
	/**
214
	 * Returns an array where keys are the slugs for billing inputs, and values
215
	 * are their i18n names
216
	 * @return array
217
	 */
218
	public function billing_input_names() {
219
		return array(
220
			'first_name' => __( 'First Name', 'event_espresso' ),
221
			'last_name' => __('Last Name', 'event_espresso'),
222
			'email' => __( 'Email', 'event_espresso' ),
223
			'company' => __( 'Company', 'event_espresso' ),
224
			'address' => __('Address', 'event_espresso'),
225
			'address2' => __('Address2', 'event_espresso'),
226
			'city' => __('City', 'event_espresso'),
227
			'state' => __('State', 'event_espresso'),
228
			'country' => __('Country', 'event_espresso'),
229
			'zip' =>  __('Zip', 'event_espresso'),
230
			'phone' => __('Phone', 'event_espresso'),
231
			'fax' => __( 'Fax', 'event_espresso' ),
232
			'cvv' => __('CVV', 'event_espresso')
233
		);
234
	}
235
	
236
	/**
237
	 * Overrides parent so we always have all billing inputs in the returned array,
238
	 * not just the ones included at the time. This helps simplify the gateway code
239
	 * @param type $billing_form
240
	 * @return array
241
	 */
242
	protected function _get_billing_values_from_form( $billing_form ){
243
		$all_billing_values_empty = array();
244
		foreach( array_keys( $this->billing_input_names() ) as $input_name ) {
245
			$all_billing_values_empty[ $input_name ] = '';
246
		}
247
		return array_merge(
248
				$all_billing_values_empty,
249
				parent::_get_billing_values_from_form($billing_form) );
250
		
251
	}
252
253
254
255
	/**
256
	 * Adds the help tab
257
	 * @see EE_PMT_Base::help_tabs_config()
258
	 * @return array
259
	 */
260
	public function help_tabs_config(){
261
		return array(
262
			$this->get_help_tab_name() => array(
263
				'title' => __('Authorize.net AIM Settings', 'event_espresso'),
264
				'filename' => 'payment_methods_overview_aim'
265
			),
266
		);
267
	}
268
269
270
271
	/**
272
	 * Gets a list of instructions and/or information regarding how the payment is to be completed
273
	 * @return string
274
	 */
275
	public function payment_information() {
276
		// TODO: Implement payment_information() method.
277
	}
278
279
280
281
}
282
// End of file EE_PMT_Aim.pm.php
283