@@ -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,13 +32,13 @@ 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_action( 'woocommerce_stripe_updated', array( $this, 'verify_domain_if_configured' ) ); |
|
37 | - add_action( 'update_option_woocommerce_stripe_settings', array( $this, 'verify_domain_on_settings_change' ), 10, 2 ); |
|
38 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
35 | + add_action('init', array($this, 'add_domain_association_rewrite_rule')); |
|
36 | + add_action('woocommerce_stripe_updated', array($this, 'verify_domain_if_configured')); |
|
37 | + add_action('update_option_woocommerce_stripe_settings', array($this, 'verify_domain_on_settings_change'), 10, 2); |
|
38 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
39 | 39 | |
40 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
41 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
40 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
41 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
42 | 42 | $this->apple_pay_verify_notice = ''; |
43 | 43 | } |
44 | 44 | |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | * @param string default |
51 | 51 | * @return string $setting_value |
52 | 52 | */ |
53 | - public function get_option( $setting = '', $default = '' ) { |
|
54 | - if ( empty( $this->stripe_settings ) ) { |
|
53 | + public function get_option($setting = '', $default = '') { |
|
54 | + if (empty($this->stripe_settings)) { |
|
55 | 55 | return $default; |
56 | 56 | } |
57 | 57 | |
58 | - if ( ! empty( $this->stripe_settings[ $setting ] ) ) { |
|
59 | - return $this->stripe_settings[ $setting ]; |
|
58 | + if ( ! empty($this->stripe_settings[$setting])) { |
|
59 | + return $this->stripe_settings[$setting]; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | return $default; |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * @return string Secret key. |
70 | 70 | */ |
71 | 71 | private function is_enabled() { |
72 | - $stripe_enabled = 'yes' === $this->get_option( 'enabled', 'no' ); |
|
73 | - $payment_request_button_enabled = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
72 | + $stripe_enabled = 'yes' === $this->get_option('enabled', 'no'); |
|
73 | + $payment_request_button_enabled = 'yes' === $this->get_option('payment_request', 'yes'); |
|
74 | 74 | |
75 | 75 | return $stripe_enabled && $payment_request_button_enabled; |
76 | 76 | } |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * @return string Secret key. |
83 | 83 | */ |
84 | 84 | private function get_secret_key() { |
85 | - $testmode = 'yes' === $this->get_option( 'testmode', 'no' ); |
|
86 | - return $testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
85 | + $testmode = 'yes' === $this->get_option('testmode', 'no'); |
|
86 | + return $testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function add_domain_association_rewrite_rule() { |
93 | 93 | $regex = '^\.well-known\/apple-developer-merchantid-domain-association$'; |
94 | - $redirect = parse_url( WC_STRIPE_PLUGIN_URL, PHP_URL_PATH ) . '/apple-developer-merchantid-domain-association'; |
|
94 | + $redirect = parse_url(WC_STRIPE_PLUGIN_URL, PHP_URL_PATH) . '/apple-developer-merchantid-domain-association'; |
|
95 | 95 | |
96 | - add_rewrite_rule( $regex, $redirect, 'top' ); |
|
96 | + add_rewrite_rule($regex, $redirect, 'top'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * @version 4.5.4 |
104 | 104 | * @param string $secret_key |
105 | 105 | */ |
106 | - private function make_domain_registration_request( $secret_key ) { |
|
107 | - if ( empty( $secret_key ) ) { |
|
108 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
106 | + private function make_domain_registration_request($secret_key) { |
|
107 | + if (empty($secret_key)) { |
|
108 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -123,22 +123,22 @@ discard block |
||
123 | 123 | $endpoint, |
124 | 124 | array( |
125 | 125 | 'headers' => $headers, |
126 | - 'body' => http_build_query( $data ), |
|
126 | + 'body' => http_build_query($data), |
|
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | |
130 | - if ( is_wp_error( $response ) ) { |
|
130 | + if (is_wp_error($response)) { |
|
131 | 131 | /* translators: error message */ |
132 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
132 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
133 | 133 | } |
134 | 134 | |
135 | - if ( 200 !== $response['response']['code'] ) { |
|
136 | - $parsed_response = json_decode( $response['body'] ); |
|
135 | + if (200 !== $response['response']['code']) { |
|
136 | + $parsed_response = json_decode($response['body']); |
|
137 | 137 | |
138 | 138 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
139 | 139 | |
140 | 140 | /* translators: error message */ |
141 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
141 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
@@ -150,25 +150,25 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @param string $secret_key |
152 | 152 | */ |
153 | - public function register_domain_with_apple( $secret_key ) { |
|
153 | + public function register_domain_with_apple($secret_key) { |
|
154 | 154 | try { |
155 | - $this->make_domain_registration_request( $secret_key ); |
|
155 | + $this->make_domain_registration_request($secret_key); |
|
156 | 156 | |
157 | 157 | // No errors to this point, verification success! |
158 | 158 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
159 | 159 | $this->apple_pay_domain_set = true; |
160 | 160 | |
161 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
161 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
162 | 162 | |
163 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
163 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
164 | 164 | |
165 | - } catch ( Exception $e ) { |
|
165 | + } catch (Exception $e) { |
|
166 | 166 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
167 | 167 | $this->apple_pay_domain_set = false; |
168 | 168 | |
169 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
169 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
170 | 170 | |
171 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
171 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public function verify_domain_if_configured() { |
183 | 183 | $secret_key = $this->get_secret_key(); |
184 | 184 | |
185 | - if ( ! $this->is_enabled() || empty( $secret_key ) ) { |
|
185 | + if ( ! $this->is_enabled() || empty($secret_key)) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | flush_rewrite_rules(); |
191 | 191 | |
192 | 192 | // Register the domain with Apple Pay. |
193 | - $this->register_domain_with_apple( $secret_key ); |
|
193 | + $this->register_domain_with_apple($secret_key); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @since 4.5.3 |
200 | 200 | * @version 4.5.4 |
201 | 201 | */ |
202 | - public function verify_domain_on_settings_change( $prev_settings, $settings ) { |
|
202 | + public function verify_domain_on_settings_change($prev_settings, $settings) { |
|
203 | 203 | // Grab previous state and then update cached settings. |
204 | 204 | $this->stripe_settings = $prev_settings; |
205 | 205 | $prev_secret_key = $this->get_secret_key(); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | $this->stripe_settings = $settings; |
208 | 208 | |
209 | 209 | // If Stripe or Payment Request Button wasn't enabled (or secret key was different) then might need to verify now. |
210 | - if ( ! $prev_is_enabled || ( $this->get_secret_key() !== $prev_secret_key ) ) { |
|
210 | + if ( ! $prev_is_enabled || ($this->get_secret_key() !== $prev_secret_key)) { |
|
211 | 211 | $this->verify_domain_if_configured(); |
212 | 212 | } |
213 | 213 | } |
@@ -218,16 +218,16 @@ discard block |
||
218 | 218 | * @since 4.0.6 |
219 | 219 | */ |
220 | 220 | public function admin_notices() { |
221 | - if ( ! $this->is_enabled() ) { |
|
221 | + if ( ! $this->is_enabled()) { |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
225 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
225 | + if ( ! current_user_can('manage_woocommerce')) { |
|
226 | 226 | return; |
227 | 227 | } |
228 | 228 | |
229 | - $empty_notice = empty( $this->apple_pay_verify_notice ); |
|
230 | - if ( $empty_notice && ( $this->apple_pay_domain_set || empty( $this->secret_key ) ) ) { |
|
229 | + $empty_notice = empty($this->apple_pay_verify_notice); |
|
230 | + if ($empty_notice && ($this->apple_pay_domain_set || empty($this->secret_key))) { |
|
231 | 231 | return; |
232 | 232 | } |
233 | 233 | |
@@ -236,28 +236,28 @@ discard block |
||
236 | 236 | * when setting screen is displayed. So if domain verification is not set, |
237 | 237 | * something went wrong so lets notify user. |
238 | 238 | */ |
239 | - $allowed_html = array( |
|
239 | + $allowed_html = array( |
|
240 | 240 | 'a' => array( |
241 | 241 | 'href' => array(), |
242 | 242 | 'title' => array(), |
243 | 243 | ), |
244 | 244 | ); |
245 | - $verification_failed_without_error = __( 'Apple Pay domain verification failed.', 'woocommerce-gateway-stripe' ); |
|
246 | - $verification_failed_with_error = __( 'Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe' ); |
|
245 | + $verification_failed_without_error = __('Apple Pay domain verification failed.', 'woocommerce-gateway-stripe'); |
|
246 | + $verification_failed_with_error = __('Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe'); |
|
247 | 247 | $check_log_text = sprintf( |
248 | 248 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
249 | - 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' ), |
|
250 | - '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', |
|
249 | + 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'), |
|
250 | + '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', |
|
251 | 251 | '</a>' |
252 | 252 | ); |
253 | 253 | |
254 | 254 | ?> |
255 | 255 | <div class="error stripe-apple-pay-message"> |
256 | - <?php if ( $empty_notice ) : ?> |
|
257 | - <p><?php echo esc_html( $verification_failed_without_error ); ?></p> |
|
256 | + <?php if ($empty_notice) : ?> |
|
257 | + <p><?php echo esc_html($verification_failed_without_error); ?></p> |
|
258 | 258 | <?php else : ?> |
259 | - <p><?php echo esc_html( $verification_failed_with_error ); ?></p> |
|
260 | - <p><i><?php echo wp_kses( make_clickable( esc_html( $this->apple_pay_verify_notice ) ), $allowed_html ); ?></i></p> |
|
259 | + <p><?php echo esc_html($verification_failed_with_error); ?></p> |
|
260 | + <p><i><?php echo wp_kses(make_clickable(esc_html($this->apple_pay_verify_notice)), $allowed_html); ?></i></p> |
|
261 | 261 | <?php endif; ?> |
262 | 262 | <p><?php echo $check_log_text; ?></p> |
263 | 263 | </div> |