Failed Conditions
Push — develop ( 2f9887...05d10f )
by Remco
03:39
created

Settings::get_settings_fields()   F

Complexity

Conditions 11
Paths 1024

Size

Total Lines 313
Code Lines 211

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
cc 11
eloc 211
nc 1024
nop 1
dl 0
loc 313
ccs 0
cts 254
cp 0
crap 132
rs 2.52
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Ingenico;
4
5
/**
6
 * Title: Ingenico gateway settings
7
 * Description:
8
 * Copyright: 2005-2019 Pronamic
9
 * Company: Pronamic
10
 *
11
 * @author  Remco Tolsma
12
 * @version 2.0.2
13
 * @since   1.3.0
14
 */
15
class Settings {
16
	/**
17
	 * Fields.
18
	 *
19
	 * @param array $fields Settings fields.
20
	 *
21
	 * @return array
22
	 */
23
	public static function get_settings_fields( $type ) {
24
		$fields = array();
25
26
		/*
27
		 * General.
28
		 */
29
		$fields[] = array(
30
			'section' => 'general',
31
			'type'    => 'html',
32
			'html'    => __( 'Account details are provided by the payment provider after registration. These settings need to match with the payment provider dashboard.', 'pronamic_ideal' ),
33
		);
34
35
		// PSPID.
36
		$fields[] = array(
37
			'filter'   => FILTER_SANITIZE_STRING,
38
			'section'  => 'ogone',
39
			'meta_key' => '_pronamic_gateway_ogone_psp_id',
40
			'title'    => __( 'PSPID', 'pronamic_ideal' ),
41
			'type'     => 'text',
42
			'classes'  => array( 'code' ),
43
			'tooltip'  => __( 'PSPID as mentioned in the payment provider dashboard.', 'pronamic_ideal' ),
44
			'methods'  => array( 'ogone_orderstandard_easy', 'ogone_orderstandard', 'ogone_directlink' ),
45
		);
46
47
		if ( in_array( $type, array( 'standard', 'directlink' ), true ) ) {
48
			// API user ID.
49
			$fields[] = array(
50
				'filter'   => FILTER_SANITIZE_STRING,
51
				'section'  => 'ogone',
52
				'meta_key' => '_pronamic_gateway_ogone_user_id',
53
				'title'    => __( 'API user ID', 'pronamic_ideal' ),
54
				'type'     => 'text',
55
				'classes'  => array( 'regular-text', 'code' ),
56
				'methods'  => array( 'ogone_orderstandard', 'ogone_directlink' ),
57
				'tooltip'  => __( 'User ID of the API user in the payment provider dashboard: Configuration &raquo; Users', 'pronamic_ideal' ),
58
			);
59
60
			// API user password.
61
			$fields[] = array(
62
				'filter'   => FILTER_SANITIZE_STRING,
63
				'section'  => 'ogone',
64
				'meta_key' => '_pronamic_gateway_ogone_password',
65
				'title'    => __( 'API user password', 'pronamic_ideal' ),
66
				'type'     => 'password',
67
				'classes'  => array( 'regular-text', 'code' ),
68
				'methods'  => array( 'ogone_orderstandard', 'ogone_directlink' ),
69
				'tooltip'  => __( 'Password of the API user in the payment provider dashboard: Configuration &raquo; Users', 'pronamic_ideal' ),
70
			);
71
		}
72
73
		if ( 'standard' === $type ) {
74
			// SHA-IN Pass phrase.
75
			$fields[] = array(
76
				'filter'   => FILTER_SANITIZE_STRING,
77
				'section'  => 'ogone',
78
				'meta_key' => '_pronamic_gateway_ogone_sha_in_pass_phrase',
79
				'title'    => __( 'SHA-IN Pass phrase', 'pronamic_ideal' ),
80
				'type'     => 'password',
81
				'classes'  => array( 'regular-text', 'code' ),
82
				'tooltip'  => __( 'SHA-IN pass phrase as mentioned in the payment provider dashboard: Configuration &raquo; Technical information &raquo; Data and origin verification.', 'pronamic_ideal' ),
83
				'methods'  => array( 'ogone_orderstandard' ),
84
			);
85
		}
86
87
		if ( 'directlink' === $type ) {
88
			// SHA-IN Pass phrase.
89
			$fields[] = array(
90
				'filter'   => FILTER_SANITIZE_STRING,
91
				'section'  => 'ogone',
92
				'meta_key' => '_pronamic_gateway_ogone_directlink_sha_in_pass_phrase',
93
				'title'    => __( 'SHA-IN Pass phrase', 'pronamic_ideal' ),
94
				'type'     => 'password',
95
				'classes'  => array( 'regular-text', 'code' ),
96
				'tooltip'  => __( 'SHA-IN pass phrase as mentioned in the payment provider dashboard: Configuration &raquo; Technical information &raquo; Data and origin verification.', 'pronamic_ideal' ),
97
				'methods'  => array( 'ogone_directlink' ),
98
			);
99
		}
100
101
		if ( in_array( $type, array( 'standard', 'directlink' ), true ) ) {
102
			// SHA-OUT Pass phrase.
103
			$fields[] = array(
104
				'filter'   => FILTER_SANITIZE_STRING,
105
				'section'  => 'ogone',
106
				'meta_key' => '_pronamic_gateway_ogone_sha_out_pass_phrase',
107
				'title'    => __( 'SHA-OUT Pass phrase', 'pronamic_ideal' ),
108
				'type'     => 'password',
109
				'classes'  => array( 'regular-text', 'code' ),
110
				'tooltip'  => __( 'SHA-OUT pass phrase as mentioned in the payment provider dashboard: Configuration &raquo; Technical information &raquo; Transaction feedback.', 'pronamic_ideal' ),
111
				'methods'  => array( 'ogone_orderstandard', 'ogone_directlink' ),
112
			);
113
114
			// Hash algorithm.
115
			$fields[] = array(
116
				'filter'   => FILTER_SANITIZE_STRING,
117
				'section'  => 'ogone',
118
				'meta_key' => '_pronamic_gateway_ogone_hash_algorithm',
119
				'title'    => __( 'Hash algorithm', 'pronamic_ideal' ),
120
				'type'     => 'optgroup',
121
				'tooltip'  => 'Hash algorithm as mentioned in the payment provider dashboard: Configuration &raquo; Technical information',
122
				'options'  => array(
123
					Ingenico::SHA_1   => __( 'SHA-1', 'pronamic_ideal' ),
124
					Ingenico::SHA_256 => __( 'SHA-256', 'pronamic_ideal' ),
125
					Ingenico::SHA_512 => __( 'SHA-512', 'pronamic_ideal' ),
126
				),
127
				'default'  => Ingenico::SHA_1,
128
				'methods'  => array( 'ogone_orderstandard', 'ogone_directlink' ),
129
			);
130
		}
131
132
		if ( 'directlink' === $type ) {
133
			// 3-D Secure
134
			$fields[] = array(
135
				'filter'   => FILTER_VALIDATE_BOOLEAN,
136
				'section'  => 'ogone',
137
				'meta_key' => '_pronamic_gateway_ogone_3d_secure_enabled',
138
				'title'    => __( '3-D Secure', 'pronamic_ideal' ),
139
				'type'     => 'checkbox',
140
				'label'    => __( 'Enable 3-D Secure protocol', 'pronamic_ideal' ),
141
				'methods'  => array( 'ogone_directlink' ),
142
			);
143
		}
144
145
		if ( 'easy' === $type ) {
146
			// Transaction feedback fields.
147
			$fields[] = array(
148
				'section' => 'ogone',
149
				'title'   => __( 'Transaction feedback', 'pronamic_ideal' ),
150
				'type'    => 'description',
151
				'methods' => array( 'ogone_orderstandard_easy' ),
152
				'html'    => sprintf(
153
					'<span class="dashicons dashicons-no"></span> %s',
154
					__( 'Payment status updates are not supported by this payment provider.', 'pronamic_ideal' )
155
				),
156
			);
157
		}
158
159
		if ( in_array( $type, array( 'standard', 'directlink' ), true ) ) {
160
			$fields[] = array(
161
				'section'  => 'ogone',
162
				'title'    => __( 'Transaction feedback', 'pronamic_ideal' ),
163
				'type'     => 'description',
164
				'methods'  => array( 'ogone_orderstandard', 'ogone_directlink' ),
165
				'html'     => __( 'Receiving payment status updates needs additional configuration.', 'pronamic_ideal' ),
166
				'features' => array( 'webhook_manual_config' ),
167
			);
168
		}
169
170
		/*
171
		 * Advanced settings
172
		 */
173
174
		$fields[] = array(
175
			'section' => 'advanced',
176
			'type'    => 'html',
177
			'html'    => __( 'Optional settings for advanced usage only.', 'pronamic_ideal' ),
178
		);
179
180
		// Form Action URL.
181
		if ( in_array( $type, array( 'easy', 'standard' ), true ) ) {
182
			$fields[] = array(
183
				'filter'   => FILTER_SANITIZE_STRING,
184
				'section'  => 'ogone_advanced',
185
				'meta_key' => '_pronamic_gateway_ogone_form_action_url',
186
				'title'    => __( 'Form Action URL', 'pronamic_ideal' ),
187
				'type'     => 'text',
188
				'classes'  => array( 'regular-text', 'code' ),
189
				'tooltip'  => __( 'With this setting you can override the default Ogone e-Commerce form action URL to the payment processing page.', 'pronamic_ideal' ),
190
				'methods'  => array( 'ogone_orderstandard_easy', 'ogone_orderstandard' ),
191
			);
192
		}
193
194
		// Order ID.
195
		$fields[] = array(
196
			'filter'      => FILTER_SANITIZE_STRING,
197
			'section'     => 'ogone_advanced',
198
			'meta_key'    => '_pronamic_gateway_ogone_order_id',
199
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
200
			'type'        => 'text',
201
			'classes'     => array( 'regular-text', 'code' ),
202
			'tooltip'     => sprintf(
203
				/* translators: %s: <code>ORDERID</code> */
204
				__( 'The Ogone %s parameter.', 'pronamic_ideal' ),
205
				sprintf( '<code>%s</code>', 'ORDERID' )
206
			),
207
			'description' => sprintf(
208
				'%s<br />%s',
209
				sprintf(
210
					/* translators: %s: <code>{order_id}</code> <code>{payment_id}</code> */
211
					__( 'Available tags: %s', 'pronamic_ideal' ),
212
					sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' )
213
				),
214
				sprintf(
215
					/* translators: %s: {payment_id} */
216
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
217
					'{payment_id}'
218
				)
219
			),
220
			'methods'     => array( 'ogone_orderstandard_easy', 'ogone_orderstandard', 'ogone_directlink' ),
221
		);
222
223
		// Parameter Variable.
224
		$fields[] = array(
225
			'filter'      => FILTER_SANITIZE_STRING,
226
			'section'     => 'ogone_advanced',
227
			'meta_key'    => '_pronamic_gateway_ogone_param_var',
228
			'title'       => __( 'Parameter Variable', 'pronamic_ideal' ),
229
			'type'        => 'text',
230
			'classes'     => array( 'regular-text', 'code' ),
231
			'tooltip'     => sprintf(
232
				/* translators: %s: <code>PARAMVAR</code> */
233
				__( 'The Ogone %s parameter.', 'pronamic_ideal' ),
234
				sprintf( '<code>%s</code>', 'PARAMVAR' )
235
			),
236
			'description' => sprintf(
237
				/* translators: %s: <code>{site_url}</code> <code>{home_url}</code> */
238
				__( 'Available tags: %s', 'pronamic_ideal' ),
239
				sprintf( '<code>%s</code> <code>%s</code>', '{site_url}', '{home_url}' )
240
			),
241
			'methods'     => array( 'ogone_orderstandard', 'ogone_directlink' ),
242
		);
243
244
		if ( in_array( $type, array( 'standard', 'directlink' ), true ) ) {
245
			// Alias.
246
			$fields[] = array(
247
				'filter'   => FILTER_VALIDATE_BOOLEAN,
248
				'section'  => 'ogone_advanced',
249
				'meta_key' => '_pronamic_gateway_ogone_alias_enabled',
250
				'title'    => __( 'Alias', 'pronamic_ideal' ),
251
				'type'     => 'checkbox',
252
				'label'    => __( 'Enable alias registration', 'pronamic_ideal' ),
253
				'tooltip'  => __( 'Enable alias creation as reference for batch payments. Requires the Alias Manager option (`REQ1`) to be enabled for the Ingenico account.', 'pronamic_ideal' ),
254
				'methods'  => array( 'ogone_directlink', 'ogone_orderstandard' ),
255
			);
256
257
			// Alias usage.
258
			$fields[] = array(
259
				'filter'      => FILTER_SANITIZE_STRING,
260
				'section'     => 'ogone_advanced',
261
				'meta_key'    => '_pronamic_gateway_ogone_alias_usage',
262
				'title'       => __( 'Alias Usage', 'pronamic_ideal' ),
263
				'type'        => 'text',
264
				'classes'     => array( 'regular-text', 'code' ),
265
				'tooltip'     => sprintf(
266
					/* translators: %s: <code>ALIASUSAGE</code> */
267
					__( 'The Ogone %s parameter.', 'pronamic_ideal' ),
268
					sprintf( '<code>%s</code>', 'ALIASUSAGE' )
269
				),
270
				'description' => __( 'Description on payment page of how aliases are used.', 'pronamic_ideal' ),
271
				'methods'     => array( 'ogone_directlink', 'ogone_orderstandard' ),
272
			);
273
274
			// Template Page.
275
			$fields[] = array(
276
				'filter'   => FILTER_SANITIZE_STRING,
277
				'section'  => 'ogone_advanced',
278
				'meta_key' => '_pronamic_gateway_ogone_template_page',
279
				'title'    => __( 'Template Page', 'pronamic_ideal' ),
280
				'type'     => 'text',
281
				'classes'  => array( 'regular-text', 'code' ),
282
				'tooltip'  => sprintf(
283
					/* translators: %s: <code>TP</code> */
284
					__( 'The Ogone %s parameter.', 'pronamic_ideal' ),
285
					sprintf( '<code>%s</code>', 'TP' )
286
				),
287
				'methods'  => array( 'ogone_orderstandard', 'ogone_directlink' ),
288
			);
289
		}
290
291
		/*
292
		 * Transaction feedback - Direct HTTP server-to-server request URLs
293
		 */
294
		if ( in_array( $type, array( 'standard', 'directlink' ), true ) ) {
295
			$fields = array(
296
				'section' => 'feedback',
297
				'type'    => 'html',
298
				'html'    => __( 'The URLs below need to be copied to the payment provider dashboard to receive automatic transaction status updates.', 'pronamic_ideal' ),
299
			);
300
		}
301
302
		// URL accepted, on hold or uncertain.
303
		$fields[] = array(
304
			'section'  => 'ogone_feedback',
305
			'title'    => __( 'URL accepted, on hold or uncertain', 'pronamic_ideal' ),
306
			'type'     => 'text',
307
			'value'    => site_url( '/' ),
308
			'classes'  => array( 'regular-text', 'code' ),
309
			'tooltip'  => __( 'Direct HTTP server-to-server request URL for payment statuses accepted, on hold or uncertain".', 'pronamic_ideal' ),
310
			'readonly' => true,
311
		);
312
313
		// URL cancel or deny.
314
		$fields[] = array(
315
			'section'  => 'ogone_feedback',
316
			'title'    => __( 'URL cancel or deny', 'pronamic_ideal' ),
317
			'type'     => 'text',
318
			'value'    => site_url( '/' ),
319
			'classes'  => array( 'regular-text', 'code' ),
320
			'tooltip'  => __( 'Direct HTTP server-to-server request URL for payment statuses "cancelled by the client" or "too many rejections by the acquirer".', 'pronamic_ideal' ),
321
			'readonly' => true,
322
		);
323
324
		// Webhook status.
325
		$fields[] = array(
326
			'section'  => 'ogone_feedback',
327
			'methods'  => array( 'ogone_orderstandard_easy', 'ogone_orderstandard', 'ogone_directlink' ),
328
			'title'    => __( 'Status', 'pronamic_ideal' ),
329
			'type'     => 'description',
330
			'features' => array( 'webhook_manual_config' ),
331
			'callback' => array( $this, 'feedback_status' ),
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using $this inside a static method is generally not recommended and can lead to errors in newer PHP versions.
Loading history...
332
		);
333
334
		// Return fields.
335
		return $fields;
336
	}
337
}
338