Completed
Branch FET/better-paypal-error-unauth... (dc9b41)
by
unknown
75:58 queued 66:48
created
core/services/payment_methods/forms/PayPalSettingsForm.php 1 patch
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -19,174 +19,174 @@
 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 = 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 = 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__('Your PayPal credentials could not be verified. There was an error communicating with PayPal, it was %1$s', 'event_espresso'),
106
-                    $response->get_error_message()
107
-                ),
108
-                __FILE__,
109
-                __FUNCTION__,
110
-                __LINE__
111
-            );
112
-        }
113
-        $response_args = array();
114
-        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__('Your PayPal credentials could not be verified. There was an error communicating with PayPal, it was %1$s', 'event_espresso'),
106
+					$response->get_error_message()
107
+				),
108
+				__FILE__,
109
+				__FUNCTION__,
110
+				__LINE__
111
+			);
112
+		}
113
+		$response_args = array();
114
+		parse_str(urldecode($response['body']), $response_args);
115 115
 
116
-        if (empty($response_args['ACK'])) {
117
-            EE_Error::add_error(
118
-                esc_html__(
119
-                    'Your PayPal credentials could not be verified. Part of their response was missing.',
120
-                    'event_espresso'
121
-                ),
122
-                __FILE__,
123
-                __FUNCTION__,
124
-                __LINE__
125
-            );
126
-        }
127
-        if (in_array(
128
-            $response_args['ACK'],
129
-            array(
130
-                'Success',
131
-                'SuccessWithWarning'
132
-            ),
133
-            true
134
-        )
135
-        ) {
136
-            return '';
137
-        } else {
138
-            return sprintf(
139
-                esc_html__('Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', 'event_espresso'),
140
-                isset($response_args['L_LONGMESSAGE0']) ? $response_args['L_LONGMESSAGE0'] : esc_html__('No error message received from PayPal', 'event_espresso'),
141
-                isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0
142
-            );
143
-        }
144
-    }
116
+		if (empty($response_args['ACK'])) {
117
+			EE_Error::add_error(
118
+				esc_html__(
119
+					'Your PayPal credentials could not be verified. Part of their response was missing.',
120
+					'event_espresso'
121
+				),
122
+				__FILE__,
123
+				__FUNCTION__,
124
+				__LINE__
125
+			);
126
+		}
127
+		if (in_array(
128
+			$response_args['ACK'],
129
+			array(
130
+				'Success',
131
+				'SuccessWithWarning'
132
+			),
133
+			true
134
+		)
135
+		) {
136
+			return '';
137
+		} else {
138
+			return sprintf(
139
+				esc_html__('Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', 'event_espresso'),
140
+				isset($response_args['L_LONGMESSAGE0']) ? $response_args['L_LONGMESSAGE0'] : esc_html__('No error message received from PayPal', 'event_espresso'),
141
+				isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0
142
+			);
143
+		}
144
+	}
145 145
 
146
-    /**
147
-     * Gets the HTML to show the link to the help tab
148
-     * @return string
149
-     */
150
-    protected function helpTabLink()
151
-    {
152
-        return $this->helpTabLink;
153
-    }
146
+	/**
147
+	 * Gets the HTML to show the link to the help tab
148
+	 * @return string
149
+	 */
150
+	protected function helpTabLink()
151
+	{
152
+		return $this->helpTabLink;
153
+	}
154 154
 
155
-    /**
156
-     * Does the normal validation, but also verifies the PayPal API credentials work.
157
-     * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more tips)
158
-     * on each of the inputs that could be the cause of the problem.
159
-     * @throws EntityNotFoundException
160
-     */
161
-    public function _validate()
162
-    {
163
-        parent::_validate();
164
-        $credentials_message = $this->checkForCredentialsErrors();
165
-        if ($credentials_message !== '') {
166
-            $this->add_validation_error($credentials_message);
167
-            $this->get_input('PMD_debug_mode')->add_validation_error(
168
-                esc_html__('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".', 'event_espresso')
169
-            );
170
-            $this->get_input('api_username')->add_validation_error(
171
-                sprintf(
172
-                    esc_html__('Are you sure this is your API username, not your login username?%1$s', 'event_espresso'),
173
-                    $this->helpTabLink()
174
-                )
175
-            );
176
-            $this->get_input('api_password')->add_validation_error(
177
-                sprintf(
178
-                    esc_html__('Are you sure this is your API password, not your login password.%1$s', 'event_espresso'),
179
-                    $this->helpTabLink()
180
-                )
181
-            );
182
-            $this->get_input('api_signature')->add_validation_error(
183
-                sprintf(
184
-                    esc_html__('Please verify your API signature is correct.%1$s', 'event_espresso'),
185
-                    $this->helpTabLink()
186
-                )
187
-            );
188
-        }
189
-    }
155
+	/**
156
+	 * Does the normal validation, but also verifies the PayPal API credentials work.
157
+	 * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more tips)
158
+	 * on each of the inputs that could be the cause of the problem.
159
+	 * @throws EntityNotFoundException
160
+	 */
161
+	public function _validate()
162
+	{
163
+		parent::_validate();
164
+		$credentials_message = $this->checkForCredentialsErrors();
165
+		if ($credentials_message !== '') {
166
+			$this->add_validation_error($credentials_message);
167
+			$this->get_input('PMD_debug_mode')->add_validation_error(
168
+				esc_html__('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".', 'event_espresso')
169
+			);
170
+			$this->get_input('api_username')->add_validation_error(
171
+				sprintf(
172
+					esc_html__('Are you sure this is your API username, not your login username?%1$s', 'event_espresso'),
173
+					$this->helpTabLink()
174
+				)
175
+			);
176
+			$this->get_input('api_password')->add_validation_error(
177
+				sprintf(
178
+					esc_html__('Are you sure this is your API password, not your login password.%1$s', 'event_espresso'),
179
+					$this->helpTabLink()
180
+				)
181
+			);
182
+			$this->get_input('api_signature')->add_validation_error(
183
+				sprintf(
184
+					esc_html__('Please verify your API signature is correct.%1$s', 'event_espresso'),
185
+					$this->helpTabLink()
186
+				)
187
+			);
188
+		}
189
+	}
190 190
 }
191 191
 // End of file PayPalSettingsForm.php
192 192
 // Location: ${NAMESPACE}/PayPalSettingsForm.php
Please login to merge, or discard this patch.
caffeinated/payment_methods/Paypal_Pro/forms/SettingsForm.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -20,33 +20,33 @@
 block discarded – undo
20 20
  */
21 21
 class SettingsForm extends PayPalSettingsForm
22 22
 {
23
-    /**
24
-     * SettingsForm constructor.
25
-     *
26
-     * @param array $options_array
27
-     * @param string $help_tab_link
28
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
29
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
30
-     * @throws \InvalidArgumentException
31
-     */
32
-    public function __construct(array $options_array = array(), $help_tab_link)
33
-    {
34
-        $options_array = array_replace_recursive(
35
-            array(
36
-                'extra_meta_inputs' => array(
37
-                    'credit_card_types' => new EE_Checkbox_Multi_Input(
38
-                        EE_PMT_Paypal_Pro::card_types_supported(),
39
-                        array(
40
-                            'html_label_text' => __('Card Types Supported', 'event_espresso'),
41
-                            'required' => true
42
-                        )
43
-                    ),
44
-                )
45
-            ),
46
-            $options_array
47
-        );
48
-        parent::__construct($options_array, $help_tab_link);
49
-    }
23
+	/**
24
+	 * SettingsForm constructor.
25
+	 *
26
+	 * @param array $options_array
27
+	 * @param string $help_tab_link
28
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
29
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
30
+	 * @throws \InvalidArgumentException
31
+	 */
32
+	public function __construct(array $options_array = array(), $help_tab_link)
33
+	{
34
+		$options_array = array_replace_recursive(
35
+			array(
36
+				'extra_meta_inputs' => array(
37
+					'credit_card_types' => new EE_Checkbox_Multi_Input(
38
+						EE_PMT_Paypal_Pro::card_types_supported(),
39
+						array(
40
+							'html_label_text' => __('Card Types Supported', 'event_espresso'),
41
+							'required' => true
42
+						)
43
+					),
44
+				)
45
+			),
46
+			$options_array
47
+		);
48
+		parent::__construct($options_array, $help_tab_link);
49
+	}
50 50
 }
51 51
 // End of file SettingsForm.php
52 52
 // Location: EventEspresso\caffeinated\payment_methods\PayPal_Pro\forms/SettingsForm.php
Please login to merge, or discard this patch.