@@ -5,7 +5,7 @@ discard block |
||
| 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 | |
@@ -53,23 +53,23 @@ discard block |
||
| 53 | 53 | public $apple_pay_verify_notice; |
| 54 | 54 | |
| 55 | 55 | public function __construct() { |
| 56 | - add_action( 'woocommerce_stripe_updated', array( $this, 'verify_domain_if_needed' ) ); |
|
| 57 | - add_action( 'update_option_woocommerce_stripe_settings', array( $this, 'verify_domain_on_new_secret_key' ), 10, 2 ); |
|
| 56 | + add_action('woocommerce_stripe_updated', array($this, 'verify_domain_if_needed')); |
|
| 57 | + add_action('update_option_woocommerce_stripe_settings', array($this, 'verify_domain_on_new_secret_key'), 10, 2); |
|
| 58 | 58 | |
| 59 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 60 | - $this->stripe_enabled = $this->get_option( 'enabled' ); |
|
| 61 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
| 62 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 59 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 60 | + $this->stripe_enabled = $this->get_option('enabled'); |
|
| 61 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
| 62 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 63 | 63 | $this->apple_pay_verify_notice = ''; |
| 64 | 64 | $this->secret_key = $this->get_secret_key(); |
| 65 | 65 | |
| 66 | - if ( empty( $this->stripe_settings ) ) { |
|
| 66 | + if (empty($this->stripe_settings)) { |
|
| 67 | 67 | return; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $this->init_apple_pay(); |
| 71 | 71 | |
| 72 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 72 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -80,13 +80,13 @@ discard block |
||
| 80 | 80 | * @param string default |
| 81 | 81 | * @return string $setting_value |
| 82 | 82 | */ |
| 83 | - public function get_option( $setting = '', $default = '' ) { |
|
| 84 | - if ( empty( $this->stripe_settings ) ) { |
|
| 83 | + public function get_option($setting = '', $default = '') { |
|
| 84 | + if (empty($this->stripe_settings)) { |
|
| 85 | 85 | return $default; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( ! empty( $this->stripe_settings[ $setting ] ) ) { |
|
| 89 | - return $this->stripe_settings[ $setting ]; |
|
| 88 | + if ( ! empty($this->stripe_settings[$setting])) { |
|
| 89 | + return $this->stripe_settings[$setting]; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | return $default; |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | * @return string Secret key. |
| 100 | 100 | */ |
| 101 | 101 | private function get_secret_key() { |
| 102 | - $testmode = 'yes' === $this->get_option( 'testmode', 'no' ); |
|
| 103 | - return $testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 102 | + $testmode = 'yes' === $this->get_option('testmode', 'no'); |
|
| 103 | + return $testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | public function init_apple_pay() { |
| 113 | 113 | if ( |
| 114 | 114 | is_admin() && |
| 115 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 116 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 117 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
| 115 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 116 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 117 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
| 118 | 118 | $this->payment_request |
| 119 | 119 | ) { |
| 120 | 120 | $this->verify_domain(); |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * @version 3.1.0 |
| 129 | 129 | * @param string $secret_key |
| 130 | 130 | */ |
| 131 | - private function register_domain_with_apple( $secret_key = '' ) { |
|
| 132 | - if ( empty( $secret_key ) ) { |
|
| 133 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 131 | + private function register_domain_with_apple($secret_key = '') { |
|
| 132 | + if (empty($secret_key)) { |
|
| 133 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -148,22 +148,22 @@ discard block |
||
| 148 | 148 | $endpoint, |
| 149 | 149 | array( |
| 150 | 150 | 'headers' => $headers, |
| 151 | - 'body' => http_build_query( $data ), |
|
| 151 | + 'body' => http_build_query($data), |
|
| 152 | 152 | ) |
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | - if ( is_wp_error( $response ) ) { |
|
| 155 | + if (is_wp_error($response)) { |
|
| 156 | 156 | /* translators: error message */ |
| 157 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 157 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if ( 200 !== $response['response']['code'] ) { |
|
| 161 | - $parsed_response = json_decode( $response['body'] ); |
|
| 160 | + if (200 !== $response['response']['code']) { |
|
| 161 | + $parsed_response = json_decode($response['body']); |
|
| 162 | 162 | |
| 163 | 163 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
| 164 | 164 | |
| 165 | 165 | /* translators: error message */ |
| 166 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
| 166 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
@@ -177,43 +177,43 @@ discard block |
||
| 177 | 177 | * @since 4.3.0 |
| 178 | 178 | * @return bool True on success, false on failure. |
| 179 | 179 | */ |
| 180 | - public function update_domain_association_file( $force = false ) { |
|
| 181 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
| 180 | + public function update_domain_association_file($force = false) { |
|
| 181 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
| 182 | 182 | $dir = '.well-known'; |
| 183 | 183 | $file = 'apple-developer-merchantid-domain-association'; |
| 184 | 184 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 185 | 185 | |
| 186 | - $existing_contents = @file_get_contents( $fullpath ); |
|
| 187 | - $new_contents = @file_get_contents( WC_STRIPE_PLUGIN_PATH . '/' . $file ); |
|
| 188 | - if ( ( ! $existing_contents && ! $force ) || $existing_contents === $new_contents ) { |
|
| 186 | + $existing_contents = @file_get_contents($fullpath); |
|
| 187 | + $new_contents = @file_get_contents(WC_STRIPE_PLUGIN_PATH . '/' . $file); |
|
| 188 | + if (( ! $existing_contents && ! $force) || $existing_contents === $new_contents) { |
|
| 189 | 189 | return true; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $error = null; |
| 193 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
| 194 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine |
|
| 195 | - $error = __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ); |
|
| 193 | + if ( ! file_exists($path . '/' . $dir)) { |
|
| 194 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine |
|
| 195 | + $error = __('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine |
|
| 199 | - $error = __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ); |
|
| 198 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine |
|
| 199 | + $error = __('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if ( isset( $error ) ) { |
|
| 202 | + if (isset($error)) { |
|
| 203 | 203 | $url = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $dir . '/' . $file; |
| 204 | - $response = wp_remote_get( $url ); |
|
| 205 | - $already_hosted = wp_remote_retrieve_body( $response ) === $new_contents; |
|
| 206 | - if ( ! $already_hosted ) { |
|
| 204 | + $response = wp_remote_get($url); |
|
| 205 | + $already_hosted = wp_remote_retrieve_body($response) === $new_contents; |
|
| 206 | + if ( ! $already_hosted) { |
|
| 207 | 207 | WC_Stripe_Logger::log( |
| 208 | 208 | 'Error: ' . $error . ' ' . |
| 209 | 209 | /* translators: expected domain association file URL */ |
| 210 | - sprintf( __( 'To enable Apple Pay, domain association file must be hosted at %s.', 'woocommerce-gateway-stripe' ), $url ) |
|
| 210 | + sprintf(__('To enable Apple Pay, domain association file must be hosted at %s.', 'woocommerce-gateway-stripe'), $url) |
|
| 211 | 211 | ); |
| 212 | 212 | } |
| 213 | 213 | return $already_hosted; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - WC_Stripe_Logger::log( 'Domain association file updated.' ); |
|
| 216 | + WC_Stripe_Logger::log('Domain association file updated.'); |
|
| 217 | 217 | return true; |
| 218 | 218 | } |
| 219 | 219 | |
@@ -224,32 +224,32 @@ discard block |
||
| 224 | 224 | * @version 3.1.0 |
| 225 | 225 | */ |
| 226 | 226 | public function verify_domain() { |
| 227 | - if ( ! $this->update_domain_association_file( true ) ) { |
|
| 227 | + if ( ! $this->update_domain_association_file(true)) { |
|
| 228 | 228 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
| 229 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
| 229 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
| 230 | 230 | return; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | try { |
| 234 | 234 | // At this point then the domain association folder and file should be available. |
| 235 | 235 | // Proceed to verify/and or verify again. |
| 236 | - $this->register_domain_with_apple( $this->secret_key ); |
|
| 236 | + $this->register_domain_with_apple($this->secret_key); |
|
| 237 | 237 | |
| 238 | 238 | // No errors to this point, verification success! |
| 239 | 239 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
| 240 | 240 | $this->apple_pay_domain_set = true; |
| 241 | 241 | |
| 242 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
| 242 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
| 243 | 243 | |
| 244 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
| 244 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
| 245 | 245 | |
| 246 | - } catch ( Exception $e ) { |
|
| 246 | + } catch (Exception $e) { |
|
| 247 | 247 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
| 248 | 248 | $this->apple_pay_domain_set = false; |
| 249 | 249 | |
| 250 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
| 250 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
| 251 | 251 | |
| 252 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 252 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | * @since 4.5.3 |
| 260 | 260 | * @version 4.5.3 |
| 261 | 261 | */ |
| 262 | - public function verify_domain_on_new_secret_key( $prev_settings, $settings ) { |
|
| 262 | + public function verify_domain_on_new_secret_key($prev_settings, $settings) { |
|
| 263 | 263 | $this->stripe_settings = $prev_settings; |
| 264 | 264 | $prev_secret_key = $this->get_secret_key(); |
| 265 | 265 | |
| 266 | 266 | $this->stripe_settings = $settings; |
| 267 | 267 | $this->secret_key = $this->get_secret_key(); |
| 268 | 268 | |
| 269 | - if ( ! empty( $this->secret_key ) && $this->secret_key !== $prev_secret_key ) { |
|
| 269 | + if ( ! empty($this->secret_key) && $this->secret_key !== $prev_secret_key) { |
|
| 270 | 270 | $this->verify_domain(); |
| 271 | 271 | } |
| 272 | 272 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @version 4.5.3 |
| 279 | 279 | */ |
| 280 | 280 | public function verify_domain_if_needed() { |
| 281 | - if ( $this->apple_pay_domain_set ) { |
|
| 281 | + if ($this->apple_pay_domain_set) { |
|
| 282 | 282 | $this->update_domain_association_file(); |
| 283 | 283 | } else { |
| 284 | 284 | $this->verify_domain(); |
@@ -291,16 +291,16 @@ discard block |
||
| 291 | 291 | * @since 4.0.6 |
| 292 | 292 | */ |
| 293 | 293 | public function admin_notices() { |
| 294 | - if ( ! $this->stripe_enabled || ! $this->payment_request ) { |
|
| 294 | + if ( ! $this->stripe_enabled || ! $this->payment_request) { |
|
| 295 | 295 | return; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 298 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 299 | 299 | return; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - $empty_notice = empty( $this->apple_pay_verify_notice ); |
|
| 303 | - if ( $empty_notice && ( $this->apple_pay_domain_set || empty( $this->secret_key ) ) ) { |
|
| 302 | + $empty_notice = empty($this->apple_pay_verify_notice); |
|
| 303 | + if ($empty_notice && ($this->apple_pay_domain_set || empty($this->secret_key))) { |
|
| 304 | 304 | return; |
| 305 | 305 | } |
| 306 | 306 | |
@@ -309,28 +309,28 @@ discard block |
||
| 309 | 309 | * when setting screen is displayed. So if domain verification is not set, |
| 310 | 310 | * something went wrong so lets notify user. |
| 311 | 311 | */ |
| 312 | - $allowed_html = array( |
|
| 312 | + $allowed_html = array( |
|
| 313 | 313 | 'a' => array( |
| 314 | 314 | 'href' => array(), |
| 315 | 315 | 'title' => array(), |
| 316 | 316 | ), |
| 317 | 317 | ); |
| 318 | - $verification_failed_without_error = __( 'Apple Pay domain verification failed.', 'woocommerce-gateway-stripe' ); |
|
| 319 | - $verification_failed_with_error = __( 'Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe' ); |
|
| 318 | + $verification_failed_without_error = __('Apple Pay domain verification failed.', 'woocommerce-gateway-stripe'); |
|
| 319 | + $verification_failed_with_error = __('Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe'); |
|
| 320 | 320 | $check_log_text = sprintf( |
| 321 | 321 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
| 322 | - 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' ), |
|
| 323 | - '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', |
|
| 322 | + 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'), |
|
| 323 | + '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', |
|
| 324 | 324 | '</a>' |
| 325 | 325 | ); |
| 326 | 326 | |
| 327 | 327 | ?> |
| 328 | 328 | <div class="error stripe-apple-pay-message"> |
| 329 | - <?php if ( $empty_notice ) : ?> |
|
| 330 | - <p><?php echo esc_html( $verification_failed_without_error ); ?></p> |
|
| 329 | + <?php if ($empty_notice) : ?> |
|
| 330 | + <p><?php echo esc_html($verification_failed_without_error); ?></p> |
|
| 331 | 331 | <?php else : ?> |
| 332 | - <p><?php echo esc_html( $verification_failed_with_error ); ?></p> |
|
| 333 | - <p><i><?php echo wp_kses( make_clickable( esc_html( $this->apple_pay_verify_notice ) ), $allowed_html ); ?></i></p> |
|
| 332 | + <p><?php echo esc_html($verification_failed_with_error); ?></p> |
|
| 333 | + <p><i><?php echo wp_kses(make_clickable(esc_html($this->apple_pay_verify_notice)), $allowed_html); ?></i></p> |
|
| 334 | 334 | <?php endif; ?> |
| 335 | 335 | <p><?php echo $check_log_text; ?></p> |
| 336 | 336 | </div> |
@@ -328,8 +328,11 @@ |
||
| 328 | 328 | <div class="error stripe-apple-pay-message"> |
| 329 | 329 | <?php if ( $empty_notice ) : ?> |
| 330 | 330 | <p><?php echo esc_html( $verification_failed_without_error ); ?></p> |
| 331 | - <?php else : ?> |
|
| 332 | - <p><?php echo esc_html( $verification_failed_with_error ); ?></p> |
|
| 331 | + <?php else { |
|
| 332 | + : ?> |
|
| 333 | + <p><?php echo esc_html( $verification_failed_with_error ); |
|
| 334 | +} |
|
| 335 | +?></p> |
|
| 333 | 336 | <p><i><?php echo wp_kses( make_clickable( esc_html( $this->apple_pay_verify_notice ) ), $allowed_html ); ?></i></p> |
| 334 | 337 | <?php endif; ?> |
| 335 | 338 | <p><?php echo $check_log_text; ?></p> |