@@ -69,7 +69,7 @@ |
||
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' ); |
@@ -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( '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 |
||
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 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 |
||
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 | /** |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function add_domain_association_rewrite_rule() { |
96 | 96 | $regex = '^\.well-known\/apple-developer-merchantid-domain-association$'; |
97 | - $redirect = parse_url( WC_STRIPE_PLUGIN_URL, PHP_URL_PATH ) . '/apple-developer-merchantid-domain-association'; |
|
97 | + $redirect = parse_url(WC_STRIPE_PLUGIN_URL, PHP_URL_PATH) . '/apple-developer-merchantid-domain-association'; |
|
98 | 98 | |
99 | - add_rewrite_rule( $regex, $redirect, 'top' ); |
|
99 | + add_rewrite_rule($regex, $redirect, 'top'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @version 4.5.4 |
107 | 107 | * @param string $secret_key |
108 | 108 | */ |
109 | - private function make_domain_registration_request( $secret_key ) { |
|
110 | - if ( empty( $secret_key ) ) { |
|
111 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
109 | + private function make_domain_registration_request($secret_key) { |
|
110 | + if (empty($secret_key)) { |
|
111 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -126,22 +126,22 @@ discard block |
||
126 | 126 | $endpoint, |
127 | 127 | array( |
128 | 128 | 'headers' => $headers, |
129 | - 'body' => http_build_query( $data ), |
|
129 | + 'body' => http_build_query($data), |
|
130 | 130 | ) |
131 | 131 | ); |
132 | 132 | |
133 | - if ( is_wp_error( $response ) ) { |
|
133 | + if (is_wp_error($response)) { |
|
134 | 134 | /* translators: error message */ |
135 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
135 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
136 | 136 | } |
137 | 137 | |
138 | - if ( 200 !== $response['response']['code'] ) { |
|
139 | - $parsed_response = json_decode( $response['body'] ); |
|
138 | + if (200 !== $response['response']['code']) { |
|
139 | + $parsed_response = json_decode($response['body']); |
|
140 | 140 | |
141 | 141 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
142 | 142 | |
143 | 143 | /* translators: error message */ |
144 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
144 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
@@ -153,25 +153,25 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @param string $secret_key |
155 | 155 | */ |
156 | - public function register_domain_with_apple( $secret_key ) { |
|
156 | + public function register_domain_with_apple($secret_key) { |
|
157 | 157 | try { |
158 | - $this->make_domain_registration_request( $secret_key ); |
|
158 | + $this->make_domain_registration_request($secret_key); |
|
159 | 159 | |
160 | 160 | // No errors to this point, verification success! |
161 | 161 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
162 | 162 | $this->apple_pay_domain_set = true; |
163 | 163 | |
164 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
164 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
165 | 165 | |
166 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
166 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
167 | 167 | |
168 | - } catch ( Exception $e ) { |
|
168 | + } catch (Exception $e) { |
|
169 | 169 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
170 | 170 | $this->apple_pay_domain_set = false; |
171 | 171 | |
172 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
172 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
173 | 173 | |
174 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
174 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | public function verify_domain_if_configured() { |
186 | 186 | $secret_key = $this->get_secret_key(); |
187 | 187 | |
188 | - if ( ! $this->is_enabled() || empty( $secret_key ) ) { |
|
188 | + if ( ! $this->is_enabled() || empty($secret_key)) { |
|
189 | 189 | return; |
190 | 190 | } |
191 | 191 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | flush_rewrite_rules(); |
194 | 194 | |
195 | 195 | // Register the domain with Apple Pay. |
196 | - $this->register_domain_with_apple( $secret_key ); |
|
196 | + $this->register_domain_with_apple($secret_key); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @since 4.5.3 |
203 | 203 | * @version 4.5.4 |
204 | 204 | */ |
205 | - public function verify_domain_on_settings_change( $prev_settings, $settings ) { |
|
205 | + public function verify_domain_on_settings_change($prev_settings, $settings) { |
|
206 | 206 | // Grab previous state and then update cached settings. |
207 | 207 | $this->stripe_settings = $prev_settings; |
208 | 208 | $prev_secret_key = $this->get_secret_key(); |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $this->stripe_settings = $settings; |
211 | 211 | |
212 | 212 | // If Stripe or Payment Request Button wasn't enabled (or secret key was different) then might need to verify now. |
213 | - if ( ! $prev_is_enabled || ( $this->get_secret_key() !== $prev_secret_key ) ) { |
|
213 | + if ( ! $prev_is_enabled || ($this->get_secret_key() !== $prev_secret_key)) { |
|
214 | 214 | $this->verify_domain_if_configured(); |
215 | 215 | } |
216 | 216 | } |
@@ -221,16 +221,16 @@ discard block |
||
221 | 221 | * @since 4.0.6 |
222 | 222 | */ |
223 | 223 | public function admin_notices() { |
224 | - if ( ! $this->is_enabled() ) { |
|
224 | + if ( ! $this->is_enabled()) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
228 | + if ( ! current_user_can('manage_woocommerce')) { |
|
229 | 229 | return; |
230 | 230 | } |
231 | 231 | |
232 | - $empty_notice = empty( $this->apple_pay_verify_notice ); |
|
233 | - if ( $empty_notice && ( $this->apple_pay_domain_set || empty( $this->secret_key ) ) ) { |
|
232 | + $empty_notice = empty($this->apple_pay_verify_notice); |
|
233 | + if ($empty_notice && ($this->apple_pay_domain_set || empty($this->secret_key))) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | 236 | |
@@ -239,28 +239,28 @@ discard block |
||
239 | 239 | * when setting screen is displayed. So if domain verification is not set, |
240 | 240 | * something went wrong so lets notify user. |
241 | 241 | */ |
242 | - $allowed_html = array( |
|
242 | + $allowed_html = array( |
|
243 | 243 | 'a' => array( |
244 | 244 | 'href' => array(), |
245 | 245 | 'title' => array(), |
246 | 246 | ), |
247 | 247 | ); |
248 | - $verification_failed_without_error = __( 'Apple Pay domain verification failed.', 'woocommerce-gateway-stripe' ); |
|
249 | - $verification_failed_with_error = __( 'Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe' ); |
|
248 | + $verification_failed_without_error = __('Apple Pay domain verification failed.', 'woocommerce-gateway-stripe'); |
|
249 | + $verification_failed_with_error = __('Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe'); |
|
250 | 250 | $check_log_text = sprintf( |
251 | 251 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
252 | - 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' ), |
|
253 | - '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', |
|
252 | + 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'), |
|
253 | + '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', |
|
254 | 254 | '</a>' |
255 | 255 | ); |
256 | 256 | |
257 | 257 | ?> |
258 | 258 | <div class="error stripe-apple-pay-message"> |
259 | - <?php if ( $empty_notice ) : ?> |
|
260 | - <p><?php echo esc_html( $verification_failed_without_error ); ?></p> |
|
259 | + <?php if ($empty_notice) : ?> |
|
260 | + <p><?php echo esc_html($verification_failed_without_error); ?></p> |
|
261 | 261 | <?php else : ?> |
262 | - <p><?php echo esc_html( $verification_failed_with_error ); ?></p> |
|
263 | - <p><i><?php echo wp_kses( make_clickable( esc_html( $this->apple_pay_verify_notice ) ), $allowed_html ); ?></i></p> |
|
262 | + <p><?php echo esc_html($verification_failed_with_error); ?></p> |
|
263 | + <p><i><?php echo wp_kses(make_clickable(esc_html($this->apple_pay_verify_notice)), $allowed_html); ?></i></p> |
|
264 | 264 | <?php endif; ?> |
265 | 265 | <p><?php echo $check_log_text; ?></p> |
266 | 266 | </div> |