Completed
Pull Request — master (#1357)
by
unknown
01:55
created
includes/class-wc-stripe-apple-pay-registration.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * Whether the gateway and Payment Request Button (prerequisites for Apple Pay) are enabled.
70 70
 	 *
71 71
 	 * @since 4.5.4
72
-	 * @return string Secret key.
72
+	 * @return boolean Secret key.
73 73
 	 */
74 74
 	private function is_enabled() {
75 75
 		$stripe_enabled                 = 'yes' === $this->get_option( 'enabled', 'no' );
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * Add to the list of publicly allowed query variables.
103 103
 	 *
104 104
 	 * @param  array $query_vars - provided public query vars.
105
-	 * @return array Updated public query vars.
105
+	 * @return string[] Updated public query vars.
106 106
 	 */
107 107
 	public function whitelist_domain_association_query_param( $query_vars ) {
108 108
 		$query_vars[] = 'apple-developer-merchantid-domain-association';
Please login to merge, or discard this patch.
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since 4.0.6
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if ( ! defined('ABSPATH')) {
9 9
 	exit;
10 10
 }
11 11
 
@@ -32,16 +32,16 @@  discard block
 block discarded – undo
32 32
 	public $apple_pay_verify_notice;
33 33
 
34 34
 	public function __construct() {
35
-		add_action( 'woocommerce_stripe_updated', array( $this, 'verify_domain_if_configured' ) );
36
-		add_action( 'update_option_woocommerce_stripe_settings', array( $this, 'verify_domain_on_settings_change' ), 10, 2 );
37
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
35
+		add_action('woocommerce_stripe_updated', array($this, 'verify_domain_if_configured'));
36
+		add_action('update_option_woocommerce_stripe_settings', array($this, 'verify_domain_on_settings_change'), 10, 2);
37
+		add_action('admin_notices', array($this, 'admin_notices'));
38 38
 
39
-		add_action( 'init', array( $this, 'add_domain_association_rewrite_rule' ) );
40
-		add_filter( 'query_vars', array( $this, 'whitelist_domain_association_query_param' ), 10, 1 );
41
-		add_action( 'parse_request', array( $this, 'parse_domain_association_request' ), 10, 1 );
39
+		add_action('init', array($this, 'add_domain_association_rewrite_rule'));
40
+		add_filter('query_vars', array($this, 'whitelist_domain_association_query_param'), 10, 1);
41
+		add_action('parse_request', array($this, 'parse_domain_association_request'), 10, 1);
42 42
 
43
-		$this->stripe_settings                 = get_option( 'woocommerce_stripe_settings', array() );
44
-		$this->apple_pay_domain_set            = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
43
+		$this->stripe_settings                 = get_option('woocommerce_stripe_settings', array());
44
+		$this->apple_pay_domain_set            = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
45 45
 		$this->apple_pay_verify_notice         = '';
46 46
 	}
47 47
 
@@ -53,13 +53,13 @@  discard block
 block discarded – undo
53 53
 	 * @param string default
54 54
 	 * @return string $setting_value
55 55
 	 */
56
-	public function get_option( $setting = '', $default = '' ) {
57
-		if ( empty( $this->stripe_settings ) ) {
56
+	public function get_option($setting = '', $default = '') {
57
+		if (empty($this->stripe_settings)) {
58 58
 			return $default;
59 59
 		}
60 60
 
61
-		if ( ! empty( $this->stripe_settings[ $setting ] ) ) {
62
-			return $this->stripe_settings[ $setting ];
61
+		if ( ! empty($this->stripe_settings[$setting])) {
62
+			return $this->stripe_settings[$setting];
63 63
 		}
64 64
 
65 65
 		return $default;
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	 * @return string Secret key.
73 73
 	 */
74 74
 	private function is_enabled() {
75
-		$stripe_enabled                 = 'yes' === $this->get_option( 'enabled', 'no' );
76
-		$payment_request_button_enabled = 'yes' === $this->get_option( 'payment_request', 'yes' );
75
+		$stripe_enabled                 = 'yes' === $this->get_option('enabled', 'no');
76
+		$payment_request_button_enabled = 'yes' === $this->get_option('payment_request', 'yes');
77 77
 
78 78
 		return $stripe_enabled && $payment_request_button_enabled;
79 79
 	}
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 	 * @return string Secret key.
86 86
 	 */
87 87
 	private function get_secret_key() {
88
-		$testmode = 'yes' === $this->get_option( 'testmode', 'no' );
89
-		return $testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
88
+		$testmode = 'yes' === $this->get_option('testmode', 'no');
89
+		return $testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
90 90
 	}
91 91
 
92 92
 	/**
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	public function add_domain_association_rewrite_rule() {
96 96
 		$regex    = '^\.well-known\/apple-developer-merchantid-domain-association$';
97 97
 		$redirect = 'index.php?apple-developer-merchantid-domain-association=1';
98
-		add_rewrite_rule( $regex, $redirect, 'top' );
98
+		add_rewrite_rule($regex, $redirect, 'top');
99 99
 	}
100 100
 
101 101
 	/**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @param  array $query_vars - provided public query vars.
105 105
 	 * @return array Updated public query vars.
106 106
 	 */
107
-	public function whitelist_domain_association_query_param( $query_vars ) {
107
+	public function whitelist_domain_association_query_param($query_vars) {
108 108
 		$query_vars[] = 'apple-developer-merchantid-domain-association';
109 109
 		return $query_vars;
110 110
 	}
@@ -114,19 +114,19 @@  discard block
 block discarded – undo
114 114
 	 *
115 115
 	 * @param WP WordPress environment object.
116 116
 	 */
117
-	public function parse_domain_association_request( $wp ) {
117
+	public function parse_domain_association_request($wp) {
118 118
 		if (
119
-			! isset( $wp->query_vars['apple-developer-merchantid-domain-association'] ) ||
119
+			! isset($wp->query_vars['apple-developer-merchantid-domain-association']) ||
120 120
 			'1' !== $wp->query_vars['apple-developer-merchantid-domain-association']
121 121
 		) {
122 122
 			return;
123 123
 		}
124 124
 
125 125
 		$path     = WC_STRIPE_PLUGIN_PATH . '/' . 'apple-developer-merchantid-domain-association';
126
-		$contents = file_get_contents( $path );
126
+		$contents = file_get_contents($path);
127 127
 
128
-		header( 'Content-Type: application/octet-stream' );
129
-		echo esc_html( $contents );
128
+		header('Content-Type: application/octet-stream');
129
+		echo esc_html($contents);
130 130
 
131 131
 		exit;
132 132
 	}
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
 	 * @version 4.5.4
139 139
 	 * @param string $secret_key
140 140
 	 */
141
-	private function make_domain_registration_request( $secret_key ) {
142
-		if ( empty( $secret_key ) ) {
143
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
141
+	private function make_domain_registration_request($secret_key) {
142
+		if (empty($secret_key)) {
143
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
144 144
 		}
145 145
 
146 146
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -158,22 +158,22 @@  discard block
 block discarded – undo
158 158
 			$endpoint,
159 159
 			array(
160 160
 				'headers' => $headers,
161
-				'body'    => http_build_query( $data ),
161
+				'body'    => http_build_query($data),
162 162
 			)
163 163
 		);
164 164
 
165
-		if ( is_wp_error( $response ) ) {
165
+		if (is_wp_error($response)) {
166 166
 			/* translators: error message */
167
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
167
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
168 168
 		}
169 169
 
170
-		if ( 200 !== $response['response']['code'] ) {
171
-			$parsed_response = json_decode( $response['body'] );
170
+		if (200 !== $response['response']['code']) {
171
+			$parsed_response = json_decode($response['body']);
172 172
 
173 173
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
174 174
 
175 175
 			/* translators: error message */
176
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
176
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
177 177
 		}
178 178
 	}
179 179
 
@@ -185,25 +185,25 @@  discard block
 block discarded – undo
185 185
 	 *
186 186
 	 * @param string $secret_key
187 187
 	 */
188
-	public function register_domain_with_apple( $secret_key ) {
188
+	public function register_domain_with_apple($secret_key) {
189 189
 		try {
190
-			$this->make_domain_registration_request( $secret_key );
190
+			$this->make_domain_registration_request($secret_key);
191 191
 
192 192
 			// No errors to this point, verification success!
193 193
 			$this->stripe_settings['apple_pay_domain_set'] = 'yes';
194 194
 			$this->apple_pay_domain_set                    = true;
195 195
 
196
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
196
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
197 197
 
198
-			WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' );
198
+			WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!');
199 199
 
200
-		} catch ( Exception $e ) {
200
+		} catch (Exception $e) {
201 201
 			$this->stripe_settings['apple_pay_domain_set'] = 'no';
202 202
 			$this->apple_pay_domain_set                    = false;
203 203
 
204
-			update_option( 'woocommerce_stripe_settings', $this->stripe_settings );
204
+			update_option('woocommerce_stripe_settings', $this->stripe_settings);
205 205
 
206
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
206
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
207 207
 		}
208 208
 	}
209 209
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	public function verify_domain_if_configured() {
218 218
 		$secret_key = $this->get_secret_key();
219 219
 
220
-		if ( ! $this->is_enabled() || empty( $secret_key ) ) {
220
+		if ( ! $this->is_enabled() || empty($secret_key)) {
221 221
 			return;
222 222
 		}
223 223
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		flush_rewrite_rules();
226 226
 
227 227
 		// Register the domain with Apple Pay.
228
-		$this->register_domain_with_apple( $secret_key );
228
+		$this->register_domain_with_apple($secret_key);
229 229
 	}
230 230
 
231 231
 	/**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	 * @since 4.5.3
235 235
 	 * @version 4.5.4
236 236
 	 */
237
-	public function verify_domain_on_settings_change( $prev_settings, $settings ) {
237
+	public function verify_domain_on_settings_change($prev_settings, $settings) {
238 238
 		// Grab previous state and then update cached settings.
239 239
 		$this->stripe_settings = $prev_settings;
240 240
 		$prev_secret_key       = $this->get_secret_key();
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 		$this->stripe_settings = $settings;
243 243
 
244 244
 		// If Stripe or Payment Request Button wasn't enabled (or secret key was different) then might need to verify now.
245
-		if ( ! $prev_is_enabled || ( $this->get_secret_key() !== $prev_secret_key ) ) {
245
+		if ( ! $prev_is_enabled || ($this->get_secret_key() !== $prev_secret_key)) {
246 246
 			$this->verify_domain_if_configured();
247 247
 		}
248 248
 	}
@@ -253,16 +253,16 @@  discard block
 block discarded – undo
253 253
 	 * @since 4.0.6
254 254
 	 */
255 255
 	public function admin_notices() {
256
-		if ( ! $this->is_enabled() ) {
256
+		if ( ! $this->is_enabled()) {
257 257
 			return;
258 258
 		}
259 259
 
260
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
260
+		if ( ! current_user_can('manage_woocommerce')) {
261 261
 			return;
262 262
 		}
263 263
 
264
-		$empty_notice = empty( $this->apple_pay_verify_notice );
265
-		if ( $empty_notice && ( $this->apple_pay_domain_set || empty( $this->secret_key ) ) ) {
264
+		$empty_notice = empty($this->apple_pay_verify_notice);
265
+		if ($empty_notice && ($this->apple_pay_domain_set || empty($this->secret_key))) {
266 266
 			return;
267 267
 		}
268 268
 
@@ -271,28 +271,28 @@  discard block
 block discarded – undo
271 271
 		 * when setting screen is displayed. So if domain verification is not set,
272 272
 		 * something went wrong so lets notify user.
273 273
 		 */
274
-		$allowed_html                      = array(
274
+		$allowed_html = array(
275 275
 			'a' => array(
276 276
 				'href'  => array(),
277 277
 				'title' => array(),
278 278
 			),
279 279
 		);
280
-		$verification_failed_without_error = __( 'Apple Pay domain verification failed.', 'woocommerce-gateway-stripe' );
281
-		$verification_failed_with_error    = __( 'Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe' );
280
+		$verification_failed_without_error = __('Apple Pay domain verification failed.', 'woocommerce-gateway-stripe');
281
+		$verification_failed_with_error    = __('Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe');
282 282
 		$check_log_text                    = sprintf(
283 283
 			/* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */
284
-			esc_html__( 'Please check the %1$slogs%2$s for more details on this issue. Logging must be enabled to see recorded logs.', 'woocommerce-gateway-stripe' ),
285
-			'<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">',
284
+			esc_html__('Please check the %1$slogs%2$s for more details on this issue. Logging must be enabled to see recorded logs.', 'woocommerce-gateway-stripe'),
285
+			'<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">',
286 286
 			'</a>'
287 287
 		);
288 288
 
289 289
 		?>
290 290
 		<div class="error stripe-apple-pay-message">
291
-			<?php if ( $empty_notice ) : ?>
292
-				<p><?php echo esc_html( $verification_failed_without_error ); ?></p>
291
+			<?php if ($empty_notice) : ?>
292
+				<p><?php echo esc_html($verification_failed_without_error); ?></p>
293 293
 			<?php else : ?>
294
-				<p><?php echo esc_html( $verification_failed_with_error ); ?></p>
295
-				<p><i><?php echo wp_kses( make_clickable( esc_html( $this->apple_pay_verify_notice ) ), $allowed_html ); ?></i></p>
294
+				<p><?php echo esc_html($verification_failed_with_error); ?></p>
295
+				<p><i><?php echo wp_kses(make_clickable(esc_html($this->apple_pay_verify_notice)), $allowed_html); ?></i></p>
296 296
 			<?php endif; ?>
297 297
 			<p><?php echo $check_log_text; ?></p>
298 298
 		</div>
Please login to merge, or discard this patch.