Completed
Pull Request — master (#1412)
by Ravinder
17:25
created

Give_Settings_Gateways   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 219
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 219
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B get_settings() 0 182 4
A get_sections() 0 9 1
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 {
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';
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' => esc_html__( 'PayPal Email', 'give' ),
57
							'desc' => esc_html__( 'Enter your PayPal account\'s email.', 'give' ),
58
							'id'   => 'paypal_email',
59
							'type' => 'email',
60
						),
61
						array(
62
							'name' => esc_html__( 'PayPal Page Style', 'give' ),
63
							'desc' => esc_html__( 'Enter the name of the 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'    => esc_html__( 'PayPal Transaction Type', 'give' ),
69
							'desc'    => esc_html__( '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' => esc_html__( 'Donation', 'give' ),
74
								'standard' => esc_html__( 'Standard Transaction', 'give' )
75
							),
76
							'default' => 'donation',
77
						),
78
						array(
79
							'name'    => esc_html__( 'PayPal IPN Verification', 'give' ),
80
							'desc'    => esc_html__( 'If donations are not getting marked as complete, use a slightly less secure method of verifying donations.', 'give' ),
81
							'id'      => 'paypal_verification',
82
							'type'    => 'radio_inline',
83
							'default' => 'enabled',
84
							'options' => array(
85
								'enabled'  => __( 'Enabled', 'give' ),
86
								'disabled' => __( 'Disabled', 'give' ),
87
							)
88
						),
89
                        array(
90
                            'name'  => esc_html__( 'PayPal Standard Gateway Settings Docs Link', 'give' ),
91
                            'id'    => 'paypal_standard_gateway_settings_docs_link',
92
                            'url'   => esc_url( 'http://docs.givewp.com/paypalstandard' ),
93
                            'title' => __( 'PayPal Standard Gateway Settings', 'give' ),
94
                            'type'  => 'give_docs_link',
95
                        ),
96
						array(
97
							'type' => 'sectionend',
98
							'id'   => 'give_title_gateway_settings_2',
99
						)
100
					);
101
					break;
102
103
				case 'offline-donations' :
104
					$settings = array(
105
						// Section 3: Offline gateway.
106
						array(
107
							'type' => 'title',
108
							'id'   => 'give_title_gateway_settings_3',
109
						),
110
						array(
111
							'name'    => esc_html__( 'Collect Billing Details', 'give' ),
112
							'desc'    => esc_html__( 'Enable to request billing details for offline donations. Will appear above offline donation instructions. Can be enabled/disabled per form.', 'give' ),
113
							'id'      => 'give_offline_donation_enable_billing_fields',
114
							'type'    => 'radio_inline',
115
							'default' => 'disabled',
116
							'options' => array(
117
								'enabled'  => __( 'Enabled', 'give' ),
118
								'disabled' => __( 'Disabled', 'give' )
119
							)
120
						),
121
						array(
122
							'name'    => esc_html__( 'Offline Donation Instructions', 'give' ),
123
							'desc'    => esc_html__( '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' ),
124
							'id'      => 'global_offline_donation_content',
125
							'default' => give_get_default_offline_donation_content(),
126
							'type'    => 'wysiwyg',
127
							'options' => array(
128
								'textarea_rows' => 6,
129
							)
130
						),
131
						array(
132
							'name'    => esc_html__( 'Offline Donation Email Instructions Subject', 'give' ),
133
							'desc'    => esc_html__( 'Enter the subject line for the donation receipt email.', 'give' ),
134
							'id'      => 'offline_donation_subject',
135
							'default' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ),
136
							'type'    => 'text'
137
						),
138
						array(
139
							'name'    => esc_html__( 'Offline Donation Email Instructions', 'give' ),
140
							'desc'    => esc_html__( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
141
							'id'      => 'global_offline_donation_email',
142
							'default' => give_get_default_offline_donation_email_content(),
143
							'type'    => 'wysiwyg',
144
							'options' => array(
145
								'textarea_rows' => 6,
146
							)
147
						),
148
                        array(
149
                            'name'  => esc_html__( 'Offline Donations Settings Docs Link', 'give' ),
150
                            'id'    => 'offline_gateway_settings_docs_link',
151
                            'url'   => esc_url( 'http://docs.givewp.com/offlinegateway' ),
152
                            'title' => __( 'Offline Gateway Settings', 'give' ),
153
                            'type'  => 'give_docs_link',
154
                        ),
155
						array(
156
							'type' => 'sectionend',
157
							'id'   => 'give_title_gateway_settings_3',
158
						)
159
					);
160
					break;
161
162
				case 'gateways-settings':
163
					$settings = array(
164
						// Section 1: Gateways.
165
						array(
166
							'id'   => 'give_title_gateway_settings_1',
167
							'type' => 'title'
168
						),
169
						array(
170
							'name'    => esc_html__( 'Test Mode', 'give' ),
171
							'desc'    => esc_html__( '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' ),
172
							'id'      => 'test_mode',
173
							'type'    => 'radio_inline',
174
							'default' => 'disabled',
175
							'options' => array(
176
								'enabled'  => __( 'Enabled', 'give' ),
177
								'disabled' => __( 'Disabled', 'give' ),
178
							)
179
						),
180
						array(
181
							'name' => esc_html__( 'Enabled Gateways', 'give' ),
182
							'desc' => esc_html__( 'Enable your payment gateway. Can be ordered by dragging.', 'give' ),
183
							'id'   => 'gateways',
184
							'type' => 'enabled_gateways'
185
						),
186
						array(
187
							'name' => esc_html__( 'Default Gateway', 'give' ),
188
							'desc' => esc_html__( 'The gateway that will be selected by default.', 'give' ),
189
							'id'   => 'default_gateway',
190
							'type' => 'default_gateway'
191
						),
192
                        array(
193
                            'name'  => esc_html__( 'Gateways Docs Link', 'give' ),
194
                            'id'    => 'gateway_settings_docs_link',
195
                            'url'   => esc_url( 'http://docs.givewp.com/gatewayssettings' ),
196
                            'title' => __( 'Gateway Settings', 'give' ),
197
                            'type'  => 'give_docs_link',
198
                        ),
199
						array(
200
							'id'   => 'give_title_gateway_settings_1',
201
							'type' => 'sectionend'
202
						),
203
					);
204
					break;
205
			}
206
207
			/**
208
			 * Filter the payment gateways settings.
209
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
210
			 */
211
			$settings = apply_filters( 'give_settings_gateways', $settings );
212
213
			/**
214
			 * Filter the settings.
215
			 *
216
			 * @since  1.8
217
			 *
218
			 * @param  array $settings
219
			 */
220
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
221
222
			// Output.
223
			return $settings;
224
		}
225
226
		/**
227
		 * Get sections.
228
		 *
229
		 * @since 1.8
230
		 * @return array
231
		 */
232
		public function get_sections() {
233
			$sections = array(
234
				'gateways-settings' => esc_html__( 'Gateways', 'give' ),
235
				'paypal-standard'   => esc_html__( 'Paypal Standard', 'give' ),
236
				'offline-donations' => esc_html__( 'Offline', 'give' )
237
			);
238
239
			return apply_filters( 'give_get_sections_' . $this->id, $sections );
240
		}
241
	}
242
243
endif;
244
245
return new Give_Settings_Gateways();
246