Completed
Push — issues/611 ( 661115...758b1c )
by Ravinder
21:11
created

Give_Settings_Gateways::get_sections()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 13.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Give Settings Page/Tab
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Settings_Gateways
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
 * @since       1.8
10
 */
11
12
if ( ! defined( 'ABSPATH' ) ) {
13
	exit; // Exit if accessed directly
14
}
15
16
if ( ! class_exists( 'Give_Settings_Gateways' ) ) :
17
18
	/**
19
	 * Give_Settings_Gateways.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Settings_Gateways extends Give_Settings_Page {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Give_Settings_Gateways has been defined more than once; this definition is ignored, only the first definition in includes/admin/reporting...s-settings-gateways.php (L23-137) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
24
25
		/**
26
		 * Constructor.
27
		 */
28
		public function __construct() {
29
			$this->id    = 'gateways';
30
			$this->label = esc_html__( 'Payment Gateways', 'give' );
31
32
			$this->default_tab = 'gateways-settings';
0 ignored issues
show
Bug introduced by
The property default_tab does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
34
			parent::__construct();
35
		}
36
37
		/**
38
		 * Get settings array.
39
		 *
40
		 * @since  1.8
41
		 * @return array
42
		 */
43
		public function get_settings() {
44
			$settings        = array();
45
			$current_section = give_get_current_setting_section();
46
47
			switch ( $current_section ) {
48
				case 'paypal-standard':
49
					$settings = array(
50
						// Section 2: PayPal Standard.
51
						array(
52
							'type' => 'title',
53
							'id'   => 'give_title_gateway_settings_2',
54
						),
55
						array(
56
							'name' => __( 'PayPal Email', 'give' ),
57
							'desc' => __( 'Enter your PayPal account\'s email.', 'give' ),
58
							'id'   => 'paypal_email',
59
							'type' => 'email',
60
						),
61
						array(
62
							'name' => __( 'PayPal Page Style', 'give' ),
63
							'desc' => __( 'Enter the name of the PayPal page style to use, or leave blank to use the default.', 'give' ),
64
							'id'   => 'paypal_page_style',
65
							'type' => 'text',
66
						),
67
						array(
68
							'name'    => __( 'PayPal Transaction Type', 'give' ),
69
							'desc'    => __( 'Nonprofits must verify their status to withdraw donations they receive via PayPal. PayPal users that are not verified nonprofits must demonstrate how their donations will be used, once they raise more than $10,000. By default, Give transactions are sent to PayPal as donations. You may change the transaction type using this option if you feel you may not meet PayPal\'s donation requirements.', 'give' ),
70
							'id'      => 'paypal_button_type',
71
							'type'    => 'radio_inline',
72
							'options' => array(
73
								'donation' => __( 'Donation', 'give' ),
74
								'standard' => __( 'Standard Transaction', 'give' )
75
							),
76
							'default' => 'donation',
77
						),
78
						array(
79
							'name'    => __( 'Billing Details', 'give' ),
80
							'desc'    => __( 'This option will enable the billing details section for PayPal Standard which requires the donor\'s address to complete the donation. These fields are not required by PayPal to process the transaction, but you may have a need to collect the data.', 'give' ),
81
							'id'      => 'paypal_standard_billing_details',
82
							'type'    => 'radio_inline',
83
							'default' => 'disabled',
84
							'options' => array(
85
								'enabled'  => __( 'Enabled', 'give' ),
86
								'disabled' => __( 'Disabled', 'give' ),
87
							)
88
						),
89
						array(
90
							'name'    => __( 'PayPal IPN Verification', 'give' ),
91
							'desc'    => __( 'If donations are not getting marked as complete, use a slightly less secure method of verifying donations.', 'give' ),
92
							'id'      => 'paypal_verification',
93
							'type'    => 'radio_inline',
94
							'default' => 'enabled',
95
							'options' => array(
96
								'enabled'  => __( 'Enabled', 'give' ),
97
								'disabled' => __( 'Disabled', 'give' ),
98
							)
99
						),
100
                        array(
101
                            'name'  => __( 'PayPal Standard Gateway Settings Docs Link', 'give' ),
102
                            'id'    => 'paypal_standard_gateway_settings_docs_link',
103
                            'url'   => esc_url( 'http://docs.givewp.com/settings-gateway-paypal-standard' ),
104
                            'title' => __( 'PayPal Standard Gateway Settings', 'give' ),
105
                            'type'  => 'give_docs_link',
106
                        ),
107
						array(
108
							'type' => 'sectionend',
109
							'id'   => 'give_title_gateway_settings_2',
110
						)
111
					);
112
					break;
113
114
				case 'offline-donations' :
115
					$settings = array(
116
						// Section 3: Offline gateway.
117
						array(
118
							'type' => 'title',
119
							'id'   => 'give_title_gateway_settings_3',
120
						),
121
						array(
122
							'name'    => __( 'Collect Billing Details', 'give' ),
123
							'desc'    => __( 'Enable to request billing details for offline donations. Will appear above offline donation instructions. Can be enabled/disabled per form.', 'give' ),
124
							'id'      => 'give_offline_donation_enable_billing_fields',
125
							'type'    => 'radio_inline',
126
							'default' => 'disabled',
127
							'options' => array(
128
								'enabled'  => __( 'Enabled', 'give' ),
129
								'disabled' => __( 'Disabled', 'give' )
130
							)
131
						),
132
						array(
133
							'name'    => __( 'Offline Donation Instructions', 'give' ),
134
							'desc'    => __( 'The following content will appear for all forms when the user selects the offline donation payment option. Note: You may customize the content per form as needed.', 'give' ),
135
							'id'      => 'global_offline_donation_content',
136
							'default' => give_get_default_offline_donation_content(),
137
							'type'    => 'wysiwyg',
138
							'options' => array(
139
								'textarea_rows' => 6,
140
							)
141
						),
142
						array(
143
							'name'  => esc_html__( 'Offline Donations Settings Docs Link', 'give' ),
144
							'id'    => 'offline_gateway_settings_docs_link',
145
							'url'   => esc_url( 'http://docs.givewp.com/offlinegateway' ),
146
							'title' => __( 'Offline Gateway Settings', 'give' ),
147
							'type'  => 'give_docs_link',
148
						),
149
						array(
150
							'type' => 'sectionend',
151
							'id'   => 'give_title_gateway_settings_3',
152
						)
153
					);
154
					break;
155
156
				case 'gateways-settings':
157
					$settings = array(
158
						// Section 1: Gateways.
159
						array(
160
							'id'   => 'give_title_gateway_settings_1',
161
							'type' => 'title'
162
						),
163
						array(
164
							'name'    => __( 'Test Mode', 'give' ),
165
							'desc'    => __( 'While in test mode no live donations are processed. To fully use test mode, you must have a sandbox (test) account for the payment gateway you are testing.', 'give' ),
166
							'id'      => 'test_mode',
167
							'type'    => 'radio_inline',
168
							'default' => 'disabled',
169
							'options' => array(
170
								'enabled'  => __( 'Enabled', 'give' ),
171
								'disabled' => __( 'Disabled', 'give' ),
172
							)
173
						),
174
						array(
175
							'name' => __( 'Enabled Gateways', 'give' ),
176
							'desc' => __( 'Enable your payment gateway. Can be ordered by dragging.', 'give' ),
177
							'id'   => 'gateways',
178
							'type' => 'enabled_gateways'
179
						),
180
						array(
181
							'name' => __( 'Default Gateway', 'give' ),
182
							'desc' => __( 'The gateway that will be selected by default.', 'give' ),
183
							'id'   => 'default_gateway',
184
							'type' => 'default_gateway'
185
						),
186
                        array(
187
                            'name'  => __( 'Gateways Docs Link', 'give' ),
188
                            'id'    => 'gateway_settings_docs_link',
189
                            'url'   => esc_url( 'http://docs.givewp.com/settings-gateways' ),
190
                            'title' => __( 'Gateway Settings', 'give' ),
191
                            'type'  => 'give_docs_link',
192
                        ),
193
						array(
194
							'id'   => 'give_title_gateway_settings_1',
195
							'type' => 'sectionend'
196
						),
197
					);
198
					break;
199
			}
200
201
			/**
202
			 * Filter the payment gateways settings.
203
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
204
			 */
205
			$settings = apply_filters( 'give_settings_gateways', $settings );
206
207
			/**
208
			 * Filter the settings.
209
			 *
210
			 * @since  1.8
211
			 *
212
			 * @param  array $settings
213
			 */
214
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
215
216
			// Output.
217
			return $settings;
218
		}
219
220
		/**
221
		 * Get sections.
222
		 *
223
		 * @since 1.8
224
		 * @return array
225
		 */
226
		public function get_sections() {
227
			$sections = array(
228
				'gateways-settings' => __( 'Gateways', 'give' ),
229
				'paypal-standard'   => __( 'PayPal Standard', 'give' ),
230
				'offline-donations' => __( 'Offline Donations', 'give' )
231
			);
232
233
			return apply_filters( 'give_get_sections_' . $this->id, $sections );
234
		}
235
	}
236
237
endif;
238
239
return new Give_Settings_Gateways();
240