@@ -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 | |
@@ -60,21 +60,21 @@ discard block |
||
60 | 60 | public $apple_pay_verify_notice; |
61 | 61 | |
62 | 62 | public function __construct() { |
63 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
64 | - $this->stripe_enabled = $this->get_option( 'enabled' ); |
|
65 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
66 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
63 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
64 | + $this->stripe_enabled = $this->get_option('enabled'); |
|
65 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
66 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
67 | 67 | $this->apple_pay_verify_notice = ''; |
68 | - $this->testmode = 'yes' === $this->get_option( 'testmode', 'no' ); |
|
69 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
68 | + $this->testmode = 'yes' === $this->get_option('testmode', 'no'); |
|
69 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
70 | 70 | |
71 | - if ( empty( $this->stripe_settings ) ) { |
|
71 | + if (empty($this->stripe_settings)) { |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->init_apple_pay(); |
76 | 76 | |
77 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
77 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | * @param string default |
86 | 86 | * @return string $setting_value |
87 | 87 | */ |
88 | - public function get_option( $setting = '', $default = '' ) { |
|
89 | - if ( empty( $this->stripe_settings ) ) { |
|
88 | + public function get_option($setting = '', $default = '') { |
|
89 | + if (empty($this->stripe_settings)) { |
|
90 | 90 | return $default; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! empty( $this->stripe_settings[ $setting ] ) ) { |
|
94 | - return $this->stripe_settings[ $setting ]; |
|
93 | + if ( ! empty($this->stripe_settings[$setting])) { |
|
94 | + return $this->stripe_settings[$setting]; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return $default; |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | public function init_apple_pay() { |
107 | 107 | if ( |
108 | 108 | is_admin() && |
109 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
110 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
111 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
109 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
110 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
111 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
112 | 112 | $this->payment_request |
113 | 113 | ) { |
114 | 114 | $this->process_apple_pay_verification(); |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | * @version 3.1.0 |
123 | 123 | * @param string $secret_key |
124 | 124 | */ |
125 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
126 | - if ( empty( $secret_key ) ) { |
|
127 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
125 | + private function register_apple_pay_domain($secret_key = '') { |
|
126 | + if (empty($secret_key)) { |
|
127 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -138,23 +138,23 @@ discard block |
||
138 | 138 | 'Authorization' => 'Bearer ' . $secret_key, |
139 | 139 | ); |
140 | 140 | |
141 | - $response = wp_remote_post( $endpoint, array( |
|
141 | + $response = wp_remote_post($endpoint, array( |
|
142 | 142 | 'headers' => $headers, |
143 | - 'body' => http_build_query( $data ), |
|
144 | - ) ); |
|
143 | + 'body' => http_build_query($data), |
|
144 | + )); |
|
145 | 145 | |
146 | - if ( is_wp_error( $response ) ) { |
|
146 | + if (is_wp_error($response)) { |
|
147 | 147 | /* translators: error message */ |
148 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
148 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
149 | 149 | } |
150 | 150 | |
151 | - if ( 200 !== $response['response']['code'] ) { |
|
152 | - $parsed_response = json_decode( $response['body'] ); |
|
151 | + if (200 !== $response['response']['code']) { |
|
152 | + $parsed_response = json_decode($response['body']); |
|
153 | 153 | |
154 | 154 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
155 | 155 | |
156 | 156 | /* translators: error message */ |
157 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
157 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -166,45 +166,45 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function process_apple_pay_verification() { |
168 | 168 | try { |
169 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
169 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
170 | 170 | $dir = '.well-known'; |
171 | 171 | $file = 'apple-developer-merchantid-domain-association'; |
172 | 172 | $fullpath = $path . '/' . $dir . '/' . $file; |
173 | 173 | |
174 | - if ( $this->apple_pay_domain_set && file_exists( $fullpath ) ) { |
|
174 | + if ($this->apple_pay_domain_set && file_exists($fullpath)) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
179 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine |
|
180 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
178 | + if ( ! file_exists($path . '/' . $dir)) { |
|
179 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine |
|
180 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | - if ( ! file_exists( $fullpath ) ) { |
|
185 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine |
|
186 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
184 | + if ( ! file_exists($fullpath)) { |
|
185 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine |
|
186 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | // At this point then the domain association folder and file should be available. |
191 | 191 | // Proceed to verify/and or verify again. |
192 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
192 | + $this->register_apple_pay_domain($this->secret_key); |
|
193 | 193 | |
194 | 194 | // No errors to this point, verification success! |
195 | 195 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
196 | 196 | $this->apple_pay_domain_set = true; |
197 | 197 | |
198 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
198 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
199 | 199 | |
200 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
200 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
201 | 201 | |
202 | - } catch ( Exception $e ) { |
|
202 | + } catch (Exception $e) { |
|
203 | 203 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
204 | 204 | |
205 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
205 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
206 | 206 | |
207 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
207 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
@@ -214,15 +214,15 @@ discard block |
||
214 | 214 | * @since 4.0.6 |
215 | 215 | */ |
216 | 216 | public function admin_notices() { |
217 | - if ( ! $this->stripe_enabled ) { |
|
217 | + if ( ! $this->stripe_enabled) { |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
221 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
221 | + if ( ! current_user_can('manage_woocommerce')) { |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
225 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
225 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
226 | 226 | $allowed_html = array( |
227 | 227 | 'a' => array( |
228 | 228 | 'href' => array(), |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | ), |
231 | 231 | ); |
232 | 232 | |
233 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
233 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | * when setting screen is displayed. So if domain verification is not set, |
239 | 239 | * something went wrong so lets notify user. |
240 | 240 | */ |
241 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
241 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
242 | 242 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
243 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
243 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | } |