Completed
Branch FET/better-paypal-error-unauth... (bfa619)
by
unknown
36:48 queued 27:44
created
payment_methods/Paypal_Express/forms/SettingsForm.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -19,53 +19,53 @@
 block discarded – undo
19 19
  */
20 20
 class SettingsForm extends PayPalSettingsForm
21 21
 {
22
-    /**
23
-     * SettingsForm constructor.
24
-     *
25
-     * @param array $options_array
26
-     * @param string $help_tab_link
27
-     * @throws InvalidDataTypeException
28
-     * @throws InvalidInterfaceException
29
-     * @throws InvalidArgumentException
30
-     */
31
-    public function __construct(array $options_array, $help_tab_link)
32
-    {
33
-        $options_array = array_replace_recursive(
34
-            array(
35
-                'extra_meta_inputs' => array(
36
-                    'request_shipping_addr' => new EE_Yes_No_Input(
37
-                        array(
38
-                            'html_label_text' => sprintf(
39
-                                esc_html__('Request Shipping Address %s', 'event_espresso'),
40
-                                $help_tab_link
41
-                            ),
42
-                            'html_help_text'  => esc_html__(
43
-                            // @codingStandardsIgnoreStart
44
-                                'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
45
-                                // @codingStandardsIgnoreEnd
46
-                                'event_espresso'
47
-                            ),
48
-                            'required'        => true,
49
-                            'default'         => false,
50
-                        )
51
-                    ),
52
-                    'image_url' => new EE_Admin_File_Uploader_Input(
53
-                        array(
54
-                            'html_label_text' => sprintf(
55
-                                esc_html__('Image URL %s', 'event_espresso'),
56
-                                $help_tab_link
57
-                            ),
58
-                            'html_help_text'  => esc_html__(
59
-                                'Used for your business/personal logo on the PayPal page',
60
-                                'event_espresso'
61
-                            ),
62
-                            'required'        => false,
63
-                        )
64
-                    ),
65
-                )
66
-            ),
67
-            $options_array
68
-        );
69
-        parent::__construct($options_array, $help_tab_link);
70
-    }
22
+	/**
23
+	 * SettingsForm constructor.
24
+	 *
25
+	 * @param array $options_array
26
+	 * @param string $help_tab_link
27
+	 * @throws InvalidDataTypeException
28
+	 * @throws InvalidInterfaceException
29
+	 * @throws InvalidArgumentException
30
+	 */
31
+	public function __construct(array $options_array, $help_tab_link)
32
+	{
33
+		$options_array = array_replace_recursive(
34
+			array(
35
+				'extra_meta_inputs' => array(
36
+					'request_shipping_addr' => new EE_Yes_No_Input(
37
+						array(
38
+							'html_label_text' => sprintf(
39
+								esc_html__('Request Shipping Address %s', 'event_espresso'),
40
+								$help_tab_link
41
+							),
42
+							'html_help_text'  => esc_html__(
43
+							// @codingStandardsIgnoreStart
44
+								'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
45
+								// @codingStandardsIgnoreEnd
46
+								'event_espresso'
47
+							),
48
+							'required'        => true,
49
+							'default'         => false,
50
+						)
51
+					),
52
+					'image_url' => new EE_Admin_File_Uploader_Input(
53
+						array(
54
+							'html_label_text' => sprintf(
55
+								esc_html__('Image URL %s', 'event_espresso'),
56
+								$help_tab_link
57
+							),
58
+							'html_help_text'  => esc_html__(
59
+								'Used for your business/personal logo on the PayPal page',
60
+								'event_espresso'
61
+							),
62
+							'required'        => false,
63
+						)
64
+					),
65
+				)
66
+			),
67
+			$options_array
68
+		);
69
+		parent::__construct($options_array, $help_tab_link);
70
+	}
71 71
 }
Please login to merge, or discard this patch.
core/services/payment_methods/forms/PayPalSettingsForm.php 1 patch
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -19,201 +19,201 @@
 block discarded – undo
19 19
  */
20 20
 class PayPalSettingsForm extends EE_Payment_Method_Form
21 21
 {
22
-    /**
23
-     * @var string of HTML being the help tab link
24
-     */
25
-    protected $helpTabLink;
22
+	/**
23
+	 * @var string of HTML being the help tab link
24
+	 */
25
+	protected $helpTabLink;
26 26
 
27
-    public function __construct(array $options_array, $help_tab_link)
28
-    {
29
-        $this->helpTabLink = $help_tab_link;
30
-        $options_array = array_replace_recursive(
31
-            array(
32
-                'extra_meta_inputs' => array(
33
-                    'api_username' => new EE_Text_Input(
34
-                        array(
35
-                            'html_label_text' => sprintf(
36
-                                // translators: %s link to help doc
37
-                                esc_html__('API Username %s', 'event_espresso'),
38
-                                $help_tab_link
39
-                            ),
40
-                            'required'        => true,
41
-                        )
42
-                    ),
43
-                    'api_password' => new EE_Text_Input(
44
-                        array(
45
-                            'html_label_text' => sprintf(
46
-                                // translators: %s link to help doc
47
-                                esc_html__('API Password %s', 'event_espresso'),
48
-                                $help_tab_link
49
-                            ),
50
-                            'required'        => true,
51
-                        )
52
-                    ),
53
-                    'api_signature' => new EE_Text_Input(
54
-                        array(
55
-                            'html_label_text' => sprintf(
56
-                                // translators: %s link to help doc
57
-                                esc_html__('API Signature %s', 'event_espresso'),
58
-                                $help_tab_link
59
-                            ),
60
-                            'required'        => true,
61
-                        )
62
-                    ),
63
-                )
64
-            ),
65
-            $options_array
66
-        );
67
-        parent::__construct($options_array);
68
-    }
27
+	public function __construct(array $options_array, $help_tab_link)
28
+	{
29
+		$this->helpTabLink = $help_tab_link;
30
+		$options_array = array_replace_recursive(
31
+			array(
32
+				'extra_meta_inputs' => array(
33
+					'api_username' => new EE_Text_Input(
34
+						array(
35
+							'html_label_text' => sprintf(
36
+								// translators: %s link to help doc
37
+								esc_html__('API Username %s', 'event_espresso'),
38
+								$help_tab_link
39
+							),
40
+							'required'        => true,
41
+						)
42
+					),
43
+					'api_password' => new EE_Text_Input(
44
+						array(
45
+							'html_label_text' => sprintf(
46
+								// translators: %s link to help doc
47
+								esc_html__('API Password %s', 'event_espresso'),
48
+								$help_tab_link
49
+							),
50
+							'required'        => true,
51
+						)
52
+					),
53
+					'api_signature' => new EE_Text_Input(
54
+						array(
55
+							'html_label_text' => sprintf(
56
+								// translators: %s link to help doc
57
+								esc_html__('API Signature %s', 'event_espresso'),
58
+								$help_tab_link
59
+							),
60
+							'required'        => true,
61
+						)
62
+					),
63
+				)
64
+			),
65
+			$options_array
66
+		);
67
+		parent::__construct($options_array);
68
+	}
69 69
 
70
-    /**
71
-     * Tests the the PayPal API credentials work ok
72
-     * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string
73
-     * @throws EE_Error
74
-     */
75
-    protected function checkForCredentialsErrors()
76
-    {
77
-        $request_params = array(
78
-            'METHOD'    => 'GetBalance',
79
-            'VERSION'   => '204.0',
80
-            'USER'      => urlencode($this->get_input_value('api_username')),
81
-            'PWD'       => urlencode($this->get_input_value('api_password')),
82
-            'SIGNATURE' => urlencode($this->get_input_value('api_signature')),
83
-        );
84
-        $gateway_url = $this->get_input_value('PMD_debug_mode')
85
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
86
-            : 'https://api-3t.paypal.com/nvp';
87
-        // Request Customer Details.
88
-        $response = wp_remote_post(
89
-            $gateway_url,
90
-            array(
91
-                'method'      => 'POST',
92
-                'timeout'     => 45,
93
-                'httpversion' => '1.1',
94
-                'cookies'     => array(),
95
-                'headers'     => array(),
96
-                'body'        => http_build_query($request_params, '', '&'),
97
-            )
98
-        );
99
-        if (is_wp_error($response) || empty($response['body'])) {
100
-            // If we got here then there was an error in this request.
101
-            // maybe is turned off. We don't know the credentials are invalid
102
-            EE_Error::add_error(
103
-                sprintf(
104
-                    // translators: %1$s Error message received from PayPal
105
-                    esc_html__(
106
-                        // @codingStandardsIgnoreStart
107
-                        'Your PayPal credentials could not be verified. The following error occurred while communicating with PayPal: %1$s',
108
-                        // @codingStandardsIgnoreEnd
109
-                        'event_espresso'
110
-                    ),
111
-                    $response->get_error_message()
112
-                ),
113
-                __FILE__,
114
-                __FUNCTION__,
115
-                __LINE__
116
-            );
117
-        }
118
-        $response_args = array();
119
-        parse_str(urldecode($response['body']), $response_args);
70
+	/**
71
+	 * Tests the the PayPal API credentials work ok
72
+	 * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string
73
+	 * @throws EE_Error
74
+	 */
75
+	protected function checkForCredentialsErrors()
76
+	{
77
+		$request_params = array(
78
+			'METHOD'    => 'GetBalance',
79
+			'VERSION'   => '204.0',
80
+			'USER'      => urlencode($this->get_input_value('api_username')),
81
+			'PWD'       => urlencode($this->get_input_value('api_password')),
82
+			'SIGNATURE' => urlencode($this->get_input_value('api_signature')),
83
+		);
84
+		$gateway_url = $this->get_input_value('PMD_debug_mode')
85
+			? 'https://api-3t.sandbox.paypal.com/nvp'
86
+			: 'https://api-3t.paypal.com/nvp';
87
+		// Request Customer Details.
88
+		$response = wp_remote_post(
89
+			$gateway_url,
90
+			array(
91
+				'method'      => 'POST',
92
+				'timeout'     => 45,
93
+				'httpversion' => '1.1',
94
+				'cookies'     => array(),
95
+				'headers'     => array(),
96
+				'body'        => http_build_query($request_params, '', '&'),
97
+			)
98
+		);
99
+		if (is_wp_error($response) || empty($response['body'])) {
100
+			// If we got here then there was an error in this request.
101
+			// maybe is turned off. We don't know the credentials are invalid
102
+			EE_Error::add_error(
103
+				sprintf(
104
+					// translators: %1$s Error message received from PayPal
105
+					esc_html__(
106
+						// @codingStandardsIgnoreStart
107
+						'Your PayPal credentials could not be verified. The following error occurred while communicating with PayPal: %1$s',
108
+						// @codingStandardsIgnoreEnd
109
+						'event_espresso'
110
+					),
111
+					$response->get_error_message()
112
+				),
113
+				__FILE__,
114
+				__FUNCTION__,
115
+				__LINE__
116
+			);
117
+		}
118
+		$response_args = array();
119
+		parse_str(urldecode($response['body']), $response_args);
120 120
 
121
-        if (empty($response_args['ACK'])) {
122
-            EE_Error::add_error(
123
-                esc_html__(
124
-                    'Your PayPal credentials could not be verified. Part of their response was missing.',
125
-                    'event_espresso'
126
-                ),
127
-                __FILE__,
128
-                __FUNCTION__,
129
-                __LINE__
130
-            );
131
-        }
132
-        if (in_array(
133
-            $response_args['ACK'],
134
-            array(
135
-                'Success',
136
-                'SuccessWithWarning'
137
-            ),
138
-            true
139
-        )
140
-        ) {
141
-            return '';
142
-        } else {
143
-            return sprintf(
144
-                // translators: %1$s: PayPal response message, %2$s: PayPal response code
145
-                esc_html__(
146
-                    // @codingStandardsIgnoreStart
147
-                    'Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.',
148
-                    // @codingStandardsIgnoreEnd
149
-                    'event_espresso'
150
-                ),
151
-                isset($response_args['L_LONGMESSAGE0'])
152
-                    ? $response_args['L_LONGMESSAGE0']
153
-                    : esc_html__('No error message received from PayPal', 'event_espresso'),
154
-                isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0
155
-            );
156
-        }
157
-    }
121
+		if (empty($response_args['ACK'])) {
122
+			EE_Error::add_error(
123
+				esc_html__(
124
+					'Your PayPal credentials could not be verified. Part of their response was missing.',
125
+					'event_espresso'
126
+				),
127
+				__FILE__,
128
+				__FUNCTION__,
129
+				__LINE__
130
+			);
131
+		}
132
+		if (in_array(
133
+			$response_args['ACK'],
134
+			array(
135
+				'Success',
136
+				'SuccessWithWarning'
137
+			),
138
+			true
139
+		)
140
+		) {
141
+			return '';
142
+		} else {
143
+			return sprintf(
144
+				// translators: %1$s: PayPal response message, %2$s: PayPal response code
145
+				esc_html__(
146
+					// @codingStandardsIgnoreStart
147
+					'Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.',
148
+					// @codingStandardsIgnoreEnd
149
+					'event_espresso'
150
+				),
151
+				isset($response_args['L_LONGMESSAGE0'])
152
+					? $response_args['L_LONGMESSAGE0']
153
+					: esc_html__('No error message received from PayPal', 'event_espresso'),
154
+				isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0
155
+			);
156
+		}
157
+	}
158 158
 
159
-    /**
160
-     * Gets the HTML to show the link to the help tab
161
-     * @return string
162
-     */
163
-    protected function helpTabLink()
164
-    {
165
-        return $this->helpTabLink;
166
-    }
159
+	/**
160
+	 * Gets the HTML to show the link to the help tab
161
+	 * @return string
162
+	 */
163
+	protected function helpTabLink()
164
+	{
165
+		return $this->helpTabLink;
166
+	}
167 167
 
168
-    /**
169
-     * Does the normal validation, but also verifies the PayPal API credentials work.
170
-     * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more
171
-     * tips) on each of the inputs that could be the cause of the problem.
172
-     * @throws EE_Error
173
-     */
174
-    public function _validate()
175
-    {
176
-        parent::_validate();
177
-        $credentials_message = $this->checkForCredentialsErrors();
178
-        if ($credentials_message !== '') {
179
-            $this->add_validation_error($credentials_message);
180
-            $this->get_input('PMD_debug_mode')->add_validation_error(
181
-                esc_html__(
182
-                    // @codingStandardsIgnoreStart
183
-                    'If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".',
184
-                    // @codingStandardsIgnoreEnd
185
-                    'event_espresso'
186
-                )
187
-            );
188
-            $this->get_input('api_username')->add_validation_error(
189
-                sprintf(
190
-                    // translators: $1$s HTML for a link to the help tab
191
-                    esc_html__(
192
-                        'Are you sure this is your API username, not your login username? %1$s',
193
-                        'event_espresso'
194
-                    ),
195
-                    $this->helpTabLink()
196
-                )
197
-            );
198
-            $this->get_input('api_password')->add_validation_error(
199
-                sprintf(
200
-                    // translators: $1$s HTML for a link to the help tab
201
-                    esc_html__(
202
-                        'Are you sure this is your API password, not your login password? %1$s',
203
-                        'event_espresso'
204
-                    ),
205
-                    $this->helpTabLink()
206
-                )
207
-            );
208
-            $this->get_input('api_signature')->add_validation_error(
209
-                sprintf(
210
-                    // translators: $1$s HTML for a link to the help tab
211
-                    esc_html__('Please verify your API signature is correct. %1$s', 'event_espresso'),
212
-                    $this->helpTabLink()
213
-                )
214
-            );
215
-        }
216
-    }
168
+	/**
169
+	 * Does the normal validation, but also verifies the PayPal API credentials work.
170
+	 * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more
171
+	 * tips) on each of the inputs that could be the cause of the problem.
172
+	 * @throws EE_Error
173
+	 */
174
+	public function _validate()
175
+	{
176
+		parent::_validate();
177
+		$credentials_message = $this->checkForCredentialsErrors();
178
+		if ($credentials_message !== '') {
179
+			$this->add_validation_error($credentials_message);
180
+			$this->get_input('PMD_debug_mode')->add_validation_error(
181
+				esc_html__(
182
+					// @codingStandardsIgnoreStart
183
+					'If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".',
184
+					// @codingStandardsIgnoreEnd
185
+					'event_espresso'
186
+				)
187
+			);
188
+			$this->get_input('api_username')->add_validation_error(
189
+				sprintf(
190
+					// translators: $1$s HTML for a link to the help tab
191
+					esc_html__(
192
+						'Are you sure this is your API username, not your login username? %1$s',
193
+						'event_espresso'
194
+					),
195
+					$this->helpTabLink()
196
+				)
197
+			);
198
+			$this->get_input('api_password')->add_validation_error(
199
+				sprintf(
200
+					// translators: $1$s HTML for a link to the help tab
201
+					esc_html__(
202
+						'Are you sure this is your API password, not your login password? %1$s',
203
+						'event_espresso'
204
+					),
205
+					$this->helpTabLink()
206
+				)
207
+			);
208
+			$this->get_input('api_signature')->add_validation_error(
209
+				sprintf(
210
+					// translators: $1$s HTML for a link to the help tab
211
+					esc_html__('Please verify your API signature is correct. %1$s', 'event_espresso'),
212
+					$this->helpTabLink()
213
+				)
214
+			);
215
+		}
216
+	}
217 217
 }
218 218
 // End of file PayPalSettingsForm.php
219 219
 // Location: ${NAMESPACE}/PayPalSettingsForm.php
Please login to merge, or discard this patch.