@@ -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,16 +60,16 @@ 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 | $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; |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | public function init_apple_pay() { |
102 | 102 | if ( |
103 | 103 | is_admin() && |
104 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
105 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
106 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
104 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
105 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
106 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
107 | 107 | $this->payment_request |
108 | 108 | ) { |
109 | 109 | $this->process_apple_pay_verification(); |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | * @version 3.1.0 |
118 | 118 | * @param string $secret_key |
119 | 119 | */ |
120 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
121 | - if ( empty( $secret_key ) ) { |
|
122 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
120 | + private function register_apple_pay_domain($secret_key = '') { |
|
121 | + if (empty($secret_key)) { |
|
122 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -133,23 +133,23 @@ discard block |
||
133 | 133 | 'Authorization' => 'Bearer ' . $secret_key, |
134 | 134 | ); |
135 | 135 | |
136 | - $response = wp_remote_post( $endpoint, array( |
|
136 | + $response = wp_remote_post($endpoint, array( |
|
137 | 137 | 'headers' => $headers, |
138 | - 'body' => http_build_query( $data ), |
|
139 | - ) ); |
|
138 | + 'body' => http_build_query($data), |
|
139 | + )); |
|
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
141 | + if (is_wp_error($response)) { |
|
142 | 142 | /* translators: error message */ |
143 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
143 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
144 | 144 | } |
145 | 145 | |
146 | - if ( 200 !== $response['response']['code'] ) { |
|
147 | - $parsed_response = json_decode( $response['body'] ); |
|
146 | + if (200 !== $response['response']['code']) { |
|
147 | + $parsed_response = json_decode($response['body']); |
|
148 | 148 | |
149 | 149 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
150 | 150 | |
151 | 151 | /* translators: error message */ |
152 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
152 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -161,45 +161,45 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function process_apple_pay_verification() { |
163 | 163 | try { |
164 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
164 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
165 | 165 | $dir = '.well-known'; |
166 | 166 | $file = 'apple-developer-merchantid-domain-association'; |
167 | 167 | $fullpath = $path . '/' . $dir . '/' . $file; |
168 | 168 | |
169 | - if ( $this->apple_pay_domain_set && file_exists( $fullpath ) ) { |
|
169 | + if ($this->apple_pay_domain_set && file_exists($fullpath)) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
174 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine |
|
175 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
173 | + if ( ! file_exists($path . '/' . $dir)) { |
|
174 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine |
|
175 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - if ( ! file_exists( $fullpath ) ) { |
|
180 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine |
|
181 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
179 | + if ( ! file_exists($fullpath)) { |
|
180 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine |
|
181 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | 185 | // At this point then the domain association folder and file should be available. |
186 | 186 | // Proceed to verify/and or verify again. |
187 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
187 | + $this->register_apple_pay_domain($this->secret_key); |
|
188 | 188 | |
189 | 189 | // No errors to this point, verification success! |
190 | 190 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
191 | 191 | $this->apple_pay_domain_set = true; |
192 | 192 | |
193 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
193 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
194 | 194 | |
195 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
195 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
196 | 196 | |
197 | - } catch ( Exception $e ) { |
|
197 | + } catch (Exception $e) { |
|
198 | 198 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
199 | 199 | |
200 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
200 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
201 | 201 | |
202 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
202 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | * @since 4.0.6 |
210 | 210 | */ |
211 | 211 | public function admin_notices() { |
212 | - if ( ! $this->stripe_enabled ) { |
|
212 | + if ( ! $this->stripe_enabled) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
216 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
217 | 217 | $allowed_html = array( |
218 | 218 | 'a' => array( |
219 | 219 | 'href' => array(), |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | ), |
222 | 222 | ); |
223 | 223 | |
224 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
224 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | * when setting screen is displayed. So if domain verification is not set, |
230 | 230 | * something went wrong so lets notify user. |
231 | 231 | */ |
232 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
232 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
233 | 233 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
234 | - 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>'; |
|
234 | + 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>'; |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | } |