@@ -69,7 +69,7 @@ discard block |
||
| 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 Whether Apple Pay required settings are enabled. |
|
| 72 | + * @return boolean Whether Apple Pay required settings are enabled. |
|
| 73 | 73 | */ |
| 74 | 74 | private function is_enabled() { |
| 75 | 75 | $stripe_enabled = 'yes' === $this->get_option( 'enabled', 'no' ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * Add to the list of publicly allowed query variables. |
| 104 | 104 | * |
| 105 | 105 | * @param array $query_vars - provided public query vars. |
| 106 | - * @return array Updated public query vars. |
|
| 106 | + * @return string[] Updated public query vars. |
|
| 107 | 107 | */ |
| 108 | 108 | public function whitelist_domain_association_query_param( $query_vars ) { |
| 109 | 109 | $query_vars[] = 'apple-developer-merchantid-domain-association'; |
@@ -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 | |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | public $apple_pay_verify_notice; |
| 33 | 33 | |
| 34 | 34 | public function __construct() { |
| 35 | - add_action( 'init', array( $this, 'add_domain_association_rewrite_rule' ) ); |
|
| 36 | - add_filter( 'query_vars', array( $this, 'whitelist_domain_association_query_param' ), 10, 1 ); |
|
| 37 | - add_action( 'parse_request', array( $this, 'parse_domain_association_request' ), 10, 1 ); |
|
| 35 | + add_action('init', array($this, 'add_domain_association_rewrite_rule')); |
|
| 36 | + add_filter('query_vars', array($this, 'whitelist_domain_association_query_param'), 10, 1); |
|
| 37 | + add_action('parse_request', array($this, 'parse_domain_association_request'), 10, 1); |
|
| 38 | 38 | |
| 39 | - add_action( 'woocommerce_stripe_updated', array( $this, 'verify_domain_if_configured' ) ); |
|
| 40 | - add_action( 'update_option_woocommerce_stripe_settings', array( $this, 'verify_domain_on_settings_change' ), 10, 2 ); |
|
| 41 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 39 | + add_action('woocommerce_stripe_updated', array($this, 'verify_domain_if_configured')); |
|
| 40 | + add_action('update_option_woocommerce_stripe_settings', array($this, 'verify_domain_on_settings_change'), 10, 2); |
|
| 41 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 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 |
||
| 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 |
||
| 72 | 72 | * @return string Whether Apple Pay required settings are enabled. |
| 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 |
||
| 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 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $regex = '^\.well-known\/apple-developer-merchantid-domain-association$'; |
| 97 | 97 | $redirect = 'index.php?apple-developer-merchantid-domain-association=1'; |
| 98 | 98 | |
| 99 | - add_rewrite_rule( $regex, $redirect, 'top' ); |
|
| 99 | + add_rewrite_rule($regex, $redirect, 'top'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param array $query_vars - provided public query vars. |
| 106 | 106 | * @return array Updated public query vars. |
| 107 | 107 | */ |
| 108 | - public function whitelist_domain_association_query_param( $query_vars ) { |
|
| 108 | + public function whitelist_domain_association_query_param($query_vars) { |
|
| 109 | 109 | $query_vars[] = 'apple-developer-merchantid-domain-association'; |
| 110 | 110 | return $query_vars; |
| 111 | 111 | } |
@@ -115,17 +115,17 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @param WP WordPress environment object. |
| 117 | 117 | */ |
| 118 | - public function parse_domain_association_request( $wp ) { |
|
| 118 | + public function parse_domain_association_request($wp) { |
|
| 119 | 119 | if ( |
| 120 | - ! isset( $wp->query_vars['apple-developer-merchantid-domain-association'] ) || |
|
| 120 | + ! isset($wp->query_vars['apple-developer-merchantid-domain-association']) || |
|
| 121 | 121 | '1' !== $wp->query_vars['apple-developer-merchantid-domain-association'] |
| 122 | 122 | ) { |
| 123 | 123 | return; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $path = WC_STRIPE_PLUGIN_PATH . '/apple-developer-merchantid-domain-association'; |
| 127 | - header( 'Content-Type: application/octet-stream' ); |
|
| 128 | - echo esc_html( file_get_contents( $path ) ); |
|
| 127 | + header('Content-Type: application/octet-stream'); |
|
| 128 | + echo esc_html(file_get_contents($path)); |
|
| 129 | 129 | exit; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | * @version 4.5.4 |
| 137 | 137 | * @param string $secret_key |
| 138 | 138 | */ |
| 139 | - private function make_domain_registration_request( $secret_key ) { |
|
| 140 | - if ( empty( $secret_key ) ) { |
|
| 141 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 139 | + private function make_domain_registration_request($secret_key) { |
|
| 140 | + if (empty($secret_key)) { |
|
| 141 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -156,22 +156,22 @@ discard block |
||
| 156 | 156 | $endpoint, |
| 157 | 157 | array( |
| 158 | 158 | 'headers' => $headers, |
| 159 | - 'body' => http_build_query( $data ), |
|
| 159 | + 'body' => http_build_query($data), |
|
| 160 | 160 | ) |
| 161 | 161 | ); |
| 162 | 162 | |
| 163 | - if ( is_wp_error( $response ) ) { |
|
| 163 | + if (is_wp_error($response)) { |
|
| 164 | 164 | /* translators: error message */ |
| 165 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 165 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( 200 !== $response['response']['code'] ) { |
|
| 169 | - $parsed_response = json_decode( $response['body'] ); |
|
| 168 | + if (200 !== $response['response']['code']) { |
|
| 169 | + $parsed_response = json_decode($response['body']); |
|
| 170 | 170 | |
| 171 | 171 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
| 172 | 172 | |
| 173 | 173 | /* translators: error message */ |
| 174 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
| 174 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -183,25 +183,25 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @param string $secret_key |
| 185 | 185 | */ |
| 186 | - public function register_domain_with_apple( $secret_key ) { |
|
| 186 | + public function register_domain_with_apple($secret_key) { |
|
| 187 | 187 | try { |
| 188 | - $this->make_domain_registration_request( $secret_key ); |
|
| 188 | + $this->make_domain_registration_request($secret_key); |
|
| 189 | 189 | |
| 190 | 190 | // No errors to this point, verification success! |
| 191 | 191 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
| 192 | 192 | $this->apple_pay_domain_set = true; |
| 193 | 193 | |
| 194 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
| 194 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
| 195 | 195 | |
| 196 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
| 196 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
| 197 | 197 | |
| 198 | - } catch ( Exception $e ) { |
|
| 198 | + } catch (Exception $e) { |
|
| 199 | 199 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
| 200 | 200 | $this->apple_pay_domain_set = false; |
| 201 | 201 | |
| 202 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
| 202 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
| 203 | 203 | |
| 204 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 204 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | public function verify_domain_if_configured() { |
| 216 | 216 | $secret_key = $this->get_secret_key(); |
| 217 | 217 | |
| 218 | - if ( ! $this->is_enabled() || empty( $secret_key ) ) { |
|
| 218 | + if ( ! $this->is_enabled() || empty($secret_key)) { |
|
| 219 | 219 | return; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | flush_rewrite_rules(); |
| 224 | 224 | |
| 225 | 225 | // Register the domain with Apple Pay. |
| 226 | - $this->register_domain_with_apple( $secret_key ); |
|
| 226 | + $this->register_domain_with_apple($secret_key); |
|
| 227 | 227 | |
| 228 | 228 | // Show/hide failure note if necessary. |
| 229 | 229 | WC_Stripe_Inbox_Notes::notify_of_apple_pay_domain_verification_if_needed(); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * @since 4.5.3 |
| 236 | 236 | * @version 4.5.4 |
| 237 | 237 | */ |
| 238 | - public function verify_domain_on_settings_change( $prev_settings, $settings ) { |
|
| 238 | + public function verify_domain_on_settings_change($prev_settings, $settings) { |
|
| 239 | 239 | // Grab previous state and then update cached settings. |
| 240 | 240 | $this->stripe_settings = $prev_settings; |
| 241 | 241 | $prev_secret_key = $this->get_secret_key(); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $this->stripe_settings = $settings; |
| 244 | 244 | |
| 245 | 245 | // If Stripe or Payment Request Button wasn't enabled (or secret key was different) then might need to verify now. |
| 246 | - if ( ! $prev_is_enabled || ( $this->get_secret_key() !== $prev_secret_key ) ) { |
|
| 246 | + if ( ! $prev_is_enabled || ($this->get_secret_key() !== $prev_secret_key)) { |
|
| 247 | 247 | $this->verify_domain_if_configured(); |
| 248 | 248 | } |
| 249 | 249 | } |
@@ -254,16 +254,16 @@ discard block |
||
| 254 | 254 | * @since 4.0.6 |
| 255 | 255 | */ |
| 256 | 256 | public function admin_notices() { |
| 257 | - if ( ! $this->is_enabled() ) { |
|
| 257 | + if ( ! $this->is_enabled()) { |
|
| 258 | 258 | return; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 261 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 262 | 262 | return; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - $empty_notice = empty( $this->apple_pay_verify_notice ); |
|
| 266 | - if ( $empty_notice && ( $this->apple_pay_domain_set || empty( $this->secret_key ) ) ) { |
|
| 265 | + $empty_notice = empty($this->apple_pay_verify_notice); |
|
| 266 | + if ($empty_notice && ($this->apple_pay_domain_set || empty($this->secret_key))) { |
|
| 267 | 267 | return; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -272,28 +272,28 @@ discard block |
||
| 272 | 272 | * when setting screen is displayed. So if domain verification is not set, |
| 273 | 273 | * something went wrong so lets notify user. |
| 274 | 274 | */ |
| 275 | - $allowed_html = array( |
|
| 275 | + $allowed_html = array( |
|
| 276 | 276 | 'a' => array( |
| 277 | 277 | 'href' => array(), |
| 278 | 278 | 'title' => array(), |
| 279 | 279 | ), |
| 280 | 280 | ); |
| 281 | - $verification_failed_without_error = __( 'Apple Pay domain verification failed.', 'woocommerce-gateway-stripe' ); |
|
| 282 | - $verification_failed_with_error = __( 'Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe' ); |
|
| 281 | + $verification_failed_without_error = __('Apple Pay domain verification failed.', 'woocommerce-gateway-stripe'); |
|
| 282 | + $verification_failed_with_error = __('Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe'); |
|
| 283 | 283 | $check_log_text = sprintf( |
| 284 | 284 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
| 285 | - 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' ), |
|
| 286 | - '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', |
|
| 285 | + 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'), |
|
| 286 | + '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', |
|
| 287 | 287 | '</a>' |
| 288 | 288 | ); |
| 289 | 289 | |
| 290 | 290 | ?> |
| 291 | 291 | <div class="error stripe-apple-pay-message"> |
| 292 | - <?php if ( $empty_notice ) : ?> |
|
| 293 | - <p><?php echo esc_html( $verification_failed_without_error ); ?></p> |
|
| 292 | + <?php if ($empty_notice) : ?> |
|
| 293 | + <p><?php echo esc_html($verification_failed_without_error); ?></p> |
|
| 294 | 294 | <?php else : ?> |
| 295 | - <p><?php echo esc_html( $verification_failed_with_error ); ?></p> |
|
| 296 | - <p><i><?php echo wp_kses( make_clickable( esc_html( $this->apple_pay_verify_notice ) ), $allowed_html ); ?></i></p> |
|
| 295 | + <p><?php echo esc_html($verification_failed_with_error); ?></p> |
|
| 296 | + <p><i><?php echo wp_kses(make_clickable(esc_html($this->apple_pay_verify_notice)), $allowed_html); ?></i></p> |
|
| 297 | 297 | <?php endif; ?> |
| 298 | 298 | <p><?php echo $check_log_text; ?></p> |
| 299 | 299 | </div> |