@@ -177,7 +177,7 @@ |
||
177 | 177 | * @param float $total Amount due. |
178 | 178 | * @param string $currency Accepted currency. |
179 | 179 | * |
180 | - * @return float|int |
|
180 | + * @return double |
|
181 | 181 | */ |
182 | 182 | public function get_stripe_amount( $total, $currency = '' ) { |
183 | 183 | if ( ! $currency ) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function __construct() { |
122 | 122 | $this->id = 'stripe'; |
123 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
124 | - $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
123 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
124 | + $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
125 | 125 | $this->has_fields = true; |
126 | 126 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
127 | 127 | $this->supports = array( |
@@ -149,43 +149,43 @@ discard block |
||
149 | 149 | $this->init_settings(); |
150 | 150 | |
151 | 151 | // Get setting values. |
152 | - $this->title = $this->get_option( 'title' ); |
|
153 | - $this->description = $this->get_option( 'description' ); |
|
154 | - $this->enabled = $this->get_option( 'enabled' ); |
|
155 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
157 | - $this->statement_descriptor = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
158 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
159 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
160 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
161 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
162 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
163 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
164 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
165 | - $this->apple_pay = 'yes' === $this->get_option( 'apple_pay', 'yes' ); |
|
166 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
167 | - $this->apple_pay_button = $this->get_option( 'apple_pay_button', 'black' ); |
|
168 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
152 | + $this->title = $this->get_option('title'); |
|
153 | + $this->description = $this->get_option('description'); |
|
154 | + $this->enabled = $this->get_option('enabled'); |
|
155 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
157 | + $this->statement_descriptor = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
158 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
159 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
160 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
161 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
162 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
163 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
164 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
165 | + $this->apple_pay = 'yes' === $this->get_option('apple_pay', 'yes'); |
|
166 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
167 | + $this->apple_pay_button = $this->get_option('apple_pay_button', 'black'); |
|
168 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
169 | 169 | $this->apple_pay_verify_notice = ''; |
170 | 170 | |
171 | - if ( $this->stripe_checkout ) { |
|
172 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
171 | + if ($this->stripe_checkout) { |
|
172 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
173 | 173 | } |
174 | 174 | |
175 | - if ( $this->testmode ) { |
|
176 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
177 | - $this->description = trim( $this->description ); |
|
175 | + if ($this->testmode) { |
|
176 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
177 | + $this->description = trim($this->description); |
|
178 | 178 | } |
179 | 179 | |
180 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
180 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
181 | 181 | |
182 | 182 | $this->init_apple_pay(); |
183 | 183 | |
184 | 184 | // Hooks. |
185 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
186 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
187 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
188 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
185 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
186 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
187 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
188 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -195,26 +195,26 @@ discard block |
||
195 | 195 | * @return string |
196 | 196 | */ |
197 | 197 | public function get_icon() { |
198 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
199 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
198 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
199 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
200 | 200 | |
201 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
202 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
203 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
201 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
202 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
203 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
204 | 204 | |
205 | 205 | $base_location = wc_get_base_location(); |
206 | 206 | |
207 | - if ( 'US' === $base_location['country'] ) { |
|
208 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
209 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
210 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
207 | + if ('US' === $base_location['country']) { |
|
208 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
209 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
210 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
211 | 211 | } |
212 | 212 | |
213 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
214 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
213 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
214 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
215 | 215 | } |
216 | 216 | |
217 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
217 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,11 +225,11 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return float|int |
227 | 227 | */ |
228 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
229 | - if ( ! $currency ) { |
|
228 | + public function get_stripe_amount($total, $currency = '') { |
|
229 | + if ( ! $currency) { |
|
230 | 230 | $currency = get_woocommerce_currency(); |
231 | 231 | } |
232 | - switch ( strtoupper( $currency ) ) { |
|
232 | + switch (strtoupper($currency)) { |
|
233 | 233 | // Zero decimal currencies. |
234 | 234 | case 'BIF' : |
235 | 235 | case 'CLP' : |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | case 'XAF' : |
247 | 247 | case 'XOF' : |
248 | 248 | case 'XPF' : |
249 | - $total = absint( $total ); |
|
249 | + $total = absint($total); |
|
250 | 250 | break; |
251 | 251 | default : |
252 | - $total = round( $total, 2 ) * 100; // In cents. |
|
252 | + $total = round($total, 2) * 100; // In cents. |
|
253 | 253 | break; |
254 | 254 | } |
255 | 255 | return $total; |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | public function init_apple_pay() { |
265 | 265 | if ( |
266 | 266 | is_admin() && |
267 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
268 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
269 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] |
|
267 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
268 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
269 | + isset($_GET['section']) && 'stripe' === $_GET['section'] |
|
270 | 270 | ) { |
271 | 271 | $this->process_apple_pay_verification(); |
272 | 272 | } |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | * @version 3.1.0 |
280 | 280 | * @param string $secret_key |
281 | 281 | */ |
282 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
283 | - if ( empty( $secret_key ) ) { |
|
284 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
282 | + private function register_apple_pay_domain($secret_key = '') { |
|
283 | + if (empty($secret_key)) { |
|
284 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -295,21 +295,21 @@ discard block |
||
295 | 295 | 'Authorization' => 'Bearer ' . $secret_key, |
296 | 296 | ); |
297 | 297 | |
298 | - $response = wp_remote_post( $endpoint, array( |
|
298 | + $response = wp_remote_post($endpoint, array( |
|
299 | 299 | 'headers' => $headers, |
300 | - 'body' => http_build_query( $data ), |
|
301 | - ) ); |
|
300 | + 'body' => http_build_query($data), |
|
301 | + )); |
|
302 | 302 | |
303 | - if ( is_wp_error( $response ) ) { |
|
304 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
303 | + if (is_wp_error($response)) { |
|
304 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( 200 !== $response['response']['code'] ) { |
|
308 | - $parsed_response = json_decode( $response['body'] ); |
|
307 | + if (200 !== $response['response']['code']) { |
|
308 | + $parsed_response = json_decode($response['body']); |
|
309 | 309 | |
310 | 310 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
311 | 311 | |
312 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
312 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
@@ -320,48 +320,48 @@ discard block |
||
320 | 320 | * @version 3.1.0 |
321 | 321 | */ |
322 | 322 | public function process_apple_pay_verification() { |
323 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
323 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
324 | 324 | |
325 | 325 | try { |
326 | - $path = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) ); |
|
326 | + $path = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'])); |
|
327 | 327 | $dir = '.well-known'; |
328 | 328 | $file = 'apple-developer-merchantid-domain-association'; |
329 | 329 | $fullpath = $path . '/' . $dir . '/' . $file; |
330 | 330 | |
331 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
331 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | |
335 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
336 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
337 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
335 | + if ( ! file_exists($path . '/' . $dir)) { |
|
336 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
337 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - if ( ! file_exists( $fullpath ) ) { |
|
342 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
343 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
341 | + if ( ! file_exists($fullpath)) { |
|
342 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
343 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | 347 | // At this point then the domain association folder and file should be available. |
348 | 348 | // Proceed to verify/and or verify again. |
349 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
349 | + $this->register_apple_pay_domain($this->secret_key); |
|
350 | 350 | |
351 | 351 | // No errors to this point, verification success! |
352 | 352 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
353 | 353 | $this->apple_pay_domain_set = true; |
354 | 354 | |
355 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
355 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
356 | 356 | |
357 | - $this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) ); |
|
357 | + $this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe')); |
|
358 | 358 | |
359 | - } catch ( Exception $e ) { |
|
359 | + } catch (Exception $e) { |
|
360 | 360 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
361 | 361 | |
362 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
362 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
363 | 363 | |
364 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
364 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | |
@@ -369,11 +369,11 @@ discard block |
||
369 | 369 | * Check if SSL is enabled and notify the user |
370 | 370 | */ |
371 | 371 | public function admin_notices() { |
372 | - if ( 'no' === $this->enabled ) { |
|
372 | + if ('no' === $this->enabled) { |
|
373 | 373 | return; |
374 | 374 | } |
375 | 375 | |
376 | - if ( $this->apple_pay && ! empty( $this->apple_pay_verify_notice ) ) { |
|
376 | + if ($this->apple_pay && ! empty($this->apple_pay_verify_notice)) { |
|
377 | 377 | $allowed_html = array( |
378 | 378 | 'a' => array( |
379 | 379 | 'href' => array(), |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | ), |
382 | 382 | ); |
383 | 383 | |
384 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
384 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -389,13 +389,13 @@ discard block |
||
389 | 389 | * when setting screen is displayed. So if domain verification is not set, |
390 | 390 | * something went wrong so lets notify user. |
391 | 391 | */ |
392 | - if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) { |
|
393 | - 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>'; |
|
392 | + if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) { |
|
393 | + 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>'; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
397 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
398 | - echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
397 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
398 | + echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
@@ -403,11 +403,11 @@ discard block |
||
403 | 403 | * Check if this gateway is enabled |
404 | 404 | */ |
405 | 405 | public function is_available() { |
406 | - if ( 'yes' === $this->enabled ) { |
|
407 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
406 | + if ('yes' === $this->enabled) { |
|
407 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
408 | 408 | return false; |
409 | 409 | } |
410 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
410 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | return true; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | * Initialise Gateway Settings Form Fields |
420 | 420 | */ |
421 | 421 | public function init_form_fields() { |
422 | - $this->form_fields = include( 'settings-stripe.php' ); |
|
422 | + $this->form_fields = include('settings-stripe.php'); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -427,54 +427,54 @@ discard block |
||
427 | 427 | */ |
428 | 428 | public function payment_fields() { |
429 | 429 | $user = wp_get_current_user(); |
430 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
430 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
431 | 431 | $total = WC()->cart->total; |
432 | 432 | |
433 | 433 | // If paying from order, we need to get total from order not cart. |
434 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
435 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
434 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
435 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
436 | 436 | $total = $order->get_total(); |
437 | 437 | } |
438 | 438 | |
439 | - if ( $user->ID ) { |
|
440 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
439 | + if ($user->ID) { |
|
440 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
441 | 441 | $user_email = $user_email ? $user_email : $user->user_email; |
442 | 442 | } else { |
443 | 443 | $user_email = ''; |
444 | 444 | } |
445 | 445 | |
446 | - if ( is_add_payment_method_page() ) { |
|
447 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
446 | + if (is_add_payment_method_page()) { |
|
447 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
448 | 448 | } else { |
449 | 449 | $pay_button_text = ''; |
450 | 450 | } |
451 | 451 | |
452 | 452 | echo '<div |
453 | 453 | id="stripe-payment-data" |
454 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
454 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
455 | 455 | data-description="" |
456 | - data-email="' . esc_attr( $user_email ) . '" |
|
457 | - data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '" |
|
458 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
459 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
460 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
461 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
462 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
463 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
456 | + data-email="' . esc_attr($user_email) . '" |
|
457 | + data-amount="' . esc_attr($this->get_stripe_amount($total)) . '" |
|
458 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
459 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
460 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
461 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
462 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
463 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
464 | 464 | |
465 | - if ( $this->description ) { |
|
466 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
465 | + if ($this->description) { |
|
466 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
467 | 467 | } |
468 | 468 | |
469 | - if ( $display_tokenization ) { |
|
469 | + if ($display_tokenization) { |
|
470 | 470 | $this->tokenization_script(); |
471 | 471 | $this->saved_payment_methods(); |
472 | 472 | } |
473 | 473 | |
474 | - if ( ! $this->stripe_checkout ) { |
|
474 | + if ( ! $this->stripe_checkout) { |
|
475 | 475 | $this->form(); |
476 | 476 | |
477 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) ) { |
|
477 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization)) { |
|
478 | 478 | $this->save_payment_method_checkbox(); |
479 | 479 | } |
480 | 480 | } |
@@ -490,20 +490,20 @@ discard block |
||
490 | 490 | * @return array |
491 | 491 | */ |
492 | 492 | public function get_localized_messages() { |
493 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
494 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
495 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
496 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
497 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
498 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
499 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
500 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
501 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
502 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
503 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
504 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
505 | - 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
506 | - ) ); |
|
493 | + return apply_filters('wc_stripe_localized_messages', array( |
|
494 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
495 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
496 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
497 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
498 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
499 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
500 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
501 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
502 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
503 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
504 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
505 | + 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
506 | + )); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -513,28 +513,28 @@ discard block |
||
513 | 513 | * @version 3.1.0 |
514 | 514 | */ |
515 | 515 | public function admin_scripts() { |
516 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
516 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
517 | 517 | return; |
518 | 518 | } |
519 | 519 | |
520 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
520 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
521 | 521 | |
522 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
522 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
523 | 523 | |
524 | 524 | $stripe_admin_params = array( |
525 | 525 | 'localized_messages' => array( |
526 | - 'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ), |
|
527 | - 'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ), |
|
528 | - 're_verify_button_text' => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ), |
|
529 | - 'missing_secret_key' => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ), |
|
526 | + 'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'), |
|
527 | + 'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'), |
|
528 | + 're_verify_button_text' => __('Re-verify Domain', 'woocommerce-gateway-stripe'), |
|
529 | + 'missing_secret_key' => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'), |
|
530 | 530 | ), |
531 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
531 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
532 | 532 | 'nonce' => array( |
533 | - 'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ), |
|
533 | + 'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'), |
|
534 | 534 | ), |
535 | 535 | ); |
536 | 536 | |
537 | - wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) ); |
|
537 | + wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params)); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
@@ -545,49 +545,49 @@ discard block |
||
545 | 545 | * @access public |
546 | 546 | */ |
547 | 547 | public function payment_scripts() { |
548 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
548 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
549 | 549 | return; |
550 | 550 | } |
551 | 551 | |
552 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
552 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
553 | 553 | |
554 | - if ( $this->stripe_checkout ) { |
|
555 | - wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
556 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe_checkout' ), WC_STRIPE_VERSION, true ); |
|
554 | + if ($this->stripe_checkout) { |
|
555 | + wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
556 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe_checkout'), WC_STRIPE_VERSION, true); |
|
557 | 557 | } else { |
558 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
559 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
558 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
559 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | $stripe_params = array( |
563 | 563 | 'key' => $this->publishable_key, |
564 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
565 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
564 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
565 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
566 | 566 | ); |
567 | 567 | |
568 | 568 | // If we're on the pay page we need to pass stripe.js the address of the order. |
569 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
570 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
571 | - $order = wc_get_order( $order_id ); |
|
569 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
570 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
571 | + $order = wc_get_order($order_id); |
|
572 | 572 | |
573 | - $stripe_params['billing_first_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
574 | - $stripe_params['billing_last_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
575 | - $stripe_params['billing_address_1'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
576 | - $stripe_params['billing_address_2'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
577 | - $stripe_params['billing_state'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_state : $order->get_billing_state(); |
|
578 | - $stripe_params['billing_city'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_city : $order->get_billing_city(); |
|
579 | - $stripe_params['billing_postcode'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
580 | - $stripe_params['billing_country'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_country : $order->get_billing_country(); |
|
573 | + $stripe_params['billing_first_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
574 | + $stripe_params['billing_last_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
575 | + $stripe_params['billing_address_1'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
576 | + $stripe_params['billing_address_2'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
577 | + $stripe_params['billing_state'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_state : $order->get_billing_state(); |
|
578 | + $stripe_params['billing_city'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_city : $order->get_billing_city(); |
|
579 | + $stripe_params['billing_postcode'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
580 | + $stripe_params['billing_country'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_country : $order->get_billing_country(); |
|
581 | 581 | } |
582 | 582 | |
583 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
584 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
585 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
583 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
584 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
585 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
586 | 586 | |
587 | 587 | // merge localized messages to be use in JS |
588 | - $stripe_params = array_merge( $stripe_params, $this->get_localized_messages() ); |
|
588 | + $stripe_params = array_merge($stripe_params, $this->get_localized_messages()); |
|
589 | 589 | |
590 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
590 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | /** |
@@ -596,35 +596,35 @@ discard block |
||
596 | 596 | * @param object $source |
597 | 597 | * @return array() |
598 | 598 | */ |
599 | - protected function generate_payment_request( $order, $source ) { |
|
599 | + protected function generate_payment_request($order, $source) { |
|
600 | 600 | $post_data = array(); |
601 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
602 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
603 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
601 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
602 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
603 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
604 | 604 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
605 | 605 | |
606 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
607 | - $billing_first_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
608 | - $billing_last_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
606 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
607 | + $billing_first_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
608 | + $billing_last_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
609 | 609 | |
610 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
610 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
611 | 611 | $post_data['receipt_email'] = $billing_email; |
612 | 612 | } |
613 | 613 | |
614 | - $post_data['expand[]'] = 'balance_transaction'; |
|
614 | + $post_data['expand[]'] = 'balance_transaction'; |
|
615 | 615 | |
616 | 616 | $metadata = array( |
617 | - __( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
618 | - __( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
617 | + __('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
618 | + __('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
619 | 619 | ); |
620 | 620 | |
621 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
621 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
622 | 622 | |
623 | - if ( $source->customer ) { |
|
623 | + if ($source->customer) { |
|
624 | 624 | $post_data['customer'] = $source->customer; |
625 | 625 | } |
626 | 626 | |
627 | - if ( $source->source ) { |
|
627 | + if ($source->source) { |
|
628 | 628 | $post_data['source'] = $source->source; |
629 | 629 | } |
630 | 630 | |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | * @param WC_Order $order |
637 | 637 | * @param object $source |
638 | 638 | */ |
639 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
639 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | /** |
@@ -648,38 +648,38 @@ discard block |
||
648 | 648 | * @throws Exception When card was not added or for and invalid card. |
649 | 649 | * @return object |
650 | 650 | */ |
651 | - protected function get_source( $user_id, $force_customer = false ) { |
|
652 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
653 | - $force_customer = apply_filters( 'wc_stripe_force_customer_creation', $force_customer, $stripe_customer ); |
|
651 | + protected function get_source($user_id, $force_customer = false) { |
|
652 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
653 | + $force_customer = apply_filters('wc_stripe_force_customer_creation', $force_customer, $stripe_customer); |
|
654 | 654 | $stripe_source = false; |
655 | 655 | $token_id = false; |
656 | 656 | |
657 | 657 | // New CC info was entered and we have a new token to process |
658 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
659 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
660 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
658 | + if (isset($_POST['stripe_token'])) { |
|
659 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
660 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
661 | 661 | |
662 | 662 | // This is true if the user wants to store the card to their account. |
663 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
664 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
663 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
664 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
665 | 665 | |
666 | - if ( is_wp_error( $stripe_source ) ) { |
|
667 | - throw new Exception( $stripe_source->get_error_message() ); |
|
666 | + if (is_wp_error($stripe_source)) { |
|
667 | + throw new Exception($stripe_source->get_error_message()); |
|
668 | 668 | } |
669 | 669 | } else { |
670 | 670 | // Not saving token, so don't define customer either. |
671 | 671 | $stripe_source = $stripe_token; |
672 | 672 | $stripe_customer = false; |
673 | 673 | } |
674 | - } elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
674 | + } elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
675 | 675 | // Use an existing token, and then process the payment |
676 | 676 | |
677 | - $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
678 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
677 | + $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
678 | + $token = WC_Payment_Tokens::get($token_id); |
|
679 | 679 | |
680 | - if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
681 | - WC()->session->set( 'refresh_totals', true ); |
|
682 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
680 | + if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
681 | + WC()->session->set('refresh_totals', true); |
|
682 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | $stripe_source = $token->get_token(); |
@@ -703,19 +703,19 @@ discard block |
||
703 | 703 | * @param object $order |
704 | 704 | * @return object |
705 | 705 | */ |
706 | - protected function get_order_source( $order = null ) { |
|
706 | + protected function get_order_source($order = null) { |
|
707 | 707 | $stripe_customer = new WC_Stripe_Customer(); |
708 | 708 | $stripe_source = false; |
709 | 709 | $token_id = false; |
710 | 710 | |
711 | - if ( $order ) { |
|
712 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
711 | + if ($order) { |
|
712 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
713 | 713 | |
714 | - if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) { |
|
715 | - $stripe_customer->set_id( $meta_value ); |
|
714 | + if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) { |
|
715 | + $stripe_customer->set_id($meta_value); |
|
716 | 716 | } |
717 | 717 | |
718 | - if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) { |
|
718 | + if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) { |
|
719 | 719 | $stripe_source = $meta_value; |
720 | 720 | } |
721 | 721 | } |
@@ -738,60 +738,60 @@ discard block |
||
738 | 738 | * |
739 | 739 | * @return array|void |
740 | 740 | */ |
741 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
741 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
742 | 742 | try { |
743 | - $order = wc_get_order( $order_id ); |
|
744 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
743 | + $order = wc_get_order($order_id); |
|
744 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
745 | 745 | |
746 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
747 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
748 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
749 | - throw new Exception( $error_msg ); |
|
746 | + if (empty($source->source) && empty($source->customer)) { |
|
747 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
748 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
749 | + throw new Exception($error_msg); |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | // Store source to order meta. |
753 | - $this->save_source( $order, $source ); |
|
753 | + $this->save_source($order, $source); |
|
754 | 754 | |
755 | 755 | // Result from Stripe API request. |
756 | 756 | $response = null; |
757 | 757 | |
758 | 758 | // Handle payment. |
759 | - if ( $order->get_total() > 0 ) { |
|
759 | + if ($order->get_total() > 0) { |
|
760 | 760 | |
761 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
762 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
761 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
762 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
763 | 763 | } |
764 | 764 | |
765 | - $this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
765 | + $this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
766 | 766 | |
767 | 767 | // Make the request. |
768 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
768 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
769 | 769 | |
770 | - if ( is_wp_error( $response ) ) { |
|
770 | + if (is_wp_error($response)) { |
|
771 | 771 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
772 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
773 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
774 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
772 | + if ('customer' === $response->get_error_code() && $retry) { |
|
773 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
774 | + return $this->process_payment($order_id, false, $force_customer); |
|
775 | 775 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
776 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
777 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
776 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
777 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
778 | 778 | $token->delete(); |
779 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
780 | - $order->add_order_note( $message ); |
|
781 | - throw new Exception( $message ); |
|
779 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
780 | + $order->add_order_note($message); |
|
781 | + throw new Exception($message); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | $localized_messages = $this->get_localized_messages(); |
785 | 785 | |
786 | - $message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message(); |
|
786 | + $message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message(); |
|
787 | 787 | |
788 | - $order->add_order_note( $message ); |
|
788 | + $order->add_order_note($message); |
|
789 | 789 | |
790 | - throw new Exception( $message ); |
|
790 | + throw new Exception($message); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | // Process valid response. |
794 | - $this->process_response( $response, $order ); |
|
794 | + $this->process_response($response, $order); |
|
795 | 795 | } else { |
796 | 796 | $order->payment_complete(); |
797 | 797 | } |
@@ -799,23 +799,23 @@ discard block |
||
799 | 799 | // Remove cart. |
800 | 800 | WC()->cart->empty_cart(); |
801 | 801 | |
802 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
802 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
803 | 803 | |
804 | 804 | // Return thank you page redirect. |
805 | 805 | return array( |
806 | 806 | 'result' => 'success', |
807 | - 'redirect' => $this->get_return_url( $order ), |
|
807 | + 'redirect' => $this->get_return_url($order), |
|
808 | 808 | ); |
809 | 809 | |
810 | - } catch ( Exception $e ) { |
|
811 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
812 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
810 | + } catch (Exception $e) { |
|
811 | + wc_add_notice($e->getMessage(), 'error'); |
|
812 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
813 | 813 | |
814 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
815 | - $this->send_failed_order_email( $order_id ); |
|
814 | + if ($order->has_status(array('pending', 'failed'))) { |
|
815 | + $this->send_failed_order_email($order_id); |
|
816 | 816 | } |
817 | 817 | |
818 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
818 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
819 | 819 | |
820 | 820 | return array( |
821 | 821 | 'result' => 'fail', |
@@ -830,56 +830,56 @@ discard block |
||
830 | 830 | * @param WC_Order $order For to which the source applies. |
831 | 831 | * @param stdClass $source Source information. |
832 | 832 | */ |
833 | - protected function save_source( $order, $source ) { |
|
834 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
833 | + protected function save_source($order, $source) { |
|
834 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
835 | 835 | |
836 | 836 | // Store source in the order. |
837 | - if ( $source->customer ) { |
|
838 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
837 | + if ($source->customer) { |
|
838 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
839 | 839 | } |
840 | - if ( $source->source ) { |
|
841 | - update_post_meta( $order_id, '_stripe_card_id', $source->source ); |
|
840 | + if ($source->source) { |
|
841 | + update_post_meta($order_id, '_stripe_card_id', $source->source); |
|
842 | 842 | } |
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | 846 | * Store extra meta data for an order from a Stripe Response. |
847 | 847 | */ |
848 | - public function process_response( $response, $order ) { |
|
849 | - $this->log( 'Processing response: ' . print_r( $response, true ) ); |
|
848 | + public function process_response($response, $order) { |
|
849 | + $this->log('Processing response: ' . print_r($response, true)); |
|
850 | 850 | |
851 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
851 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
852 | 852 | |
853 | 853 | // Store charge data |
854 | - update_post_meta( $order_id, '_stripe_charge_id', $response->id ); |
|
855 | - update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
854 | + update_post_meta($order_id, '_stripe_charge_id', $response->id); |
|
855 | + update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
856 | 856 | |
857 | 857 | // Store other data such as fees |
858 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
858 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
859 | 859 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
860 | 860 | // values are in the local currency of the Stripe account, not from WC. |
861 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe::format_number( $response->balance_transaction, 'fee' ) : 0; |
|
862 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe::format_number( $response->balance_transaction, 'net' ) : 0; |
|
863 | - update_post_meta( $order_id, 'Stripe Fee', $fee ); |
|
864 | - update_post_meta( $order_id, 'Net Revenue From Stripe', $net ); |
|
861 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe::format_number($response->balance_transaction, 'fee') : 0; |
|
862 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe::format_number($response->balance_transaction, 'net') : 0; |
|
863 | + update_post_meta($order_id, 'Stripe Fee', $fee); |
|
864 | + update_post_meta($order_id, 'Net Revenue From Stripe', $net); |
|
865 | 865 | } |
866 | 866 | |
867 | - if ( $response->captured ) { |
|
868 | - $order->payment_complete( $response->id ); |
|
867 | + if ($response->captured) { |
|
868 | + $order->payment_complete($response->id); |
|
869 | 869 | |
870 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
871 | - $order->add_order_note( $message ); |
|
872 | - $this->log( 'Success: ' . $message ); |
|
870 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
871 | + $order->add_order_note($message); |
|
872 | + $this->log('Success: ' . $message); |
|
873 | 873 | |
874 | 874 | } else { |
875 | - add_post_meta( $order_id, '_transaction_id', $response->id, true ); |
|
875 | + add_post_meta($order_id, '_transaction_id', $response->id, true); |
|
876 | 876 | |
877 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
878 | - version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
877 | + if ($order->has_status(array('pending', 'failed'))) { |
|
878 | + version_compare(WC_VERSION, '3.0.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
879 | 879 | } |
880 | 880 | |
881 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
882 | - $this->log( "Successful auth: $response->id" ); |
|
881 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
882 | + $this->log("Successful auth: $response->id"); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | return $response; |
@@ -891,32 +891,32 @@ discard block |
||
891 | 891 | * @since 3.0.0 |
892 | 892 | */ |
893 | 893 | public function add_payment_method() { |
894 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
895 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
894 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
895 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
896 | 896 | return; |
897 | 897 | } |
898 | 898 | |
899 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
900 | - $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
899 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
900 | + $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
901 | 901 | |
902 | - if ( is_wp_error( $card ) ) { |
|
902 | + if (is_wp_error($card)) { |
|
903 | 903 | $localized_messages = $this->get_localized_messages(); |
904 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
904 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
905 | 905 | |
906 | 906 | // loop through the errors to find matching localized message |
907 | - foreach ( $card->errors as $error => $msg ) { |
|
908 | - if ( isset( $localized_messages[ $error ] ) ) { |
|
909 | - $error_msg = $localized_messages[ $error ]; |
|
907 | + foreach ($card->errors as $error => $msg) { |
|
908 | + if (isset($localized_messages[$error])) { |
|
909 | + $error_msg = $localized_messages[$error]; |
|
910 | 910 | } |
911 | 911 | } |
912 | 912 | |
913 | - wc_add_notice( $error_msg, 'error' ); |
|
913 | + wc_add_notice($error_msg, 'error'); |
|
914 | 914 | return; |
915 | 915 | } |
916 | 916 | |
917 | 917 | return array( |
918 | 918 | 'result' => 'success', |
919 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
919 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
920 | 920 | ); |
921 | 921 | } |
922 | 922 | |
@@ -926,36 +926,36 @@ discard block |
||
926 | 926 | * @param float $amount |
927 | 927 | * @return bool |
928 | 928 | */ |
929 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
930 | - $order = wc_get_order( $order_id ); |
|
929 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
930 | + $order = wc_get_order($order_id); |
|
931 | 931 | |
932 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
932 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
933 | 933 | return false; |
934 | 934 | } |
935 | 935 | |
936 | 936 | $body = array(); |
937 | 937 | |
938 | - if ( ! is_null( $amount ) ) { |
|
939 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
938 | + if ( ! is_null($amount)) { |
|
939 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
940 | 940 | } |
941 | 941 | |
942 | - if ( $reason ) { |
|
942 | + if ($reason) { |
|
943 | 943 | $body['metadata'] = array( |
944 | 944 | 'reason' => $reason, |
945 | 945 | ); |
946 | 946 | } |
947 | 947 | |
948 | - $this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
948 | + $this->log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
949 | 949 | |
950 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
950 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
951 | 951 | |
952 | - if ( is_wp_error( $response ) ) { |
|
953 | - $this->log( 'Error: ' . $response->get_error_message() ); |
|
952 | + if (is_wp_error($response)) { |
|
953 | + $this->log('Error: ' . $response->get_error_message()); |
|
954 | 954 | return $response; |
955 | - } elseif ( ! empty( $response->id ) ) { |
|
956 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
957 | - $order->add_order_note( $refund_message ); |
|
958 | - $this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
955 | + } elseif ( ! empty($response->id)) { |
|
956 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
957 | + $order->add_order_note($refund_message); |
|
958 | + $this->log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
959 | 959 | return true; |
960 | 960 | } |
961 | 961 | } |
@@ -968,10 +968,10 @@ discard block |
||
968 | 968 | * @param int $order_id |
969 | 969 | * @return null |
970 | 970 | */ |
971 | - public function send_failed_order_email( $order_id ) { |
|
971 | + public function send_failed_order_email($order_id) { |
|
972 | 972 | $emails = WC()->mailer()->get_emails(); |
973 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
974 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
973 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
974 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
975 | 975 | } |
976 | 976 | } |
977 | 977 | |
@@ -983,9 +983,9 @@ discard block |
||
983 | 983 | * |
984 | 984 | * @param string $message |
985 | 985 | */ |
986 | - public function log( $message ) { |
|
987 | - if ( $this->logging ) { |
|
988 | - WC_Stripe::log( $message ); |
|
986 | + public function log($message) { |
|
987 | + if ($this->logging) { |
|
988 | + WC_Stripe::log($message); |
|
989 | 989 | } |
990 | 990 | } |
991 | 991 | } |
@@ -23,7 +23,6 @@ |
||
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Set secret API Key. |
26 | - * @param string $key |
|
27 | 26 | */ |
28 | 27 | public static function set_secret_key( $secret_key ) { |
29 | 28 | self::$secret_key = $secret_key; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * Set secret API Key. |
26 | 26 | * @param string $key |
27 | 27 | */ |
28 | - public static function set_secret_key( $secret_key ) { |
|
28 | + public static function set_secret_key($secret_key) { |
|
29 | 29 | self::$secret_key = $secret_key; |
30 | 30 | } |
31 | 31 | |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | * @return string |
35 | 35 | */ |
36 | 36 | public static function get_secret_key() { |
37 | - if ( ! self::$secret_key ) { |
|
38 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
37 | + if ( ! self::$secret_key) { |
|
38 | + $options = get_option('woocommerce_stripe_settings'); |
|
39 | 39 | |
40 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
41 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
40 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
41 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | return self::$secret_key; |
@@ -51,38 +51,38 @@ discard block |
||
51 | 51 | * @param string $api |
52 | 52 | * @return array|WP_Error |
53 | 53 | */ |
54 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
55 | - self::log( "{$api} request: " . print_r( $request, true ) ); |
|
54 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
55 | + self::log("{$api} request: " . print_r($request, true)); |
|
56 | 56 | |
57 | 57 | $response = wp_safe_remote_post( |
58 | 58 | self::ENDPOINT . $api, |
59 | 59 | array( |
60 | 60 | 'method' => $method, |
61 | 61 | 'headers' => array( |
62 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
62 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
63 | 63 | 'Stripe-Version' => '2016-03-07', |
64 | 64 | ), |
65 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
65 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
66 | 66 | 'timeout' => 70, |
67 | 67 | 'user-agent' => 'WooCommerce ' . WC()->version, |
68 | 68 | ) |
69 | 69 | ); |
70 | 70 | |
71 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
72 | - self::log( 'Error Response: ' . print_r( $response, true ) ); |
|
73 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe' ) ); |
|
71 | + if (is_wp_error($response) || empty($response['body'])) { |
|
72 | + self::log('Error Response: ' . print_r($response, true)); |
|
73 | + return new WP_Error('stripe_error', __('There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe')); |
|
74 | 74 | } |
75 | 75 | |
76 | - $parsed_response = json_decode( $response['body'] ); |
|
76 | + $parsed_response = json_decode($response['body']); |
|
77 | 77 | |
78 | 78 | // Handle response |
79 | - if ( ! empty( $parsed_response->error ) ) { |
|
80 | - if ( ! empty( $parsed_response->error->code ) ) { |
|
79 | + if ( ! empty($parsed_response->error)) { |
|
80 | + if ( ! empty($parsed_response->error->code)) { |
|
81 | 81 | $code = $parsed_response->error->code; |
82 | 82 | } else { |
83 | 83 | $code = 'stripe_error'; |
84 | 84 | } |
85 | - return new WP_Error( $code, $parsed_response->error->message ); |
|
85 | + return new WP_Error($code, $parsed_response->error->message); |
|
86 | 86 | } else { |
87 | 87 | return $parsed_response; |
88 | 88 | } |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @param string $message |
98 | 98 | */ |
99 | - public static function log( $message ) { |
|
100 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
99 | + public static function log($message) { |
|
100 | + $options = get_option('woocommerce_stripe_settings'); |
|
101 | 101 | |
102 | - if ( 'yes' === $options['logging'] ) { |
|
103 | - WC_Stripe::log( $message ); |
|
102 | + if ('yes' === $options['logging']) { |
|
103 | + WC_Stripe::log($message); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |
@@ -210,7 +210,6 @@ |
||
210 | 210 | /** |
211 | 211 | * Get a customers saved cards using their Stripe ID. Cached. |
212 | 212 | * |
213 | - * @param string $customer_id |
|
214 | 213 | * @return array |
215 | 214 | */ |
216 | 215 | public function get_cards() { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param integer $user_id |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
55 | - $this->id = wc_clean( $id ); |
|
54 | + public function set_id($id) { |
|
55 | + $this->id = wc_clean($id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | */ |
62 | 62 | public function get_user_id() { |
63 | - return absint( $this->user_id ); |
|
63 | + return absint($this->user_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Set User ID used by WordPress. |
68 | 68 | * @param int $user_id |
69 | 69 | */ |
70 | - public function set_user_id( $user_id ) { |
|
71 | - $this->user_id = absint( $user_id ); |
|
70 | + public function set_user_id($user_id) { |
|
71 | + $this->user_id = absint($user_id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * Get data from the Stripe API about this customer |
91 | 91 | */ |
92 | 92 | public function get_customer_data() { |
93 | - if ( empty( $this->customer_data ) && $this->get_id() && false === ( $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ) ) ) { |
|
94 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
93 | + if (empty($this->customer_data) && $this->get_id() && false === ($this->customer_data = get_transient('stripe_customer_' . $this->get_id()))) { |
|
94 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
95 | 95 | |
96 | - if ( ! is_wp_error( $response ) ) { |
|
97 | - $this->set_customer_data( $response ); |
|
98 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
96 | + if ( ! is_wp_error($response)) { |
|
97 | + $this->set_customer_data($response); |
|
98 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | return $this->customer_data; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $data = $this->get_customer_data(); |
110 | 110 | $source = ''; |
111 | 111 | |
112 | - if ( $data ) { |
|
112 | + if ($data) { |
|
113 | 113 | $source = $data->default_source; |
114 | 114 | } |
115 | 115 | |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | * @param array $args |
122 | 122 | * @return WP_Error|int |
123 | 123 | */ |
124 | - public function create_customer( $args = array() ) { |
|
125 | - if ( $user = $this->get_user() ) { |
|
126 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
127 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
124 | + public function create_customer($args = array()) { |
|
125 | + if ($user = $this->get_user()) { |
|
126 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
127 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
128 | 128 | |
129 | 129 | $defaults = array( |
130 | 130 | 'email' => $user->user_email, |
@@ -139,26 +139,26 @@ discard block |
||
139 | 139 | |
140 | 140 | $metadata = array(); |
141 | 141 | |
142 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
142 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
143 | 143 | |
144 | - $args = wp_parse_args( $args, $defaults ); |
|
145 | - $response = WC_Stripe_API::request( $args, 'customers' ); |
|
144 | + $args = wp_parse_args($args, $defaults); |
|
145 | + $response = WC_Stripe_API::request($args, 'customers'); |
|
146 | 146 | |
147 | - if ( is_wp_error( $response ) ) { |
|
147 | + if (is_wp_error($response)) { |
|
148 | 148 | return $response; |
149 | - } elseif ( empty( $response->id ) ) { |
|
150 | - return new WP_Error( 'stripe_error', __( 'Could not create Stripe customer.', 'woocommerce-gateway-stripe' ) ); |
|
149 | + } elseif (empty($response->id)) { |
|
150 | + return new WP_Error('stripe_error', __('Could not create Stripe customer.', 'woocommerce-gateway-stripe')); |
|
151 | 151 | } |
152 | 152 | |
153 | - $this->set_id( $response->id ); |
|
153 | + $this->set_id($response->id); |
|
154 | 154 | $this->clear_cache(); |
155 | - $this->set_customer_data( $response ); |
|
155 | + $this->set_customer_data($response); |
|
156 | 156 | |
157 | - if ( $this->get_user_id() ) { |
|
158 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
157 | + if ($this->get_user_id()) { |
|
158 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
159 | 159 | } |
160 | 160 | |
161 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
161 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
162 | 162 | |
163 | 163 | return $response->id; |
164 | 164 | } |
@@ -169,44 +169,44 @@ discard block |
||
169 | 169 | * @param bool $retry |
170 | 170 | * @return WP_Error|int |
171 | 171 | */ |
172 | - public function add_card( $token, $retry = true ) { |
|
173 | - if ( ! $this->get_id() ) { |
|
174 | - if ( ( $response = $this->create_customer() ) && is_wp_error( $response ) ) { |
|
172 | + public function add_card($token, $retry = true) { |
|
173 | + if ( ! $this->get_id()) { |
|
174 | + if (($response = $this->create_customer()) && is_wp_error($response)) { |
|
175 | 175 | return $response; |
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - $response = WC_Stripe_API::request( array( |
|
179 | + $response = WC_Stripe_API::request(array( |
|
180 | 180 | 'source' => $token, |
181 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
181 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
182 | 182 | |
183 | - if ( is_wp_error( $response ) ) { |
|
184 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
183 | + if (is_wp_error($response)) { |
|
184 | + if ('customer' === $response->get_error_code() && $retry) { |
|
185 | 185 | $this->create_customer(); |
186 | - return $this->add_card( $token, false ); |
|
186 | + return $this->add_card($token, false); |
|
187 | 187 | } else { |
188 | 188 | return $response; |
189 | 189 | } |
190 | - } elseif ( empty( $response->id ) ) { |
|
191 | - return new WP_Error( 'error', __( 'Unable to add card', 'woocommerce-gateway-stripe' ) ); |
|
190 | + } elseif (empty($response->id)) { |
|
191 | + return new WP_Error('error', __('Unable to add card', 'woocommerce-gateway-stripe')); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | // Add token to WooCommerce |
195 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
195 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
196 | 196 | $token = new WC_Payment_Token_CC(); |
197 | - $token->set_token( $response->id ); |
|
198 | - $token->set_gateway_id( 'stripe' ); |
|
199 | - $token->set_card_type( strtolower( $response->brand ) ); |
|
200 | - $token->set_last4( $response->last4 ); |
|
201 | - $token->set_expiry_month( $response->exp_month ); |
|
202 | - $token->set_expiry_year( $response->exp_year ); |
|
203 | - $token->set_user_id( $this->get_user_id() ); |
|
197 | + $token->set_token($response->id); |
|
198 | + $token->set_gateway_id('stripe'); |
|
199 | + $token->set_card_type(strtolower($response->brand)); |
|
200 | + $token->set_last4($response->last4); |
|
201 | + $token->set_expiry_month($response->exp_month); |
|
202 | + $token->set_expiry_year($response->exp_year); |
|
203 | + $token->set_user_id($this->get_user_id()); |
|
204 | 204 | $token->save(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | $this->clear_cache(); |
208 | 208 | |
209 | - do_action( 'woocommerce_stripe_add_card', $this->get_id(), $token, $response ); |
|
209 | + do_action('woocommerce_stripe_add_card', $this->get_id(), $token, $response); |
|
210 | 210 | |
211 | 211 | return $response->id; |
212 | 212 | } |
@@ -220,20 +220,20 @@ discard block |
||
220 | 220 | public function get_cards() { |
221 | 221 | $cards = array(); |
222 | 222 | |
223 | - if ( $this->get_id() && false === ( $cards = get_transient( 'stripe_cards_' . $this->get_id() ) ) ) { |
|
224 | - $response = WC_Stripe_API::request( array( |
|
223 | + if ($this->get_id() && false === ($cards = get_transient('stripe_cards_' . $this->get_id()))) { |
|
224 | + $response = WC_Stripe_API::request(array( |
|
225 | 225 | 'limit' => 100, |
226 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
226 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
227 | 227 | |
228 | - if ( is_wp_error( $response ) ) { |
|
228 | + if (is_wp_error($response)) { |
|
229 | 229 | return array(); |
230 | 230 | } |
231 | 231 | |
232 | - if ( is_array( $response->data ) ) { |
|
232 | + if (is_array($response->data)) { |
|
233 | 233 | $cards = $response->data; |
234 | 234 | } |
235 | 235 | |
236 | - set_transient( 'stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48 ); |
|
236 | + set_transient('stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | return $cards; |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | * Delete a card from stripe. |
244 | 244 | * @param string $card_id |
245 | 245 | */ |
246 | - public function delete_card( $card_id ) { |
|
247 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $card_id ), 'DELETE' ); |
|
246 | + public function delete_card($card_id) { |
|
247 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($card_id), 'DELETE'); |
|
248 | 248 | |
249 | 249 | $this->clear_cache(); |
250 | 250 | |
251 | - if ( ! is_wp_error( $response ) ) { |
|
252 | - do_action( 'wc_stripe_delete_card', $this->get_id(), $response ); |
|
251 | + if ( ! is_wp_error($response)) { |
|
252 | + do_action('wc_stripe_delete_card', $this->get_id(), $response); |
|
253 | 253 | |
254 | 254 | return true; |
255 | 255 | } |
@@ -261,15 +261,15 @@ discard block |
||
261 | 261 | * Set default card in Stripe |
262 | 262 | * @param string $card_id |
263 | 263 | */ |
264 | - public function set_default_card( $card_id ) { |
|
265 | - $response = WC_Stripe_API::request( array( |
|
266 | - 'default_source' => sanitize_text_field( $card_id ), |
|
267 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
264 | + public function set_default_card($card_id) { |
|
265 | + $response = WC_Stripe_API::request(array( |
|
266 | + 'default_source' => sanitize_text_field($card_id), |
|
267 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
268 | 268 | |
269 | 269 | $this->clear_cache(); |
270 | 270 | |
271 | - if ( ! is_wp_error( $response ) ) { |
|
272 | - do_action( 'wc_stripe_set_default_card', $this->get_id(), $response ); |
|
271 | + if ( ! is_wp_error($response)) { |
|
272 | + do_action('wc_stripe_set_default_card', $this->get_id(), $response); |
|
273 | 273 | |
274 | 274 | return true; |
275 | 275 | } |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * Deletes caches for this users cards. |
282 | 282 | */ |
283 | 283 | public function clear_cache() { |
284 | - delete_transient( 'stripe_cards_' . $this->get_id() ); |
|
285 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
284 | + delete_transient('stripe_cards_' . $this->get_id()); |
|
285 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
286 | 286 | $this->customer_data = array(); |
287 | 287 | } |
288 | 288 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -12,25 +12,25 @@ discard block |
||
12 | 12 | * Constructor |
13 | 13 | */ |
14 | 14 | public function __construct() { |
15 | - add_action( 'wp', array( $this, 'delete_card' ) ); |
|
16 | - add_action( 'woocommerce_after_my_account', array( $this, 'output' ) ); |
|
17 | - add_action( 'wp', array( $this, 'default_card' ) ); |
|
15 | + add_action('wp', array($this, 'delete_card')); |
|
16 | + add_action('woocommerce_after_my_account', array($this, 'output')); |
|
17 | + add_action('wp', array($this, 'default_card')); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Display saved cards |
22 | 22 | */ |
23 | 23 | public function output() { |
24 | - if ( ! is_user_logged_in() ) { |
|
24 | + if ( ! is_user_logged_in()) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
28 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
28 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
29 | 29 | $stripe_cards = $stripe_customer->get_cards(); |
30 | 30 | $default_card = $stripe_customer->get_default_card(); |
31 | 31 | |
32 | - if ( $stripe_cards ) { |
|
33 | - wc_get_template( 'saved-cards.php', array( 'cards' => $stripe_cards, 'default_card' => $default_card ), 'woocommerce-gateway-stripe/', untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/legacy/templates/' ); |
|
32 | + if ($stripe_cards) { |
|
33 | + wc_get_template('saved-cards.php', array('cards' => $stripe_cards, 'default_card' => $default_card), 'woocommerce-gateway-stripe/', untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/legacy/templates/'); |
|
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | * Delete a card |
39 | 39 | */ |
40 | 40 | public function delete_card() { |
41 | - if ( ! isset( $_POST['stripe_delete_card'] ) || ! is_account_page() ) { |
|
41 | + if ( ! isset($_POST['stripe_delete_card']) || ! is_account_page()) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
45 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
46 | 46 | $stripe_customer_id = $stripe_customer->get_id(); |
47 | - $delete_card = sanitize_text_field( $_POST['stripe_delete_card'] ); |
|
47 | + $delete_card = sanitize_text_field($_POST['stripe_delete_card']); |
|
48 | 48 | |
49 | - if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce( $_POST['_wpnonce'], "stripe_del_card" ) ) { |
|
50 | - wp_die( __( 'Unable to make default card, please try again', 'woocommerce-gateway-stripe' ) ); |
|
49 | + if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce($_POST['_wpnonce'], "stripe_del_card")) { |
|
50 | + wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe')); |
|
51 | 51 | } |
52 | 52 | |
53 | - if ( ! $stripe_customer->delete_card( $delete_card ) ) { |
|
54 | - wc_add_notice( __( 'Unable to delete card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
53 | + if ( ! $stripe_customer->delete_card($delete_card)) { |
|
54 | + wc_add_notice(__('Unable to delete card.', 'woocommerce-gateway-stripe'), 'error'); |
|
55 | 55 | } else { |
56 | - wc_add_notice( __( 'Card deleted.', 'woocommerce-gateway-stripe' ), 'success' ); |
|
56 | + wc_add_notice(__('Card deleted.', 'woocommerce-gateway-stripe'), 'success'); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -61,22 +61,22 @@ discard block |
||
61 | 61 | * Make a card as default method |
62 | 62 | */ |
63 | 63 | public function default_card() { |
64 | - if ( ! isset( $_POST['stripe_default_card'] ) || ! is_account_page() ) { |
|
64 | + if ( ! isset($_POST['stripe_default_card']) || ! is_account_page()) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
68 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
69 | 69 | $stripe_customer_id = $stripe_customer->get_id(); |
70 | - $default_source = sanitize_text_field( $_POST['stripe_default_card'] ); |
|
70 | + $default_source = sanitize_text_field($_POST['stripe_default_card']); |
|
71 | 71 | |
72 | - if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce( $_POST['_wpnonce'], "stripe_default_card" ) ) { |
|
73 | - wp_die( __( 'Unable to make default card, please try again', 'woocommerce-gateway-stripe' ) ); |
|
72 | + if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce($_POST['_wpnonce'], "stripe_default_card")) { |
|
73 | + wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe')); |
|
74 | 74 | } |
75 | 75 | |
76 | - if ( ! $stripe_customer->set_default_card( $default_source ) ) { |
|
77 | - wc_add_notice( __( 'Unable to update default card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
76 | + if ( ! $stripe_customer->set_default_card($default_source)) { |
|
77 | + wc_add_notice(__('Unable to update default card.', 'woocommerce-gateway-stripe'), 'error'); |
|
78 | 78 | } else { |
79 | - wc_add_notice( __( 'Default card updated.', 'woocommerce-gateway-stripe' ), 'success' ); |
|
79 | + wc_add_notice(__('Default card updated.', 'woocommerce-gateway-stripe'), 'success'); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -1,37 +1,37 @@ |
||
1 | -<h2 id="saved-cards" style="margin-top:40px;"><?php _e( 'Saved cards', 'woocommerce-gateway-stripe' ); ?></h2> |
|
1 | +<h2 id="saved-cards" style="margin-top:40px;"><?php _e('Saved cards', 'woocommerce-gateway-stripe'); ?></h2> |
|
2 | 2 | <table class="shop_table"> |
3 | 3 | <thead> |
4 | 4 | <tr> |
5 | - <th><?php esc_html_e( 'Card', 'woocommerce-gateway-stripe' ); ?></th> |
|
6 | - <th><?php esc_html_e( 'Expires', 'woocommerce-gateway-stripe' ); ?></th> |
|
5 | + <th><?php esc_html_e('Card', 'woocommerce-gateway-stripe'); ?></th> |
|
6 | + <th><?php esc_html_e('Expires', 'woocommerce-gateway-stripe'); ?></th> |
|
7 | 7 | <th></th> |
8 | 8 | </tr> |
9 | 9 | </thead> |
10 | 10 | <tbody> |
11 | - <?php foreach ( $cards as $card ) : |
|
12 | - if ( 'card' !== $card->object ) { |
|
11 | + <?php foreach ($cards as $card) : |
|
12 | + if ('card' !== $card->object) { |
|
13 | 13 | continue; |
14 | 14 | } |
15 | 15 | |
16 | 16 | $is_default_card = $card->id === $default_card ? true : false; |
17 | 17 | ?> |
18 | 18 | <tr> |
19 | - <td><?php printf( __( '%s card ending in %s', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4 ); ?> |
|
20 | - <?php if ( $is_default_card ) echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); ?> |
|
19 | + <td><?php printf(__('%s card ending in %s', 'woocommerce-gateway-stripe'), $card->brand, $card->last4); ?> |
|
20 | + <?php if ($is_default_card) echo '<br />' . __('(Default)', 'woocommerce-gateway-stripe'); ?> |
|
21 | 21 | </td> |
22 | - <td><?php printf( __( 'Expires %s/%s', 'woocommerce-gateway-stripe' ), $card->exp_month, $card->exp_year ); ?></td> |
|
22 | + <td><?php printf(__('Expires %s/%s', 'woocommerce-gateway-stripe'), $card->exp_month, $card->exp_year); ?></td> |
|
23 | 23 | <td> |
24 | 24 | <form action="" method="POST"> |
25 | - <?php wp_nonce_field ( 'stripe_del_card' ); ?> |
|
26 | - <input type="hidden" name="stripe_delete_card" value="<?php echo esc_attr( $card->id ); ?>"> |
|
27 | - <input type="submit" class="button" value="<?php esc_attr_e( 'Delete card', 'woocommerce-gateway-stripe' ); ?>"> |
|
25 | + <?php wp_nonce_field('stripe_del_card'); ?> |
|
26 | + <input type="hidden" name="stripe_delete_card" value="<?php echo esc_attr($card->id); ?>"> |
|
27 | + <input type="submit" class="button" value="<?php esc_attr_e('Delete card', 'woocommerce-gateway-stripe'); ?>"> |
|
28 | 28 | </form> |
29 | 29 | |
30 | - <?php if ( ! $is_default_card ) { ?> |
|
30 | + <?php if ( ! $is_default_card) { ?> |
|
31 | 31 | <form action="" method="POST" style="margin-top:10px;"> |
32 | - <?php wp_nonce_field ( 'stripe_default_card' ); ?> |
|
33 | - <input type="hidden" name="stripe_default_card" value="<?php echo esc_attr( $card->id ); ?>"> |
|
34 | - <input type="submit" class="button" value="<?php esc_attr_e( 'Make Default', 'woocommerce-gateway-stripe' ); ?>"> |
|
32 | + <?php wp_nonce_field('stripe_default_card'); ?> |
|
33 | + <input type="hidden" name="stripe_default_card" value="<?php echo esc_attr($card->id); ?>"> |
|
34 | + <input type="submit" class="button" value="<?php esc_attr_e('Make Default', 'woocommerce-gateway-stripe'); ?>"> |
|
35 | 35 | </form> |
36 | 36 | <?php } ?> |
37 | 37 | </td> |
@@ -17,7 +17,10 @@ |
||
17 | 17 | ?> |
18 | 18 | <tr> |
19 | 19 | <td><?php printf( __( '%s card ending in %s', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4 ); ?> |
20 | - <?php if ( $is_default_card ) echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); ?> |
|
20 | + <?php if ( $is_default_card ) { |
|
21 | + echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); |
|
22 | +} |
|
23 | +?> |
|
21 | 24 | </td> |
22 | 25 | <td><?php printf( __( 'Expires %s/%s', 'woocommerce-gateway-stripe' ), $card->exp_month, $card->exp_year ); ?></td> |
23 | 26 | <td> |
@@ -144,6 +144,8 @@ discard block |
||
144 | 144 | |
145 | 145 | /** |
146 | 146 | * Allow this class and other classes to add slug keyed notices (to avoid duplication) |
147 | + * @param string $slug |
|
148 | + * @param string $class |
|
147 | 149 | */ |
148 | 150 | public function add_admin_notice( $slug, $class, $message ) { |
149 | 151 | $this->notices[ $slug ] = array( |
@@ -397,7 +399,7 @@ discard block |
||
397 | 399 | /** |
398 | 400 | * List of currencies supported by Stripe that has no decimals. |
399 | 401 | * |
400 | - * @return array $currencies |
|
402 | + * @return string[] $currencies |
|
401 | 403 | */ |
402 | 404 | public static function no_decimal_currencies() { |
403 | 405 | return array( |
@@ -25,21 +25,21 @@ discard block |
||
25 | 25 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
26 | 26 | */ |
27 | 27 | |
28 | -if ( ! defined( 'ABSPATH' ) ) { |
|
28 | +if ( ! defined('ABSPATH')) { |
|
29 | 29 | exit; |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Required minimums and constants |
34 | 34 | */ |
35 | -define( 'WC_STRIPE_VERSION', '3.1.7' ); |
|
36 | -define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
37 | -define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' ); |
|
38 | -define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
39 | -define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
40 | -define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
35 | +define('WC_STRIPE_VERSION', '3.1.7'); |
|
36 | +define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
37 | +define('WC_STRIPE_MIN_WC_VER', '2.5.0'); |
|
38 | +define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
39 | +define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
40 | +define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
41 | 41 | |
42 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
42 | +if ( ! class_exists('WC_Stripe')) : |
|
43 | 43 | |
44 | 44 | class WC_Stripe { |
45 | 45 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @return Singleton The *Singleton* instance. |
60 | 60 | */ |
61 | 61 | public static function get_instance() { |
62 | - if ( null === self::$instance ) { |
|
62 | + if (null === self::$instance) { |
|
63 | 63 | self::$instance = new self(); |
64 | 64 | } |
65 | 65 | return self::$instance; |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | * *Singleton* via the `new` operator from outside of this class. |
109 | 109 | */ |
110 | 110 | protected function __construct() { |
111 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
112 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
113 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
111 | + add_action('admin_init', array($this, 'check_environment')); |
|
112 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
113 | + add_action('plugins_loaded', array($this, 'init')); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -118,35 +118,35 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function init() { |
120 | 120 | // Don't hook anything else in the plugin if we're in an incompatible environment |
121 | - if ( self::get_environment_warning() ) { |
|
121 | + if (self::get_environment_warning()) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
125 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
126 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
125 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
126 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
127 | 127 | |
128 | 128 | // Init the gateway itself |
129 | 129 | $this->init_gateways(); |
130 | 130 | |
131 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
132 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
133 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
134 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
135 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
136 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
137 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
138 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
139 | - add_action( 'wp_ajax_stripe_dismiss_request_api_notice', array( $this, 'dismiss_request_api_notice' ) ); |
|
140 | - add_action( 'wp_ajax_stripe_dismiss_apple_pay_notice', array( $this, 'dismiss_apple_pay_notice' ) ); |
|
141 | - |
|
142 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' ); |
|
131 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
132 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
133 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
134 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
135 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
136 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
137 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
138 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
139 | + add_action('wp_ajax_stripe_dismiss_request_api_notice', array($this, 'dismiss_request_api_notice')); |
|
140 | + add_action('wp_ajax_stripe_dismiss_apple_pay_notice', array($this, 'dismiss_apple_pay_notice')); |
|
141 | + |
|
142 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php'); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * Allow this class and other classes to add slug keyed notices (to avoid duplication) |
147 | 147 | */ |
148 | - public function add_admin_notice( $slug, $class, $message ) { |
|
149 | - $this->notices[ $slug ] = array( |
|
148 | + public function add_admin_notice($slug, $class, $message) { |
|
149 | + $this->notices[$slug] = array( |
|
150 | 150 | 'class' => $class, |
151 | 151 | 'message' => $message, |
152 | 152 | ); |
@@ -157,29 +157,29 @@ discard block |
||
157 | 157 | * or the environment changes after activation. Also handles upgrade routines. |
158 | 158 | */ |
159 | 159 | public function check_environment() { |
160 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'woocommerce_stripe_version' ) ) ) { |
|
160 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('woocommerce_stripe_version'))) { |
|
161 | 161 | $this->install(); |
162 | 162 | |
163 | - do_action( 'woocommerce_stripe_updated' ); |
|
163 | + do_action('woocommerce_stripe_updated'); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $environment_warning = self::get_environment_warning(); |
167 | 167 | |
168 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
169 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
168 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
169 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Check if secret key present. Otherwise prompt, via notice, to go to |
173 | 173 | // setting. |
174 | - if ( ! class_exists( 'WC_Stripe_API' ) ) { |
|
175 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
174 | + if ( ! class_exists('WC_Stripe_API')) { |
|
175 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $secret = WC_Stripe_API::get_secret_key(); |
179 | 179 | |
180 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
180 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
181 | 181 | $setting_link = $this->get_setting_link(); |
182 | - $this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) ); |
|
182 | + $this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link)); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | * @return bool |
192 | 192 | */ |
193 | 193 | private static function _update_plugin_version() { |
194 | - delete_option( 'wc_stripe_version' ); |
|
195 | - add_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
194 | + delete_option('wc_stripe_version'); |
|
195 | + add_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
196 | 196 | |
197 | 197 | return true; |
198 | 198 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @version 3.1.0 |
205 | 205 | */ |
206 | 206 | public function dismiss_request_api_notice() { |
207 | - add_option( 'wc_stripe_show_request_api_notice', 'no' ); |
|
207 | + add_option('wc_stripe_show_request_api_notice', 'no'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @version 3.1.0 |
215 | 215 | */ |
216 | 216 | public function dismiss_apple_pay_notice() { |
217 | - add_option( 'wc_stripe_show_apple_pay_notice', 'no' ); |
|
217 | + add_option('wc_stripe_show_apple_pay_notice', 'no'); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * @version 3.1.0 |
225 | 225 | */ |
226 | 226 | public function install() { |
227 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
228 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
227 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
228 | + define('WC_STRIPE_INSTALLING', true); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | $this->_update_plugin_version(); |
@@ -236,24 +236,24 @@ discard block |
||
236 | 236 | * found or false if the environment has no problems. |
237 | 237 | */ |
238 | 238 | static function get_environment_warning() { |
239 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
240 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
239 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
240 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
241 | 241 | |
242 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
242 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
243 | 243 | } |
244 | 244 | |
245 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
246 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
245 | + if ( ! defined('WC_VERSION')) { |
|
246 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
247 | 247 | } |
248 | 248 | |
249 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
250 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
249 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
250 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
251 | 251 | |
252 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
252 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
253 | 253 | } |
254 | 254 | |
255 | - if ( ! function_exists( 'curl_init' ) ) { |
|
256 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
255 | + if ( ! function_exists('curl_init')) { |
|
256 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | return false; |
@@ -264,15 +264,15 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @since 1.0.0 |
266 | 266 | */ |
267 | - public function plugin_action_links( $links ) { |
|
267 | + public function plugin_action_links($links) { |
|
268 | 268 | $setting_link = $this->get_setting_link(); |
269 | 269 | |
270 | 270 | $plugin_links = array( |
271 | - '<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
272 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
273 | - '<a href="https://woocommerce.com/contact-us/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
271 | + '<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
272 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
273 | + '<a href="https://woocommerce.com/contact-us/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
274 | 274 | ); |
275 | - return array_merge( $plugin_links, $links ); |
|
275 | + return array_merge($plugin_links, $links); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -283,24 +283,24 @@ discard block |
||
283 | 283 | * @return string Setting link |
284 | 284 | */ |
285 | 285 | public function get_setting_link() { |
286 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
286 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
287 | 287 | |
288 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
288 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
289 | 289 | |
290 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
290 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | 294 | * Display any notices we've collected thus far (e.g. for connection, disconnection) |
295 | 295 | */ |
296 | 296 | public function admin_notices() { |
297 | - $show_request_api_notice = get_option( 'wc_stripe_show_request_api_notice' ); |
|
298 | - $show_apple_pay_notice = get_option( 'wc_stripe_show_apple_pay_notice' ); |
|
297 | + $show_request_api_notice = get_option('wc_stripe_show_request_api_notice'); |
|
298 | + $show_apple_pay_notice = get_option('wc_stripe_show_apple_pay_notice'); |
|
299 | 299 | |
300 | - if ( empty( $show_apple_pay_notice ) ) { |
|
300 | + if (empty($show_apple_pay_notice)) { |
|
301 | 301 | // @TODO remove this notice in the future. |
302 | 302 | ?> |
303 | - <div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php esc_html_e( 'New Feature! Stripe now supports Apple Pay. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe' ); ?></p></div> |
|
303 | + <div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php esc_html_e('New Feature! Stripe now supports Apple Pay. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe'); ?></p></div> |
|
304 | 304 | |
305 | 305 | <script type="application/javascript"> |
306 | 306 | jQuery( '.wc-stripe-apple-pay-notice' ).on( 'click', '.notice-dismiss', function() { |
@@ -308,17 +308,17 @@ discard block |
||
308 | 308 | action: 'stripe_dismiss_apple_pay_notice' |
309 | 309 | }; |
310 | 310 | |
311 | - jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data ); |
|
311 | + jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data ); |
|
312 | 312 | }); |
313 | 313 | </script> |
314 | 314 | |
315 | 315 | <?php |
316 | 316 | } |
317 | 317 | |
318 | - if ( empty( $show_request_api_notice ) ) { |
|
318 | + if (empty($show_request_api_notice)) { |
|
319 | 319 | // @TODO remove this notice in the future. |
320 | 320 | ?> |
321 | - <div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e( 'New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe' ); ?></p></div> |
|
321 | + <div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e('New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe'); ?></p></div> |
|
322 | 322 | |
323 | 323 | <script type="application/javascript"> |
324 | 324 | jQuery( '.wc-stripe-request-api-notice' ).on( 'click', '.notice-dismiss', function() { |
@@ -326,16 +326,16 @@ discard block |
||
326 | 326 | action: 'stripe_dismiss_request_api_notice' |
327 | 327 | }; |
328 | 328 | |
329 | - jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data ); |
|
329 | + jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data ); |
|
330 | 330 | }); |
331 | 331 | </script> |
332 | 332 | |
333 | 333 | <?php |
334 | 334 | } |
335 | 335 | |
336 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
337 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
338 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
336 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
337 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
338 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
339 | 339 | echo '</p></div>'; |
340 | 340 | } |
341 | 341 | } |
@@ -346,28 +346,28 @@ discard block |
||
346 | 346 | * @since 1.0.0 |
347 | 347 | */ |
348 | 348 | public function init_gateways() { |
349 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
349 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
350 | 350 | $this->subscription_support_enabled = true; |
351 | 351 | } |
352 | 352 | |
353 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
353 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
354 | 354 | $this->pre_order_enabled = true; |
355 | 355 | } |
356 | 356 | |
357 | - if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
|
357 | + if ( ! class_exists('WC_Payment_Gateway')) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | - if ( class_exists( 'WC_Payment_Gateway_CC' ) ) { |
|
362 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
363 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' ); |
|
361 | + if (class_exists('WC_Payment_Gateway_CC')) { |
|
362 | + include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
363 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php'); |
|
364 | 364 | } else { |
365 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' ); |
|
366 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' ); |
|
365 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php'); |
|
366 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php'); |
|
367 | 367 | } |
368 | 368 | |
369 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
370 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
369 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
370 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
371 | 371 | |
372 | 372 | $load_addons = ( |
373 | 373 | $this->subscription_support_enabled |
@@ -375,8 +375,8 @@ discard block |
||
375 | 375 | $this->pre_order_enabled |
376 | 376 | ); |
377 | 377 | |
378 | - if ( $load_addons ) { |
|
379 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' ); |
|
378 | + if ($load_addons) { |
|
379 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php'); |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 | |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | * |
386 | 386 | * @since 1.0.0 |
387 | 387 | */ |
388 | - public function add_gateways( $methods ) { |
|
389 | - if ( $this->subscription_support_enabled || $this->pre_order_enabled ) { |
|
388 | + public function add_gateways($methods) { |
|
389 | + if ($this->subscription_support_enabled || $this->pre_order_enabled) { |
|
390 | 390 | $methods[] = 'WC_Gateway_Stripe_Addons'; |
391 | 391 | } else { |
392 | 392 | $methods[] = 'WC_Gateway_Stripe'; |
@@ -426,24 +426,24 @@ discard block |
||
426 | 426 | * @param object $balance_transaction |
427 | 427 | * @param string $type Type of number to format |
428 | 428 | */ |
429 | - public static function format_number( $balance_transaction, $type = 'fee' ) { |
|
430 | - if ( ! is_object( $balance_transaction ) ) { |
|
429 | + public static function format_number($balance_transaction, $type = 'fee') { |
|
430 | + if ( ! is_object($balance_transaction)) { |
|
431 | 431 | return; |
432 | 432 | } |
433 | 433 | |
434 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
435 | - if ( 'fee' === $type ) { |
|
434 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
435 | + if ('fee' === $type) { |
|
436 | 436 | return $balance_transaction->fee; |
437 | 437 | } |
438 | 438 | |
439 | 439 | return $balance_transaction->net; |
440 | 440 | } |
441 | 441 | |
442 | - if ( 'fee' === $type ) { |
|
443 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
442 | + if ('fee' === $type) { |
|
443 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
444 | 444 | } |
445 | 445 | |
446 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
446 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -451,35 +451,35 @@ discard block |
||
451 | 451 | * |
452 | 452 | * @param int $order_id |
453 | 453 | */ |
454 | - public function capture_payment( $order_id ) { |
|
455 | - $order = wc_get_order( $order_id ); |
|
454 | + public function capture_payment($order_id) { |
|
455 | + $order = wc_get_order($order_id); |
|
456 | 456 | |
457 | - if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
458 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
459 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
457 | + if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) { |
|
458 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
459 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
460 | 460 | |
461 | - if ( $charge && 'no' === $captured ) { |
|
462 | - $result = WC_Stripe_API::request( array( |
|
461 | + if ($charge && 'no' === $captured) { |
|
462 | + $result = WC_Stripe_API::request(array( |
|
463 | 463 | 'amount' => $order->get_total() * 100, |
464 | 464 | 'expand[]' => 'balance_transaction', |
465 | - ), 'charges/' . $charge . '/capture' ); |
|
465 | + ), 'charges/' . $charge . '/capture'); |
|
466 | 466 | |
467 | - if ( is_wp_error( $result ) ) { |
|
468 | - $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
467 | + if (is_wp_error($result)) { |
|
468 | + $order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
469 | 469 | } else { |
470 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
471 | - update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ); |
|
470 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
471 | + update_post_meta($order_id, '_stripe_charge_captured', 'yes'); |
|
472 | 472 | |
473 | 473 | // Store other data such as fees |
474 | - update_post_meta( $order_id, 'Stripe Payment ID', $result->id ); |
|
474 | + update_post_meta($order_id, 'Stripe Payment ID', $result->id); |
|
475 | 475 | |
476 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
476 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
477 | 477 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
478 | 478 | // values are in the local currency of the Stripe account, not from WC. |
479 | - $fee = ! empty( $result->balance_transaction->fee ) ? self::format_number( $result->balance_transaction, 'fee' ) : 0; |
|
480 | - $net = ! empty( $result->balance_transaction->net ) ? self::format_number( $result->balance_transaction, 'net' ) : 0; |
|
481 | - update_post_meta( $order_id, 'Stripe Fee', $fee ); |
|
482 | - update_post_meta( $order_id, 'Net Revenue From Stripe', $net ); |
|
479 | + $fee = ! empty($result->balance_transaction->fee) ? self::format_number($result->balance_transaction, 'fee') : 0; |
|
480 | + $net = ! empty($result->balance_transaction->net) ? self::format_number($result->balance_transaction, 'net') : 0; |
|
481 | + update_post_meta($order_id, 'Stripe Fee', $fee); |
|
482 | + update_post_meta($order_id, 'Net Revenue From Stripe', $net); |
|
483 | 483 | } |
484 | 484 | } |
485 | 485 | } |
@@ -491,23 +491,23 @@ discard block |
||
491 | 491 | * |
492 | 492 | * @param int $order_id |
493 | 493 | */ |
494 | - public function cancel_payment( $order_id ) { |
|
495 | - $order = wc_get_order( $order_id ); |
|
494 | + public function cancel_payment($order_id) { |
|
495 | + $order = wc_get_order($order_id); |
|
496 | 496 | |
497 | - if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
498 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
497 | + if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) { |
|
498 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
499 | 499 | |
500 | - if ( $charge ) { |
|
501 | - $result = WC_Stripe_API::request( array( |
|
500 | + if ($charge) { |
|
501 | + $result = WC_Stripe_API::request(array( |
|
502 | 502 | 'amount' => $order->get_total() * 100, |
503 | - ), 'charges/' . $charge . '/refund' ); |
|
503 | + ), 'charges/' . $charge . '/refund'); |
|
504 | 504 | |
505 | - if ( is_wp_error( $result ) ) { |
|
506 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
505 | + if (is_wp_error($result)) { |
|
506 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
507 | 507 | } else { |
508 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
509 | - delete_post_meta( $order_id, '_stripe_charge_captured' ); |
|
510 | - delete_post_meta( $order_id, '_stripe_charge_id' ); |
|
508 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
509 | + delete_post_meta($order_id, '_stripe_charge_captured'); |
|
510 | + delete_post_meta($order_id, '_stripe_charge_id'); |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | } |
@@ -518,28 +518,28 @@ discard block |
||
518 | 518 | * @param array $tokens |
519 | 519 | * @return array |
520 | 520 | */ |
521 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
522 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
523 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
521 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
522 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
523 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
524 | 524 | $stripe_cards = $stripe_customer->get_cards(); |
525 | 525 | $stored_tokens = array(); |
526 | 526 | |
527 | - foreach ( $tokens as $token ) { |
|
527 | + foreach ($tokens as $token) { |
|
528 | 528 | $stored_tokens[] = $token->get_token(); |
529 | 529 | } |
530 | 530 | |
531 | - foreach ( $stripe_cards as $card ) { |
|
532 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
531 | + foreach ($stripe_cards as $card) { |
|
532 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
533 | 533 | $token = new WC_Payment_Token_CC(); |
534 | - $token->set_token( $card->id ); |
|
535 | - $token->set_gateway_id( 'stripe' ); |
|
536 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
537 | - $token->set_last4( $card->last4 ); |
|
538 | - $token->set_expiry_month( $card->exp_month ); |
|
539 | - $token->set_expiry_year( $card->exp_year ); |
|
540 | - $token->set_user_id( $customer_id ); |
|
534 | + $token->set_token($card->id); |
|
535 | + $token->set_gateway_id('stripe'); |
|
536 | + $token->set_card_type(strtolower($card->brand)); |
|
537 | + $token->set_last4($card->last4); |
|
538 | + $token->set_expiry_month($card->exp_month); |
|
539 | + $token->set_expiry_year($card->exp_year); |
|
540 | + $token->set_user_id($customer_id); |
|
541 | 541 | $token->save(); |
542 | - $tokens[ $token->get_id() ] = $token; |
|
542 | + $tokens[$token->get_id()] = $token; |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | } |
@@ -549,21 +549,21 @@ discard block |
||
549 | 549 | /** |
550 | 550 | * Delete token from Stripe |
551 | 551 | */ |
552 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
553 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
554 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
555 | - $stripe_customer->delete_card( $token->get_token() ); |
|
552 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
553 | + if ('stripe' === $token->get_gateway_id()) { |
|
554 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
555 | + $stripe_customer->delete_card($token->get_token()); |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | |
559 | 559 | /** |
560 | 560 | * Set as default in Stripe |
561 | 561 | */ |
562 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
563 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
564 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
565 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
566 | - $stripe_customer->set_default_card( $token->get_token() ); |
|
562 | + public function woocommerce_payment_token_set_default($token_id) { |
|
563 | + $token = WC_Payment_Tokens::get($token_id); |
|
564 | + if ('stripe' === $token->get_gateway_id()) { |
|
565 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
566 | + $stripe_customer->set_default_card($token->get_token()); |
|
567 | 567 | } |
568 | 568 | } |
569 | 569 | |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | */ |
573 | 573 | public static function get_minimum_amount() { |
574 | 574 | // Check order amount |
575 | - switch ( get_woocommerce_currency() ) { |
|
575 | + switch (get_woocommerce_currency()) { |
|
576 | 576 | case 'USD': |
577 | 577 | case 'CAD': |
578 | 578 | case 'EUR': |
@@ -616,12 +616,12 @@ discard block |
||
616 | 616 | * And fits on your back? |
617 | 617 | * It's log, log, log |
618 | 618 | */ |
619 | - public static function log( $message ) { |
|
620 | - if ( empty( self::$log ) ) { |
|
619 | + public static function log($message) { |
|
620 | + if (empty(self::$log)) { |
|
621 | 621 | self::$log = new WC_Logger(); |
622 | 622 | } |
623 | 623 | |
624 | - self::$log->add( 'woocommerce-gateway-stripe', $message ); |
|
624 | + self::$log->add('woocommerce-gateway-stripe', $message); |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 |
@@ -1,176 +1,176 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -return apply_filters( 'wc_stripe_settings', |
|
6 | +return apply_filters('wc_stripe_settings', |
|
7 | 7 | array( |
8 | 8 | 'enabled' => array( |
9 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
10 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
9 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
10 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'checkbox', |
12 | 12 | 'description' => '', |
13 | 13 | 'default' => 'no', |
14 | 14 | ), |
15 | 15 | 'title' => array( |
16 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
16 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
17 | 17 | 'type' => 'text', |
18 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
19 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
18 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
19 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'desc_tip' => true, |
21 | 21 | ), |
22 | 22 | 'description' => array( |
23 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
24 | 24 | 'type' => 'text', |
25 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
26 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ), |
|
25 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
26 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
27 | 27 | 'desc_tip' => true, |
28 | 28 | ), |
29 | 29 | 'testmode' => array( |
30 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
31 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
31 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
32 | 32 | 'type' => 'checkbox', |
33 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
33 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'default' => 'yes', |
35 | 35 | 'desc_tip' => true, |
36 | 36 | ), |
37 | 37 | 'test_secret_key' => array( |
38 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
38 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
39 | 39 | 'type' => 'text', |
40 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
40 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'default' => '', |
42 | 42 | 'desc_tip' => true, |
43 | 43 | ), |
44 | 44 | 'test_publishable_key' => array( |
45 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
45 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
46 | 46 | 'type' => 'text', |
47 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
47 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
48 | 48 | 'default' => '', |
49 | 49 | 'desc_tip' => true, |
50 | 50 | ), |
51 | 51 | 'secret_key' => array( |
52 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
52 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
53 | 53 | 'type' => 'text', |
54 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
54 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
55 | 55 | 'default' => '', |
56 | 56 | 'desc_tip' => true, |
57 | 57 | ), |
58 | 58 | 'publishable_key' => array( |
59 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
59 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
60 | 60 | 'type' => 'text', |
61 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
61 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
62 | 62 | 'default' => '', |
63 | 63 | 'desc_tip' => true, |
64 | 64 | ), |
65 | 65 | 'statement_descriptor' => array( |
66 | - 'title' => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ), |
|
66 | + 'title' => __('Statement Descriptor', 'woocommerce-gateway-stripe'), |
|
67 | 67 | 'type' => 'text', |
68 | - 'description' => __( 'Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe' ), |
|
68 | + 'description' => __('Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe'), |
|
69 | 69 | 'default' => '', |
70 | 70 | 'desc_tip' => true, |
71 | 71 | ), |
72 | 72 | 'capture' => array( |
73 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
74 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
73 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
74 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
75 | 75 | 'type' => 'checkbox', |
76 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
76 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
77 | 77 | 'default' => 'yes', |
78 | 78 | 'desc_tip' => true, |
79 | 79 | ), |
80 | 80 | 'stripe_checkout' => array( |
81 | - 'title' => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
82 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
81 | + 'title' => __('Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
82 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
83 | 83 | 'type' => 'checkbox', |
84 | - 'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ), |
|
84 | + 'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'), |
|
85 | 85 | 'default' => 'no', |
86 | 86 | 'desc_tip' => true, |
87 | 87 | ), |
88 | 88 | 'stripe_checkout_locale' => array( |
89 | - 'title' => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ), |
|
89 | + 'title' => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'), |
|
90 | 90 | 'type' => 'select', |
91 | 91 | 'class' => 'wc-enhanced-select', |
92 | - 'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ), |
|
92 | + 'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'), |
|
93 | 93 | 'default' => 'en', |
94 | 94 | 'desc_tip' => true, |
95 | 95 | 'options' => array( |
96 | - 'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ), |
|
97 | - 'zh' => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ), |
|
98 | - 'da' => __( 'Danish', 'woocommerce-gateway-stripe' ), |
|
99 | - 'nl' => __( 'Dutch', 'woocommerce-gateway-stripe' ), |
|
100 | - 'en' => __( 'English', 'woocommerce-gateway-stripe' ), |
|
101 | - 'fi' => __( 'Finnish', 'woocommerce-gateway-stripe' ), |
|
102 | - 'fr' => __( 'French', 'woocommerce-gateway-stripe' ), |
|
103 | - 'de' => __( 'German', 'woocommerce-gateway-stripe' ), |
|
104 | - 'it' => __( 'Italian', 'woocommerce-gateway-stripe' ), |
|
105 | - 'ja' => __( 'Japanese', 'woocommerce-gateway-stripe' ), |
|
106 | - 'no' => __( 'Norwegian', 'woocommerce-gateway-stripe' ), |
|
107 | - 'es' => __( 'Spanish', 'woocommerce-gateway-stripe' ), |
|
108 | - 'sv' => __( 'Swedish', 'woocommerce-gateway-stripe' ), |
|
96 | + 'auto' => __('Auto', 'woocommerce-gateway-stripe'), |
|
97 | + 'zh' => __('Simplified Chinese', 'woocommerce-gateway-stripe'), |
|
98 | + 'da' => __('Danish', 'woocommerce-gateway-stripe'), |
|
99 | + 'nl' => __('Dutch', 'woocommerce-gateway-stripe'), |
|
100 | + 'en' => __('English', 'woocommerce-gateway-stripe'), |
|
101 | + 'fi' => __('Finnish', 'woocommerce-gateway-stripe'), |
|
102 | + 'fr' => __('French', 'woocommerce-gateway-stripe'), |
|
103 | + 'de' => __('German', 'woocommerce-gateway-stripe'), |
|
104 | + 'it' => __('Italian', 'woocommerce-gateway-stripe'), |
|
105 | + 'ja' => __('Japanese', 'woocommerce-gateway-stripe'), |
|
106 | + 'no' => __('Norwegian', 'woocommerce-gateway-stripe'), |
|
107 | + 'es' => __('Spanish', 'woocommerce-gateway-stripe'), |
|
108 | + 'sv' => __('Swedish', 'woocommerce-gateway-stripe'), |
|
109 | 109 | ), |
110 | 110 | ), |
111 | 111 | 'stripe_bitcoin' => array( |
112 | - 'title' => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
113 | - 'label' => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
112 | + 'title' => __('Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
113 | + 'label' => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
114 | 114 | 'type' => 'checkbox', |
115 | - 'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ), |
|
115 | + 'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'), |
|
116 | 116 | 'default' => 'no', |
117 | 117 | 'desc_tip' => true, |
118 | 118 | ), |
119 | 119 | 'stripe_checkout_image' => array( |
120 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
121 | - 'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ), |
|
120 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
121 | + 'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'), |
|
122 | 122 | 'type' => 'text', |
123 | 123 | 'default' => '', |
124 | 124 | 'desc_tip' => true, |
125 | 125 | ), |
126 | 126 | 'request_payment_api' => array( |
127 | - 'title' => __( 'Payment Request API', 'woocommerce-gateway-stripe' ), |
|
128 | - 'label' => __( 'Enable Payment Request API', 'woocommerce-gateway-stripe' ), |
|
127 | + 'title' => __('Payment Request API', 'woocommerce-gateway-stripe'), |
|
128 | + 'label' => __('Enable Payment Request API', 'woocommerce-gateway-stripe'), |
|
129 | 129 | 'type' => 'checkbox', |
130 | - 'description' => __( 'If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe' ), |
|
130 | + 'description' => __('If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe'), |
|
131 | 131 | 'default' => 'no', |
132 | 132 | 'desc_tip' => true, |
133 | 133 | ), |
134 | 134 | 'apple_pay' => array( |
135 | - 'title' => __( 'Apple Pay', 'woocommerce-gateway-stripe' ), |
|
136 | - 'label' => sprintf( __( 'Enable Apple Pay. %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ), |
|
135 | + 'title' => __('Apple Pay', 'woocommerce-gateway-stripe'), |
|
136 | + 'label' => sprintf(__('Enable Apple Pay. %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'), |
|
137 | 137 | 'type' => 'checkbox', |
138 | - 'description' => __( 'If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe' ), |
|
138 | + 'description' => __('If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe'), |
|
139 | 139 | 'default' => 'yes', |
140 | 140 | 'desc_tip' => true, |
141 | 141 | ), |
142 | 142 | 'apple_pay_button' => array( |
143 | - 'title' => __( 'Apple Pay Button Style', 'woocommerce-gateway-stripe' ), |
|
144 | - 'label' => __( 'Button Style', 'woocommerce-gateway-stripe' ), |
|
143 | + 'title' => __('Apple Pay Button Style', 'woocommerce-gateway-stripe'), |
|
144 | + 'label' => __('Button Style', 'woocommerce-gateway-stripe'), |
|
145 | 145 | 'type' => 'select', |
146 | - 'description' => __( 'Select the button style you would like to show.', 'woocommerce-gateway-stripe' ), |
|
146 | + 'description' => __('Select the button style you would like to show.', 'woocommerce-gateway-stripe'), |
|
147 | 147 | 'default' => 'black', |
148 | 148 | 'desc_tip' => true, |
149 | 149 | 'options' => array( |
150 | - 'black' => __( 'Black', 'woocommerce-gateway-stripe' ), |
|
151 | - 'white' => __( 'White', 'woocommerce-gateway-stripe' ), |
|
150 | + 'black' => __('Black', 'woocommerce-gateway-stripe'), |
|
151 | + 'white' => __('White', 'woocommerce-gateway-stripe'), |
|
152 | 152 | ), |
153 | 153 | ), |
154 | 154 | 'apple_pay_button_lang' => array( |
155 | - 'title' => __( 'Apple Pay Button Language', 'woocommerce-gateway-stripe' ), |
|
156 | - 'description' => __( 'Enter the 2 letter ISO code for the language you would like your Apple Pay Button to display in. Reference available ISO codes here <code>http://www.w3schools.com/tags/ref_language_codes.asp</code>', 'woocommerce-gateway-stripe' ), |
|
155 | + 'title' => __('Apple Pay Button Language', 'woocommerce-gateway-stripe'), |
|
156 | + 'description' => __('Enter the 2 letter ISO code for the language you would like your Apple Pay Button to display in. Reference available ISO codes here <code>http://www.w3schools.com/tags/ref_language_codes.asp</code>', 'woocommerce-gateway-stripe'), |
|
157 | 157 | 'type' => 'text', |
158 | 158 | 'default' => 'en', |
159 | 159 | 'desc_tip' => false, |
160 | 160 | ), |
161 | 161 | 'saved_cards' => array( |
162 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
163 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
162 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
163 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
164 | 164 | 'type' => 'checkbox', |
165 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
165 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
166 | 166 | 'default' => 'no', |
167 | 167 | 'desc_tip' => true, |
168 | 168 | ), |
169 | 169 | 'logging' => array( |
170 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
171 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
170 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
171 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
172 | 172 | 'type' => 'checkbox', |
173 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
173 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
174 | 174 | 'default' => 'no', |
175 | 175 | 'desc_tip' => true, |
176 | 176 | ), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | */ |
16 | 16 | public function __construct() { |
17 | 17 | $this->id = 'stripe'; |
18 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
19 | - $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
18 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
19 | + $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
20 | 20 | $this->has_fields = true; |
21 | 21 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
22 | 22 | $this->supports = array( |
@@ -42,35 +42,35 @@ discard block |
||
42 | 42 | $this->init_settings(); |
43 | 43 | |
44 | 44 | // Get setting values. |
45 | - $this->title = $this->get_option( 'title' ); |
|
46 | - $this->description = $this->get_option( 'description' ); |
|
47 | - $this->enabled = $this->get_option( 'enabled' ); |
|
48 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
49 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
50 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
51 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
52 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
53 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
54 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
55 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
56 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
57 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
58 | - |
|
59 | - if ( $this->stripe_checkout ) { |
|
60 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
45 | + $this->title = $this->get_option('title'); |
|
46 | + $this->description = $this->get_option('description'); |
|
47 | + $this->enabled = $this->get_option('enabled'); |
|
48 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
49 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
50 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
51 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
52 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
53 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
54 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
55 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
56 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
57 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
58 | + |
|
59 | + if ($this->stripe_checkout) { |
|
60 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
61 | 61 | } |
62 | 62 | |
63 | - if ( $this->testmode ) { |
|
64 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
65 | - $this->description = trim( $this->description ); |
|
63 | + if ($this->testmode) { |
|
64 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
65 | + $this->description = trim($this->description); |
|
66 | 66 | } |
67 | 67 | |
68 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
68 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
69 | 69 | |
70 | 70 | // Hooks |
71 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
72 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
73 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
71 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
72 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
73 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,37 +80,37 @@ discard block |
||
80 | 80 | * @return string |
81 | 81 | */ |
82 | 82 | public function get_icon() { |
83 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
84 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
83 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
84 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
85 | 85 | |
86 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
87 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
88 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
86 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
87 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
88 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
89 | 89 | |
90 | 90 | $base_location = wc_get_base_location(); |
91 | 91 | |
92 | - if ( 'US' === $base_location['country'] ) { |
|
93 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
94 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
95 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
92 | + if ('US' === $base_location['country']) { |
|
93 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
94 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
95 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
96 | 96 | } |
97 | 97 | |
98 | - if ( $this->bitcoin ) { |
|
99 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
98 | + if ($this->bitcoin) { |
|
99 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
100 | 100 | } |
101 | 101 | |
102 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
102 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Get Stripe amount to pay |
107 | 107 | * @return float |
108 | 108 | */ |
109 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
110 | - if ( ! $currency ) { |
|
109 | + public function get_stripe_amount($total, $currency = '') { |
|
110 | + if ( ! $currency) { |
|
111 | 111 | $currency = get_woocommerce_currency(); |
112 | 112 | } |
113 | - switch ( strtoupper( $currency ) ) { |
|
113 | + switch (strtoupper($currency)) { |
|
114 | 114 | // Zero decimal currencies |
115 | 115 | case 'BIF' : |
116 | 116 | case 'CLP' : |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | case 'XAF' : |
128 | 128 | case 'XOF' : |
129 | 129 | case 'XPF' : |
130 | - $total = absint( $total ); |
|
130 | + $total = absint($total); |
|
131 | 131 | break; |
132 | 132 | default : |
133 | - $total = round( $total, 2 ) * 100; // In cents |
|
133 | + $total = round($total, 2) * 100; // In cents |
|
134 | 134 | break; |
135 | 135 | } |
136 | 136 | return $total; |
@@ -140,31 +140,31 @@ discard block |
||
140 | 140 | * Check if SSL is enabled and notify the user |
141 | 141 | */ |
142 | 142 | public function admin_notices() { |
143 | - if ( $this->enabled == 'no' ) { |
|
143 | + if ($this->enabled == 'no') { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | - $addons = ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) ? '_addons' : ''; |
|
147 | + $addons = (class_exists('WC_Subscriptions_Order') || class_exists('WC_Pre_Orders_Order')) ? '_addons' : ''; |
|
148 | 148 | |
149 | 149 | // Check required fields |
150 | - if ( ! $this->secret_key ) { |
|
151 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
150 | + if ( ! $this->secret_key) { |
|
151 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
152 | 152 | return; |
153 | 153 | |
154 | - } elseif ( ! $this->publishable_key ) { |
|
155 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
154 | + } elseif ( ! $this->publishable_key) { |
|
155 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | 159 | // Simple check for duplicate keys |
160 | - if ( $this->secret_key == $this->publishable_key ) { |
|
161 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
160 | + if ($this->secret_key == $this->publishable_key) { |
|
161 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
162 | 162 | return; |
163 | 163 | } |
164 | 164 | |
165 | 165 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected |
166 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
167 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
166 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
167 | + echo '<div class="error"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | * Check if this gateway is enabled |
173 | 173 | */ |
174 | 174 | public function is_available() { |
175 | - if ( 'yes' === $this->enabled ) { |
|
176 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
175 | + if ('yes' === $this->enabled) { |
|
176 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
177 | 177 | return false; |
178 | 178 | } |
179 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
179 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
180 | 180 | return false; |
181 | 181 | } |
182 | 182 | return true; |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * Initialise Gateway Settings Form Fields |
189 | 189 | */ |
190 | 190 | public function init_form_fields() { |
191 | - $this->form_fields = include( untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/settings-stripe.php' ); |
|
191 | + $this->form_fields = include(untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/settings-stripe.php'); |
|
192 | 192 | |
193 | - wc_enqueue_js( " |
|
193 | + wc_enqueue_js(" |
|
194 | 194 | jQuery( function( $ ) { |
195 | 195 | $( '#woocommerce_stripe_stripe_checkout' ).change(function(){ |
196 | 196 | if ( $( this ).is( ':checked' ) ) { |
@@ -210,25 +210,25 @@ discard block |
||
210 | 210 | ?> |
211 | 211 | <fieldset class="stripe-legacy-payment-fields"> |
212 | 212 | <?php |
213 | - if ( $this->description ) { |
|
214 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
213 | + if ($this->description) { |
|
214 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
215 | 215 | } |
216 | - if ( $this->saved_cards && is_user_logged_in() ) { |
|
217 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
216 | + if ($this->saved_cards && is_user_logged_in()) { |
|
217 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
218 | 218 | ?> |
219 | 219 | <p class="form-row form-row-wide"> |
220 | - <a class="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_class', 'button' ); ?>" style="float:right;" href="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_url', get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>#saved-cards"><?php esc_html_e( 'Manage cards', 'woocommerce-gateway-stripe' ); ?></a> |
|
220 | + <a class="<?php echo apply_filters('wc_stripe_manage_saved_cards_class', 'button'); ?>" style="float:right;" href="<?php echo apply_filters('wc_stripe_manage_saved_cards_url', get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>#saved-cards"><?php esc_html_e('Manage cards', 'woocommerce-gateway-stripe'); ?></a> |
|
221 | 221 | <?php |
222 | - if ( $cards = $stripe_customer->get_cards() ) { |
|
222 | + if ($cards = $stripe_customer->get_cards()) { |
|
223 | 223 | $default_card = $cards[0]->id; |
224 | - foreach ( (array) $cards as $card ) { |
|
225 | - if ( 'card' !== $card->object ) { |
|
224 | + foreach ((array) $cards as $card) { |
|
225 | + if ('card' !== $card->object) { |
|
226 | 226 | continue; |
227 | 227 | } |
228 | 228 | ?> |
229 | - <label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr( strtolower( $card->brand ) ); ?>"> |
|
230 | - <input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked( $default_card, $card->id ) ?> /> |
|
231 | - <?php printf( __( '%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4, $card->exp_month, $card->exp_year ); ?> |
|
229 | + <label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr(strtolower($card->brand)); ?>"> |
|
230 | + <input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked($default_card, $card->id) ?> /> |
|
231 | + <?php printf(__('%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe'), $card->brand, $card->last4, $card->exp_month, $card->exp_year); ?> |
|
232 | 232 | </label> |
233 | 233 | <?php |
234 | 234 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | ?> |
237 | 237 | <label for="new"> |
238 | 238 | <input type="radio" id="new" name="wc-stripe-payment-token" value="new" /> |
239 | - <?php _e( 'Use a new credit card', 'woocommerce-gateway-stripe' ); ?> |
|
239 | + <?php _e('Use a new credit card', 'woocommerce-gateway-stripe'); ?> |
|
240 | 240 | </label> |
241 | 241 | </p> |
242 | 242 | <?php |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | |
245 | 245 | $user = wp_get_current_user(); |
246 | 246 | |
247 | - if ( $user ) { |
|
248 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
247 | + if ($user) { |
|
248 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
249 | 249 | $user_email = $user_email ? $user_email : $user->user_email; |
250 | 250 | } else { |
251 | 251 | $user_email = ''; |
@@ -253,22 +253,22 @@ discard block |
||
253 | 253 | |
254 | 254 | $display = ''; |
255 | 255 | |
256 | - if ( $this->stripe_checkout || $this->saved_cards && ! empty( $cards ) ) { |
|
256 | + if ($this->stripe_checkout || $this->saved_cards && ! empty($cards)) { |
|
257 | 257 | $display = 'style="display:none;"'; |
258 | 258 | } |
259 | 259 | |
260 | 260 | echo '<div ' . $display . ' id="stripe-payment-data" |
261 | 261 | data-description="" |
262 | - data-email="' . esc_attr( $user_email ) . '" |
|
263 | - data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '" |
|
264 | - data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '" |
|
265 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
266 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
267 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
268 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">'; |
|
269 | - |
|
270 | - if ( ! $this->stripe_checkout ) { |
|
271 | - $this->credit_card_form( array( 'fields_have_names' => false ) ); |
|
262 | + data-email="' . esc_attr($user_email) . '" |
|
263 | + data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '" |
|
264 | + data-name="' . esc_attr(get_bloginfo('name', 'display')) . '" |
|
265 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
266 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
267 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
268 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">'; |
|
269 | + |
|
270 | + if ( ! $this->stripe_checkout) { |
|
271 | + $this->credit_card_form(array('fields_have_names' => false)); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | echo '</div>'; |
@@ -285,27 +285,27 @@ discard block |
||
285 | 285 | * @access public |
286 | 286 | */ |
287 | 287 | public function payment_scripts() { |
288 | - if ( $this->stripe_checkout ) { |
|
289 | - wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
290 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
288 | + if ($this->stripe_checkout) { |
|
289 | + wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
290 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
291 | 291 | } else { |
292 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
293 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
292 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
293 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $stripe_params = array( |
297 | 297 | 'key' => $this->publishable_key, |
298 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
299 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
298 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
299 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
300 | 300 | ); |
301 | 301 | |
302 | 302 | // If we're on the pay page we need to pass stripe.js the address of the order. |
303 | - if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) { |
|
304 | - $order_key = urldecode( $_GET['order'] ); |
|
305 | - $order_id = absint( $_GET['order_id'] ); |
|
306 | - $order = wc_get_order( $order_id ); |
|
303 | + if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) { |
|
304 | + $order_key = urldecode($_GET['order']); |
|
305 | + $order_id = absint($_GET['order_id']); |
|
306 | + $order = wc_get_order($order_id); |
|
307 | 307 | |
308 | - if ( $order->id === $order_id && $order->order_key === $order_key ) { |
|
308 | + if ($order->id === $order_id && $order->order_key === $order_key) { |
|
309 | 309 | $stripe_params['billing_first_name'] = $order->billing_first_name; |
310 | 310 | $stripe_params['billing_last_name'] = $order->billing_last_name; |
311 | 311 | $stripe_params['billing_address_1'] = $order->billing_address_1; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
320 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
320 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -326,28 +326,28 @@ discard block |
||
326 | 326 | * @param object $source |
327 | 327 | * @return array() |
328 | 328 | */ |
329 | - protected function generate_payment_request( $order, $source ) { |
|
329 | + protected function generate_payment_request($order, $source) { |
|
330 | 330 | $post_data = array(); |
331 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
332 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
333 | - $post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
331 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
332 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
333 | + $post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
334 | 334 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
335 | 335 | |
336 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
336 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
337 | 337 | $post_data['receipt_email'] = $order->billing_email; |
338 | 338 | } |
339 | 339 | |
340 | - $post_data['expand[]'] = 'balance_transaction'; |
|
340 | + $post_data['expand[]'] = 'balance_transaction'; |
|
341 | 341 | |
342 | - if ( $source->customer ) { |
|
342 | + if ($source->customer) { |
|
343 | 343 | $post_data['customer'] = $source->customer; |
344 | 344 | } |
345 | 345 | |
346 | - if ( $source->source ) { |
|
346 | + if ($source->source) { |
|
347 | 347 | $post_data['source'] = $source->source; |
348 | 348 | } |
349 | 349 | |
350 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
350 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -355,22 +355,22 @@ discard block |
||
355 | 355 | * @param bool $force_customer Should we force customer creation? |
356 | 356 | * @return object |
357 | 357 | */ |
358 | - protected function get_source( $user_id, $force_customer = false ) { |
|
359 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
358 | + protected function get_source($user_id, $force_customer = false) { |
|
359 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
360 | 360 | $stripe_source = false; |
361 | 361 | $token_id = false; |
362 | 362 | |
363 | 363 | // New CC info was entered and we have a new token to process |
364 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
365 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
366 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
364 | + if (isset($_POST['stripe_token'])) { |
|
365 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
366 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
367 | 367 | |
368 | 368 | // This is true if the user wants to store the card to their account. |
369 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
370 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
369 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
370 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
371 | 371 | |
372 | - if ( is_wp_error( $stripe_source ) ) { |
|
373 | - throw new Exception( $stripe_source->get_error_message() ); |
|
372 | + if (is_wp_error($stripe_source)) { |
|
373 | + throw new Exception($stripe_source->get_error_message()); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | } else { |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | } |
382 | 382 | |
383 | 383 | // Use an existing token, and then process the payment |
384 | - elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
385 | - $stripe_source = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
384 | + elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
385 | + $stripe_source = wc_clean($_POST['wc-stripe-payment-token']); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | return (object) array( |
@@ -403,16 +403,16 @@ discard block |
||
403 | 403 | * @param object $order |
404 | 404 | * @return object |
405 | 405 | */ |
406 | - protected function get_order_source( $order = null ) { |
|
406 | + protected function get_order_source($order = null) { |
|
407 | 407 | $stripe_customer = new WC_Stripe_Customer(); |
408 | 408 | $stripe_source = false; |
409 | 409 | $token_id = false; |
410 | 410 | |
411 | - if ( $order ) { |
|
412 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
413 | - $stripe_customer->set_id( $meta_value ); |
|
411 | + if ($order) { |
|
412 | + if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
413 | + $stripe_customer->set_id($meta_value); |
|
414 | 414 | } |
415 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
415 | + if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
416 | 416 | $stripe_source = $meta_value; |
417 | 417 | } |
418 | 418 | } |
@@ -427,43 +427,43 @@ discard block |
||
427 | 427 | /** |
428 | 428 | * Process the payment |
429 | 429 | */ |
430 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
430 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
431 | 431 | try { |
432 | - $order = wc_get_order( $order_id ); |
|
433 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
432 | + $order = wc_get_order($order_id); |
|
433 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
434 | 434 | |
435 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
436 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
437 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
438 | - throw new Exception( $error_msg ); |
|
435 | + if (empty($source->source) && empty($source->customer)) { |
|
436 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
437 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
438 | + throw new Exception($error_msg); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | // Store source to order meta |
442 | - $this->save_source( $order, $source ); |
|
442 | + $this->save_source($order, $source); |
|
443 | 443 | |
444 | 444 | // Handle payment |
445 | - if ( $order->get_total() > 0 ) { |
|
445 | + if ($order->get_total() > 0) { |
|
446 | 446 | |
447 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
448 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
447 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
448 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
449 | 449 | } |
450 | 450 | |
451 | - WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
451 | + WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
452 | 452 | |
453 | 453 | // Make the request |
454 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
454 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
455 | 455 | |
456 | - if ( is_wp_error( $response ) ) { |
|
456 | + if (is_wp_error($response)) { |
|
457 | 457 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
458 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
459 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
460 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
458 | + if ('customer' === $response->get_error_code() && $retry) { |
|
459 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
460 | + return $this->process_payment($order_id, false, $force_customer); |
|
461 | 461 | } |
462 | - throw new Exception( $response->get_error_code() . ': ' . $response->get_error_message() ); |
|
462 | + throw new Exception($response->get_error_code() . ': ' . $response->get_error_message()); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | // Process valid response |
466 | - $this->process_response( $response, $order ); |
|
466 | + $this->process_response($response, $order); |
|
467 | 467 | } else { |
468 | 468 | $order->payment_complete(); |
469 | 469 | } |
@@ -474,13 +474,13 @@ discard block |
||
474 | 474 | // Return thank you page redirect |
475 | 475 | return array( |
476 | 476 | 'result' => 'success', |
477 | - 'redirect' => $this->get_return_url( $order ) |
|
477 | + 'redirect' => $this->get_return_url($order) |
|
478 | 478 | ); |
479 | 479 | |
480 | - } catch ( Exception $e ) { |
|
481 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
482 | - WC()->session->set( 'refresh_totals', true ); |
|
483 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
480 | + } catch (Exception $e) { |
|
481 | + wc_add_notice($e->getMessage(), 'error'); |
|
482 | + WC()->session->set('refresh_totals', true); |
|
483 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
484 | 484 | return; |
485 | 485 | } |
486 | 486 | } |
@@ -488,45 +488,45 @@ discard block |
||
488 | 488 | /** |
489 | 489 | * Save source to order. |
490 | 490 | */ |
491 | - protected function save_source( $order, $source ) { |
|
491 | + protected function save_source($order, $source) { |
|
492 | 492 | // Store source in the order |
493 | - if ( $source->customer ) { |
|
494 | - update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
493 | + if ($source->customer) { |
|
494 | + update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
495 | 495 | } |
496 | - if ( $source->source ) { |
|
497 | - update_post_meta( $order->id, '_stripe_card_id', $source->source->id ); |
|
496 | + if ($source->source) { |
|
497 | + update_post_meta($order->id, '_stripe_card_id', $source->source->id); |
|
498 | 498 | } |
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
502 | 502 | * Store extra meta data for an order from a Stripe Response. |
503 | 503 | */ |
504 | - public function process_response( $response, $order ) { |
|
505 | - WC_Stripe::log( "Processing response: " . print_r( $response, true ) ); |
|
504 | + public function process_response($response, $order) { |
|
505 | + WC_Stripe::log("Processing response: " . print_r($response, true)); |
|
506 | 506 | |
507 | 507 | // Store charge data |
508 | - update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
509 | - update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
508 | + update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
509 | + update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
510 | 510 | |
511 | 511 | // Store other data such as fees |
512 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
513 | - $fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' ); |
|
514 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
515 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee ); |
|
512 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
513 | + $fee = number_format($response->balance_transaction->fee / 100, 2, '.', ''); |
|
514 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
515 | + update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee); |
|
516 | 516 | } |
517 | 517 | |
518 | - if ( $response->captured ) { |
|
519 | - $order->payment_complete( $response->id ); |
|
520 | - WC_Stripe::log( "Successful charge: $response->id" ); |
|
518 | + if ($response->captured) { |
|
519 | + $order->payment_complete($response->id); |
|
520 | + WC_Stripe::log("Successful charge: $response->id"); |
|
521 | 521 | } else { |
522 | - add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
522 | + add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
523 | 523 | |
524 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
524 | + if ($order->has_status(array('pending', 'failed'))) { |
|
525 | 525 | $order->reduce_order_stock(); |
526 | 526 | } |
527 | 527 | |
528 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
529 | - WC_Stripe::log( "Successful auth: $response->id" ); |
|
528 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
529 | + WC_Stripe::log("Successful auth: $response->id"); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | return $response; |
@@ -538,21 +538,21 @@ discard block |
||
538 | 538 | * @since 3.0.0 |
539 | 539 | */ |
540 | 540 | public function add_payment_method() { |
541 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
542 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
541 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
542 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
543 | 543 | return; |
544 | 544 | } |
545 | 545 | |
546 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
547 | - $result = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
546 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
547 | + $result = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
548 | 548 | |
549 | - if ( is_wp_error( $result ) ) { |
|
550 | - throw new Exception( $result->get_error_message() ); |
|
549 | + if (is_wp_error($result)) { |
|
550 | + throw new Exception($result->get_error_message()); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | return array( |
554 | 554 | 'result' => 'success', |
555 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
555 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
556 | 556 | ); |
557 | 557 | } |
558 | 558 | |
@@ -562,36 +562,36 @@ discard block |
||
562 | 562 | * @param float $amount |
563 | 563 | * @return bool |
564 | 564 | */ |
565 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
566 | - $order = wc_get_order( $order_id ); |
|
565 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
566 | + $order = wc_get_order($order_id); |
|
567 | 567 | |
568 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
568 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
569 | 569 | return false; |
570 | 570 | } |
571 | 571 | |
572 | 572 | $body = array(); |
573 | 573 | |
574 | - if ( ! is_null( $amount ) ) { |
|
575 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
574 | + if ( ! is_null($amount)) { |
|
575 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
576 | 576 | } |
577 | 577 | |
578 | - if ( $reason ) { |
|
578 | + if ($reason) { |
|
579 | 579 | $body['metadata'] = array( |
580 | 580 | 'reason' => $reason, |
581 | 581 | ); |
582 | 582 | } |
583 | 583 | |
584 | - WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
584 | + WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
585 | 585 | |
586 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
586 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
587 | 587 | |
588 | - if ( is_wp_error( $response ) ) { |
|
589 | - WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
588 | + if (is_wp_error($response)) { |
|
589 | + WC_Stripe::log("Error: " . $response->get_error_message()); |
|
590 | 590 | return $response; |
591 | - } elseif ( ! empty( $response->id ) ) { |
|
592 | - $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
593 | - $order->add_order_note( $refund_message ); |
|
594 | - WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
591 | + } elseif ( ! empty($response->id)) { |
|
592 | + $refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
593 | + $order->add_order_note($refund_message); |
|
594 | + WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message))); |
|
595 | 595 | return true; |
596 | 596 | } |
597 | 597 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -96,28 +96,28 @@ discard block |
||
96 | 96 | public function __construct() { |
97 | 97 | self::$_this = $this; |
98 | 98 | |
99 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
99 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
100 | 100 | |
101 | - $this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
101 | + $this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
102 | 102 | |
103 | 103 | // If both site title and statement descriptor is not set. Fallback. |
104 | - if ( empty( $this->statement_descriptor ) ) { |
|
104 | + if (empty($this->statement_descriptor)) { |
|
105 | 105 | $this->statement_descriptor = $_SERVER['SERVER_NAME']; |
106 | 106 | } |
107 | 107 | |
108 | - $this->enabled = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false; |
|
109 | - $this->testmode = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false; |
|
110 | - $this->capture = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false; |
|
111 | - $this->saved_cards = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false; |
|
112 | - $this->apple_pay = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false; |
|
113 | - $this->apple_pay_button = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
114 | - $this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
115 | - $this->logging = ( ! empty( $gateway_settings['logging'] ) && 'yes' === $gateway_settings['logging'] ) ? true : false; |
|
116 | - $this->publishable_key = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : ''; |
|
108 | + $this->enabled = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false; |
|
109 | + $this->testmode = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false; |
|
110 | + $this->capture = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false; |
|
111 | + $this->saved_cards = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false; |
|
112 | + $this->apple_pay = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false; |
|
113 | + $this->apple_pay_button = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
114 | + $this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
115 | + $this->logging = ( ! empty($gateway_settings['logging']) && 'yes' === $gateway_settings['logging']) ? true : false; |
|
116 | + $this->publishable_key = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : ''; |
|
117 | 117 | $this->is_shipping_enabled = $this->is_shipping_enabled(); |
118 | 118 | |
119 | - if ( $this->testmode ) { |
|
120 | - $this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : ''; |
|
119 | + if ($this->testmode) { |
|
120 | + $this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : ''; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | $this->init(); |
@@ -136,53 +136,53 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function init() { |
138 | 138 | // If Apple Pay is not enabled no need to proceed further. |
139 | - if ( ! $this->apple_pay ) { |
|
139 | + if ( ! $this->apple_pay) { |
|
140 | 140 | return; |
141 | 141 | } |
142 | 142 | |
143 | - add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) ); |
|
144 | - add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) ); |
|
143 | + add_action('wp_enqueue_scripts', array($this, 'cart_scripts')); |
|
144 | + add_action('wp_enqueue_scripts', array($this, 'single_scripts')); |
|
145 | 145 | |
146 | 146 | /** |
147 | 147 | * In order to display the Apple Pay button in the correct position, |
148 | 148 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
149 | 149 | * CSS is used to position the button. |
150 | 150 | */ |
151 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
152 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 ); |
|
151 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
152 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1); |
|
153 | 153 | } else { |
154 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 ); |
|
154 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1); |
|
155 | 155 | } |
156 | 156 | |
157 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 ); |
|
158 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
159 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 ); |
|
160 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
161 | - add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) ); |
|
162 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
163 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
164 | - add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) ); |
|
165 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) ); |
|
166 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
167 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
168 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
169 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
157 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1); |
|
158 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2); |
|
159 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1); |
|
160 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2); |
|
161 | + add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors')); |
|
162 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
163 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
164 | + add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart')); |
|
165 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single')); |
|
166 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
167 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
168 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
169 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Filters the gateway title to reflect Apple Pay. |
174 | 174 | * |
175 | 175 | */ |
176 | - public function filter_gateway_title( $title, $id ) { |
|
176 | + public function filter_gateway_title($title, $id) { |
|
177 | 177 | global $post; |
178 | 178 | |
179 | - if ( ! is_object( $post ) ) { |
|
179 | + if ( ! is_object($post)) { |
|
180 | 180 | return $title; |
181 | 181 | } |
182 | 182 | |
183 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
183 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
184 | 184 | |
185 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
185 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
186 | 186 | return $method_title; |
187 | 187 | } |
188 | 188 | |
@@ -196,13 +196,13 @@ discard block |
||
196 | 196 | * @version 3.1.4 |
197 | 197 | */ |
198 | 198 | public function log_apple_pay_errors() { |
199 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
200 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
199 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
200 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
201 | 201 | } |
202 | 202 | |
203 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
203 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
204 | 204 | |
205 | - $this->log( $errors ); |
|
205 | + $this->log($errors); |
|
206 | 206 | |
207 | 207 | exit; |
208 | 208 | } |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | * @since 3.1.4 |
214 | 214 | * @version 3.1.4 |
215 | 215 | */ |
216 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
216 | + public function postal_code_validation($valid, $postcode, $country) { |
|
217 | 217 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
218 | 218 | |
219 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
219 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
220 | 220 | return $valid; |
221 | 221 | } |
222 | 222 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * when passing it back from the shippingcontactselected object. This causes WC to invalidate |
226 | 226 | * the order and not let it go through. The remedy for now is just to remove this validation. |
227 | 227 | */ |
228 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
228 | + if ('GB' === $country || 'CA' === $country) { |
|
229 | 229 | return true; |
230 | 230 | } |
231 | 231 | |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | * @return bool |
241 | 241 | */ |
242 | 242 | public function is_shipping_enabled() { |
243 | - $shipping_enabled = get_option( 'woocommerce_ship_to_countries', '' ); |
|
243 | + $shipping_enabled = get_option('woocommerce_ship_to_countries', ''); |
|
244 | 244 | |
245 | - if ( 'disabled' === $shipping_enabled ) { |
|
245 | + if ('disabled' === $shipping_enabled) { |
|
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | |
@@ -256,42 +256,42 @@ discard block |
||
256 | 256 | * @version 3.1.4 |
257 | 257 | */ |
258 | 258 | public function single_scripts() { |
259 | - if ( ! is_single() ) { |
|
259 | + if ( ! is_single()) { |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | |
263 | 263 | global $post; |
264 | 264 | |
265 | - $product = wc_get_product( $post->ID ); |
|
265 | + $product = wc_get_product($post->ID); |
|
266 | 266 | |
267 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
267 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
271 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
272 | 272 | |
273 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
273 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
274 | 274 | |
275 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
276 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay_single', plugins_url( 'assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
275 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
276 | + wp_enqueue_script('woocommerce_stripe_apple_pay_single', plugins_url('assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
277 | 277 | |
278 | 278 | $stripe_params = array( |
279 | 279 | 'key' => $this->publishable_key, |
280 | 280 | 'currency_code' => get_woocommerce_currency(), |
281 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
281 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
282 | 282 | 'label' => $this->statement_descriptor, |
283 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
284 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
285 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
286 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
287 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
288 | - 'needs_shipping' => ( $product->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no', |
|
283 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
284 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
285 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
286 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
287 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
288 | + 'needs_shipping' => ($product->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no', |
|
289 | 289 | 'i18n' => array( |
290 | - 'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
290 | + 'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
291 | 291 | ), |
292 | 292 | ); |
293 | 293 | |
294 | - wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) ); |
|
294 | + wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params)); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -301,32 +301,32 @@ discard block |
||
301 | 301 | * @version 3.1.0 |
302 | 302 | */ |
303 | 303 | public function cart_scripts() { |
304 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
304 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
305 | 305 | return; |
306 | 306 | } |
307 | 307 | |
308 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
308 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
309 | 309 | |
310 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
310 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
311 | 311 | |
312 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
313 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
312 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
313 | + wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
314 | 314 | |
315 | 315 | $stripe_params = array( |
316 | 316 | 'key' => $this->publishable_key, |
317 | 317 | 'currency_code' => get_woocommerce_currency(), |
318 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
318 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
319 | 319 | 'label' => $this->statement_descriptor, |
320 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
321 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
322 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
323 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
324 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
325 | - 'needs_shipping' => ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no', |
|
320 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
321 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
322 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
323 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
324 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
325 | + 'needs_shipping' => (WC()->cart->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no', |
|
326 | 326 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
327 | 327 | ); |
328 | 328 | |
329 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
329 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | * @return array |
338 | 338 | */ |
339 | 339 | public function supported_product_types() { |
340 | - return apply_filters( 'wc_stripe_apple_pay_supported_types', array( |
|
340 | + return apply_filters('wc_stripe_apple_pay_supported_types', array( |
|
341 | 341 | 'simple', |
342 | 342 | 'variable', |
343 | 343 | 'variation', |
344 | - ) ); |
|
344 | + )); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -353,10 +353,10 @@ discard block |
||
353 | 353 | * @return bool |
354 | 354 | */ |
355 | 355 | public function allowed_items_in_cart() { |
356 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
357 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
356 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
357 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
358 | 358 | |
359 | - if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
359 | + if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
360 | 360 | return false; |
361 | 361 | } |
362 | 362 | } |
@@ -377,29 +377,29 @@ discard block |
||
377 | 377 | * In order for the Apple Pay button to show on product detail page, |
378 | 378 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
379 | 379 | */ |
380 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
381 | - $this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
380 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
381 | + $this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
382 | 382 | return; |
383 | 383 | } |
384 | 384 | |
385 | - if ( is_single() ) { |
|
385 | + if (is_single()) { |
|
386 | 386 | global $post; |
387 | 387 | |
388 | - $product = wc_get_product( $post->ID ); |
|
388 | + $product = wc_get_product($post->ID); |
|
389 | 389 | |
390 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
390 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
391 | 391 | return; |
392 | 392 | } |
393 | 393 | } else { |
394 | - if ( ! $this->allowed_items_in_cart() ) { |
|
395 | - $this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
394 | + if ( ! $this->allowed_items_in_cart()) { |
|
395 | + $this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
396 | 396 | return; |
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | 400 | ?> |
401 | 401 | <div class="apple-pay-button-wrapper"> |
402 | - <button class="apple-pay-button" lang="<?php echo esc_attr( $this->apple_pay_button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $this->apple_pay_button ); ?>;" alt="<?php esc_attr_e( 'Buy with Apple Pay', 'woocommerce-gateway-stripe' ); ?>"></button> |
|
402 | + <button class="apple-pay-button" lang="<?php echo esc_attr($this->apple_pay_button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($this->apple_pay_button); ?>;" alt="<?php esc_attr_e('Buy with Apple Pay', 'woocommerce-gateway-stripe'); ?>"></button> |
|
403 | 403 | </div> |
404 | 404 | <?php |
405 | 405 | } |
@@ -417,17 +417,17 @@ discard block |
||
417 | 417 | * In order for the Apple Pay button to show on cart page, |
418 | 418 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
419 | 419 | */ |
420 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
421 | - $this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
420 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
421 | + $this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
422 | 422 | return; |
423 | 423 | } |
424 | 424 | |
425 | - if ( ! $this->allowed_items_in_cart() ) { |
|
426 | - $this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
425 | + if ( ! $this->allowed_items_in_cart()) { |
|
426 | + $this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
427 | 427 | return; |
428 | 428 | } |
429 | 429 | ?> |
430 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
430 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
431 | 431 | <?php |
432 | 432 | } |
433 | 433 | |
@@ -438,51 +438,51 @@ discard block |
||
438 | 438 | * @version 3.1.0 |
439 | 439 | */ |
440 | 440 | public function generate_apple_pay_single() { |
441 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
442 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
441 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
442 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
443 | 443 | } |
444 | 444 | |
445 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
446 | - define( 'WOOCOMMERCE_CART', true ); |
|
445 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
446 | + define('WOOCOMMERCE_CART', true); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | WC()->shipping->reset_shipping(); |
450 | 450 | |
451 | 451 | global $post; |
452 | 452 | |
453 | - $product = wc_get_product( $post->ID ); |
|
454 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
453 | + $product = wc_get_product($post->ID); |
|
454 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
455 | 455 | |
456 | 456 | /** |
457 | 457 | * If this page is single product page, we need to simulate |
458 | 458 | * adding the product to the cart taken account if it is a |
459 | 459 | * simple or variable product. |
460 | 460 | */ |
461 | - if ( is_single() ) { |
|
461 | + if (is_single()) { |
|
462 | 462 | // First empty the cart to prevent wrong calculation. |
463 | 463 | WC()->cart->empty_cart(); |
464 | 464 | |
465 | - if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
466 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
465 | + if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
466 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
467 | 467 | |
468 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
469 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
468 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
469 | + $variation_id = $product->get_matching_variation($attributes); |
|
470 | 470 | } else { |
471 | - $data_store = WC_Data_Store::load( 'product' ); |
|
472 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
471 | + $data_store = WC_Data_Store::load('product'); |
|
472 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
473 | 473 | } |
474 | 474 | |
475 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
475 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
476 | 476 | } |
477 | 477 | |
478 | - if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) { |
|
479 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
478 | + if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) { |
|
479 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
480 | 480 | } |
481 | 481 | } |
482 | 482 | |
483 | 483 | WC()->cart->calculate_totals(); |
484 | 484 | |
485 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
485 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | /** |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | * @version 3.1.0 |
493 | 493 | */ |
494 | 494 | public function generate_apple_pay_cart() { |
495 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
496 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
495 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
496 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
497 | 497 | } |
498 | 498 | |
499 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
499 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
@@ -517,29 +517,29 @@ discard block |
||
517 | 517 | * @version 3.1.0 |
518 | 518 | * @param array $address |
519 | 519 | */ |
520 | - public function calculate_shipping( $address = array() ) { |
|
521 | - $country = strtoupper( $address['countryCode'] ); |
|
522 | - $state = strtoupper( $address['administrativeArea'] ); |
|
520 | + public function calculate_shipping($address = array()) { |
|
521 | + $country = strtoupper($address['countryCode']); |
|
522 | + $state = strtoupper($address['administrativeArea']); |
|
523 | 523 | $postcode = $address['postalCode']; |
524 | 524 | $city = $address['locality']; |
525 | 525 | |
526 | 526 | WC()->shipping->reset_shipping(); |
527 | 527 | |
528 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
529 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
530 | - } elseif ( $postcode ) { |
|
531 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
528 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
529 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
530 | + } elseif ($postcode) { |
|
531 | + $postcode = wc_format_postcode($postcode, $country); |
|
532 | 532 | } |
533 | 533 | |
534 | - if ( $country ) { |
|
535 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
536 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
534 | + if ($country) { |
|
535 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
536 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
537 | 537 | } else { |
538 | 538 | WC()->customer->set_to_base(); |
539 | 539 | WC()->customer->set_shipping_to_base(); |
540 | 540 | } |
541 | 541 | |
542 | - version_compare( WC_VERSION, '3.0', '<' ) ? WC()->customer->calculated_shipping( true ) : WC()->customer->set_calculated_shipping( true ); |
|
542 | + version_compare(WC_VERSION, '3.0', '<') ? WC()->customer->calculated_shipping(true) : WC()->customer->set_calculated_shipping(true); |
|
543 | 543 | |
544 | 544 | WC()->customer->save(); |
545 | 545 | |
@@ -563,17 +563,17 @@ discard block |
||
563 | 563 | $packages[0]['destination']['postcode'] = $postcode; |
564 | 564 | $packages[0]['destination']['city'] = $city; |
565 | 565 | |
566 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
567 | - if ( $item['data']->needs_shipping() ) { |
|
568 | - if ( isset( $item['line_total'] ) ) { |
|
566 | + foreach (WC()->cart->get_cart() as $item) { |
|
567 | + if ($item['data']->needs_shipping()) { |
|
568 | + if (isset($item['line_total'])) { |
|
569 | 569 | $packages[0]['contents_cost'] += $item['line_total']; |
570 | 570 | } |
571 | 571 | } |
572 | 572 | } |
573 | 573 | |
574 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
574 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
575 | 575 | |
576 | - WC()->shipping->calculate_shipping( $packages ); |
|
576 | + WC()->shipping->calculate_shipping($packages); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -583,18 +583,18 @@ discard block |
||
583 | 583 | * @version 3.1.0 |
584 | 584 | */ |
585 | 585 | public function get_shipping_methods() { |
586 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
587 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
586 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
587 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
588 | 588 | } |
589 | 589 | |
590 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
591 | - define( 'WOOCOMMERCE_CART', true ); |
|
590 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
591 | + define('WOOCOMMERCE_CART', true); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | try { |
595 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
595 | + $address = array_map('wc_clean', $_POST['address']); |
|
596 | 596 | |
597 | - $this->calculate_shipping( $address ); |
|
597 | + $this->calculate_shipping($address); |
|
598 | 598 | |
599 | 599 | // Set the shipping options. |
600 | 600 | $currency = get_woocommerce_currency(); |
@@ -602,13 +602,13 @@ discard block |
||
602 | 602 | |
603 | 603 | $packages = WC()->shipping->get_packages(); |
604 | 604 | |
605 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
606 | - foreach ( $packages as $package_key => $package ) { |
|
607 | - if ( empty( $package['rates'] ) ) { |
|
608 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
605 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
606 | + foreach ($packages as $package_key => $package) { |
|
607 | + if (empty($package['rates'])) { |
|
608 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
609 | 609 | } |
610 | 610 | |
611 | - foreach ( $package['rates'] as $key => $rate ) { |
|
611 | + foreach ($package['rates'] as $key => $rate) { |
|
612 | 612 | $data[] = array( |
613 | 613 | 'id' => $rate->id, |
614 | 614 | 'label' => $rate->label, |
@@ -622,16 +622,16 @@ discard block |
||
622 | 622 | } |
623 | 623 | |
624 | 624 | // Auto select the first shipping method. |
625 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
625 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
626 | 626 | |
627 | 627 | WC()->cart->calculate_totals(); |
628 | 628 | |
629 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
629 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
630 | 630 | } else { |
631 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
631 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
632 | 632 | } |
633 | - } catch ( Exception $e ) { |
|
634 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
633 | + } catch (Exception $e) { |
|
634 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
635 | 635 | } |
636 | 636 | } |
637 | 637 | |
@@ -642,29 +642,29 @@ discard block |
||
642 | 642 | * @version 3.1.0 |
643 | 643 | */ |
644 | 644 | public function update_shipping_method() { |
645 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
646 | - define( 'WOOCOMMERCE_CART', true ); |
|
645 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
646 | + define('WOOCOMMERCE_CART', true); |
|
647 | 647 | } |
648 | 648 | |
649 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
650 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
649 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
650 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
651 | 651 | } |
652 | 652 | |
653 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
653 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
654 | 654 | |
655 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
655 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
656 | 656 | |
657 | 657 | WC()->cart->calculate_totals(); |
658 | 658 | |
659 | 659 | // Send back the new cart total. |
660 | 660 | $currency = get_woocommerce_currency(); |
661 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
661 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
662 | 662 | $data = array( |
663 | 663 | 'total' => WC()->cart->total, |
664 | 664 | ); |
665 | 665 | |
666 | 666 | // Include fees and taxes as displayItems. |
667 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
667 | + foreach (WC()->cart->fees as $key => $fee) { |
|
668 | 668 | $data['items'][] = array( |
669 | 669 | 'label' => $fee->name, |
670 | 670 | 'amount' => array( |
@@ -673,9 +673,9 @@ discard block |
||
673 | 673 | ), |
674 | 674 | ); |
675 | 675 | } |
676 | - if ( 0 < $tax_total ) { |
|
676 | + if (0 < $tax_total) { |
|
677 | 677 | $data['items'][] = array( |
678 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
678 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
679 | 679 | 'amount' => array( |
680 | 680 | 'currency' => $currency, |
681 | 681 | 'value' => $tax_total, |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | ); |
684 | 684 | } |
685 | 685 | |
686 | - wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
686 | + wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
@@ -694,37 +694,37 @@ discard block |
||
694 | 694 | * @version 3.1.0 |
695 | 695 | */ |
696 | 696 | public function process_apple_pay() { |
697 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
698 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
697 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
698 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | try { |
702 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
702 | + $result = array_map('wc_clean', $_POST['result']); |
|
703 | 703 | |
704 | - $order = $this->create_order( $result ); |
|
704 | + $order = $this->create_order($result); |
|
705 | 705 | |
706 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
706 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
707 | 707 | |
708 | 708 | // Handle payment. |
709 | - if ( $order->get_total() > 0 ) { |
|
709 | + if ($order->get_total() > 0) { |
|
710 | 710 | |
711 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
712 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
711 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
712 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
713 | 713 | } |
714 | 714 | |
715 | - $this->log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
715 | + $this->log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
716 | 716 | |
717 | 717 | // Make the request. |
718 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
718 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
719 | 719 | |
720 | - if ( is_wp_error( $response ) ) { |
|
720 | + if (is_wp_error($response)) { |
|
721 | 721 | $localized_messages = $this->get_localized_messages(); |
722 | 722 | |
723 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
723 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
724 | 724 | } |
725 | 725 | |
726 | 726 | // Process valid response. |
727 | - $this->process_response( $response, $order ); |
|
727 | + $this->process_response($response, $order); |
|
728 | 728 | } else { |
729 | 729 | $order->payment_complete(); |
730 | 730 | } |
@@ -732,24 +732,24 @@ discard block |
||
732 | 732 | // Remove cart. |
733 | 733 | WC()->cart->empty_cart(); |
734 | 734 | |
735 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
736 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
735 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
736 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
737 | 737 | |
738 | 738 | // Return thank you page redirect. |
739 | - wp_send_json( array( |
|
739 | + wp_send_json(array( |
|
740 | 740 | 'success' => 'true', |
741 | - 'redirect' => $this->get_return_url( $order ), |
|
742 | - ) ); |
|
741 | + 'redirect' => $this->get_return_url($order), |
|
742 | + )); |
|
743 | 743 | |
744 | - } catch ( Exception $e ) { |
|
745 | - WC()->session->set( 'refresh_totals', true ); |
|
746 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
744 | + } catch (Exception $e) { |
|
745 | + WC()->session->set('refresh_totals', true); |
|
746 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
747 | 747 | |
748 | - if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
749 | - $this->send_failed_order_email( $order_id ); |
|
748 | + if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) { |
|
749 | + $this->send_failed_order_email($order_id); |
|
750 | 750 | } |
751 | 751 | |
752 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
752 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
@@ -759,16 +759,16 @@ discard block |
||
759 | 759 | * @param string $source token |
760 | 760 | * @return array() |
761 | 761 | */ |
762 | - protected function generate_payment_request( $order, $source ) { |
|
762 | + protected function generate_payment_request($order, $source) { |
|
763 | 763 | $post_data = array(); |
764 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
765 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
766 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
764 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
765 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
766 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
767 | 767 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
768 | 768 | |
769 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
769 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
770 | 770 | |
771 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
771 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
772 | 772 | $post_data['receipt_email'] = $billing_email; |
773 | 773 | } |
774 | 774 | |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | * @param WC_Order $order |
784 | 784 | * @param object $source |
785 | 785 | */ |
786 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
786 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -792,14 +792,14 @@ discard block |
||
792 | 792 | * @since 3.1.0 |
793 | 793 | * @version 3.1.0 |
794 | 794 | */ |
795 | - public function build_shipping_methods( $shipping_methods ) { |
|
796 | - if ( empty( $shipping_methods ) ) { |
|
795 | + public function build_shipping_methods($shipping_methods) { |
|
796 | + if (empty($shipping_methods)) { |
|
797 | 797 | return array(); |
798 | 798 | } |
799 | 799 | |
800 | 800 | $shipping = array(); |
801 | 801 | |
802 | - foreach ( $shipping_methods as $method ) { |
|
802 | + foreach ($shipping_methods as $method) { |
|
803 | 803 | $shipping[] = array( |
804 | 804 | 'label' => $method['label'], |
805 | 805 | 'detail' => '', |
@@ -818,67 +818,67 @@ discard block |
||
818 | 818 | * @version 3.1.0 |
819 | 819 | */ |
820 | 820 | public function build_line_items() { |
821 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
822 | - define( 'WOOCOMMERCE_CART', true ); |
|
821 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
822 | + define('WOOCOMMERCE_CART', true); |
|
823 | 823 | } |
824 | 824 | |
825 | - $decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 ); |
|
825 | + $decimals = apply_filters('wc_stripe_apple_pay_decimals', 2); |
|
826 | 826 | |
827 | 827 | $items = array(); |
828 | 828 | $subtotal = 0; |
829 | 829 | |
830 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
831 | - $amount = wc_format_decimal( $cart_item['line_subtotal'], $decimals ); |
|
832 | - $subtotal += $cart_item['line_subtotal']; |
|
830 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
831 | + $amount = wc_format_decimal($cart_item['line_subtotal'], $decimals); |
|
832 | + $subtotal += $cart_item['line_subtotal']; |
|
833 | 833 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
834 | 834 | |
835 | - $product_name = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
835 | + $product_name = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
836 | 836 | |
837 | 837 | $item = array( |
838 | 838 | 'type' => 'final', |
839 | 839 | 'label' => $product_name . $quantity_label, |
840 | - 'amount' => wc_format_decimal( $amount, $decimals ), |
|
840 | + 'amount' => wc_format_decimal($amount, $decimals), |
|
841 | 841 | ); |
842 | 842 | |
843 | 843 | $items[] = $item; |
844 | 844 | } |
845 | 845 | |
846 | 846 | // Default show only subtotal instead of itemization. |
847 | - if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) { |
|
847 | + if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) { |
|
848 | 848 | $items = array(); |
849 | 849 | $items[] = array( |
850 | 850 | 'type' => 'final', |
851 | - 'label' => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ), |
|
852 | - 'amount' => wc_format_decimal( $subtotal, $decimals ), |
|
851 | + 'label' => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')), |
|
852 | + 'amount' => wc_format_decimal($subtotal, $decimals), |
|
853 | 853 | ); |
854 | 854 | } |
855 | 855 | |
856 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals ); |
|
857 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); |
|
858 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $decimals ); |
|
859 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts; |
|
860 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
856 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals); |
|
857 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals); |
|
858 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $decimals); |
|
859 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts; |
|
860 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
861 | 861 | |
862 | - if ( wc_tax_enabled() ) { |
|
862 | + if (wc_tax_enabled()) { |
|
863 | 863 | $items[] = array( |
864 | 864 | 'type' => 'final', |
865 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
865 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
866 | 866 | 'amount' => $tax, |
867 | 867 | ); |
868 | 868 | } |
869 | 869 | |
870 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) { |
|
870 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled) { |
|
871 | 871 | $items[] = array( |
872 | 872 | 'type' => 'final', |
873 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
873 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
874 | 874 | 'amount' => $shipping, |
875 | 875 | ); |
876 | 876 | } |
877 | 877 | |
878 | - if ( WC()->cart->has_discount() ) { |
|
878 | + if (WC()->cart->has_discount()) { |
|
879 | 879 | $items[] = array( |
880 | 880 | 'type' => 'final', |
881 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
881 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
882 | 882 | 'amount' => '-' . $discounts, |
883 | 883 | ); |
884 | 884 | } |
@@ -894,24 +894,24 @@ discard block |
||
894 | 894 | * @param array $data |
895 | 895 | * @return object $order |
896 | 896 | */ |
897 | - public function create_order( $data = array() ) { |
|
898 | - if ( empty( $data ) ) { |
|
899 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
897 | + public function create_order($data = array()) { |
|
898 | + if (empty($data)) { |
|
899 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | $order = wc_create_order(); |
903 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
903 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
904 | 904 | |
905 | - if ( is_wp_error( $order ) ) { |
|
906 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
907 | - } elseif ( false === $order ) { |
|
908 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
905 | + if (is_wp_error($order)) { |
|
906 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
907 | + } elseif (false === $order) { |
|
908 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
909 | 909 | } else { |
910 | - do_action( 'woocommerce_new_order', $order_id ); |
|
910 | + do_action('woocommerce_new_order', $order_id); |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | // Store the line items to the new/resumed order |
914 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
914 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
915 | 915 | $item_id = $order->add_product( |
916 | 916 | $values['data'], |
917 | 917 | $values['quantity'], |
@@ -927,25 +927,25 @@ discard block |
||
927 | 927 | ) |
928 | 928 | ); |
929 | 929 | |
930 | - if ( ! $item_id ) { |
|
931 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
930 | + if ( ! $item_id) { |
|
931 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
932 | 932 | } |
933 | 933 | |
934 | 934 | // Allow plugins to add order item meta |
935 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
936 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
935 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
936 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
937 | 937 | } else { |
938 | - do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() ); |
|
938 | + do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id()); |
|
939 | 939 | } |
940 | 940 | } |
941 | 941 | |
942 | 942 | // Store fees |
943 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
944 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
945 | - $item_id = $order->add_fee( $fee ); |
|
943 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
944 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
945 | + $item_id = $order->add_fee($fee); |
|
946 | 946 | } else { |
947 | 947 | $item = new WC_Order_Item_Fee(); |
948 | - $item->set_props( array( |
|
948 | + $item->set_props(array( |
|
949 | 949 | 'name' => $fee->name, |
950 | 950 | 'tax_class' => $fee->taxable ? $fee->tax_class : 0, |
951 | 951 | 'total' => $fee->amount, |
@@ -954,79 +954,79 @@ discard block |
||
954 | 954 | 'total' => $fee->tax_data, |
955 | 955 | ), |
956 | 956 | 'order_id' => $order->get_id(), |
957 | - ) ); |
|
957 | + )); |
|
958 | 958 | $item_id = $item->save(); |
959 | - $order->add_item( $item ); |
|
959 | + $order->add_item($item); |
|
960 | 960 | } |
961 | 961 | |
962 | - if ( ! $item_id ) { |
|
963 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
962 | + if ( ! $item_id) { |
|
963 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | // Allow plugins to add order item meta to fees |
967 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
968 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
967 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
968 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
969 | 969 | } else { |
970 | - do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() ); |
|
970 | + do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id()); |
|
971 | 971 | } |
972 | 972 | } |
973 | 973 | |
974 | 974 | // Store tax rows |
975 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
976 | - $tax_amount = WC()->cart->get_tax_amount( $tax_rate_id ); |
|
977 | - $shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id ); |
|
975 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
976 | + $tax_amount = WC()->cart->get_tax_amount($tax_rate_id); |
|
977 | + $shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id); |
|
978 | 978 | |
979 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
980 | - $item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount ); |
|
979 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
980 | + $item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount); |
|
981 | 981 | } else { |
982 | 982 | $item = new WC_Order_Item_Tax(); |
983 | - $item->set_props( array( |
|
983 | + $item->set_props(array( |
|
984 | 984 | 'rate_id' => $tax_rate_id, |
985 | 985 | 'tax_total' => $tax_amount, |
986 | 986 | 'shipping_tax_total' => $shipping_tax_amount, |
987 | - ) ); |
|
988 | - $item->set_rate( $tax_rate_id ); |
|
989 | - $item->set_order_id( $order->get_id() ); |
|
987 | + )); |
|
988 | + $item->set_rate($tax_rate_id); |
|
989 | + $item->set_order_id($order->get_id()); |
|
990 | 990 | $item_id = $item->save(); |
991 | - $order->add_item( $item ); |
|
991 | + $order->add_item($item); |
|
992 | 992 | } |
993 | 993 | |
994 | - if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
995 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
994 | + if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
995 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
996 | 996 | } |
997 | 997 | } |
998 | 998 | |
999 | 999 | // Store coupons |
1000 | - $discount = WC()->cart->get_coupon_discount_amount( $code ); |
|
1001 | - $discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code ); |
|
1000 | + $discount = WC()->cart->get_coupon_discount_amount($code); |
|
1001 | + $discount_tax = WC()->cart->get_coupon_discount_tax_amount($code); |
|
1002 | 1002 | |
1003 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
1004 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1005 | - $coupon_id = $order->add_coupon( $code, $discount, $discount_tax ); |
|
1003 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
1004 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1005 | + $coupon_id = $order->add_coupon($code, $discount, $discount_tax); |
|
1006 | 1006 | } else { |
1007 | 1007 | $item = new WC_Order_Item_Coupon(); |
1008 | - $item->set_props( array( |
|
1008 | + $item->set_props(array( |
|
1009 | 1009 | 'code' => $code, |
1010 | 1010 | 'discount' => $discount, |
1011 | 1011 | 'discount_tax' => $discount_tax, |
1012 | 1012 | 'order_id' => $order->get_id(), |
1013 | - ) ); |
|
1013 | + )); |
|
1014 | 1014 | $coupon_id = $item->save(); |
1015 | - $order->add_item( $item ); |
|
1015 | + $order->add_item($item); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | - if ( ! $coupon_id ) { |
|
1019 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
1018 | + if ( ! $coupon_id) { |
|
1019 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
1020 | 1020 | } |
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | // Billing address |
1024 | 1024 | $billing_address = array(); |
1025 | - if ( ! empty( $data['token']['card'] ) ) { |
|
1025 | + if ( ! empty($data['token']['card'])) { |
|
1026 | 1026 | // Name from Stripe is a full name string. |
1027 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
1028 | - $lastname = array_pop( $name ); |
|
1029 | - $firstname = implode( ' ', $name ); |
|
1027 | + $name = explode(' ', $data['token']['card']['name']); |
|
1028 | + $lastname = array_pop($name); |
|
1029 | + $firstname = implode(' ', $name); |
|
1030 | 1030 | $billing_address['first_name'] = $firstname; |
1031 | 1031 | $billing_address['last_name'] = $lastname; |
1032 | 1032 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1041,7 +1041,7 @@ discard block |
||
1041 | 1041 | |
1042 | 1042 | // Shipping address. |
1043 | 1043 | $shipping_address = array(); |
1044 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty( $data['shippingContact'] ) ) { |
|
1044 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty($data['shippingContact'])) { |
|
1045 | 1045 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
1046 | 1046 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
1047 | 1047 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | $shipping_address['city'] = $data['shippingContact']['locality']; |
1053 | 1053 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
1054 | 1054 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
1055 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
1055 | + } elseif ( ! empty($data['shippingContact'])) { |
|
1056 | 1056 | $shipping_address['first_name'] = $firstname; |
1057 | 1057 | $shipping_address['last_name'] = $lastname; |
1058 | 1058 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1065,33 +1065,33 @@ discard block |
||
1065 | 1065 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
1066 | 1066 | } |
1067 | 1067 | |
1068 | - $order->set_address( $billing_address, 'billing' ); |
|
1069 | - $order->set_address( $shipping_address, 'shipping' ); |
|
1068 | + $order->set_address($billing_address, 'billing'); |
|
1069 | + $order->set_address($shipping_address, 'shipping'); |
|
1070 | 1070 | |
1071 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
1071 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
1072 | 1072 | |
1073 | 1073 | // Get the rate object selected by user. |
1074 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
1075 | - foreach ( $package['rates'] as $key => $rate ) { |
|
1074 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
1075 | + foreach ($package['rates'] as $key => $rate) { |
|
1076 | 1076 | // Loop through user chosen shipping methods. |
1077 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
1078 | - if ( $method === $key ) { |
|
1079 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1080 | - $order->add_shipping( $rate ); |
|
1077 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
1078 | + if ($method === $key) { |
|
1079 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1080 | + $order->add_shipping($rate); |
|
1081 | 1081 | } else { |
1082 | 1082 | $item = new WC_Order_Item_Shipping(); |
1083 | - $item->set_props( array( |
|
1083 | + $item->set_props(array( |
|
1084 | 1084 | 'method_title' => $rate->label, |
1085 | 1085 | 'method_id' => $rate->id, |
1086 | - 'total' => wc_format_decimal( $rate->cost ), |
|
1086 | + 'total' => wc_format_decimal($rate->cost), |
|
1087 | 1087 | 'taxes' => $rate->taxes, |
1088 | 1088 | 'order_id' => $order->get_id(), |
1089 | - ) ); |
|
1090 | - foreach ( $rate->get_meta_data() as $key => $value ) { |
|
1091 | - $item->add_meta_data( $key, $value, true ); |
|
1089 | + )); |
|
1090 | + foreach ($rate->get_meta_data() as $key => $value) { |
|
1091 | + $item->add_meta_data($key, $value, true); |
|
1092 | 1092 | } |
1093 | 1093 | $item->save(); |
1094 | - $order->add_item( $item ); |
|
1094 | + $order->add_item($item); |
|
1095 | 1095 | } |
1096 | 1096 | } |
1097 | 1097 | } |
@@ -1099,27 +1099,27 @@ discard block |
||
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
1102 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
1102 | + $order->set_payment_method($available_gateways['stripe']); |
|
1103 | 1103 | |
1104 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1105 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
1106 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
1107 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
1108 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
1109 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
1110 | - $order->set_total( WC()->cart->total ); |
|
1104 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1105 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
1106 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
1107 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
1108 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
1109 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
1110 | + $order->set_total(WC()->cart->total); |
|
1111 | 1111 | } else { |
1112 | - $order->set_shipping_total( WC()->cart->shipping_total ); |
|
1113 | - $order->set_discount_total( WC()->cart->get_cart_discount_total() ); |
|
1114 | - $order->set_discount_tax( WC()->cart->get_cart_discount_tax_total() ); |
|
1115 | - $order->set_cart_tax( WC()->cart->tax_total ); |
|
1116 | - $order->set_shipping_tax( WC()->cart->shipping_tax_total ); |
|
1117 | - $order->set_total( WC()->cart->total ); |
|
1112 | + $order->set_shipping_total(WC()->cart->shipping_total); |
|
1113 | + $order->set_discount_total(WC()->cart->get_cart_discount_total()); |
|
1114 | + $order->set_discount_tax(WC()->cart->get_cart_discount_tax_total()); |
|
1115 | + $order->set_cart_tax(WC()->cart->tax_total); |
|
1116 | + $order->set_shipping_tax(WC()->cart->shipping_tax_total); |
|
1117 | + $order->set_total(WC()->cart->total); |
|
1118 | 1118 | $order->save(); |
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | // If we got here, the order was created without problems! |
1122 | - wc_transaction_query( 'commit' ); |
|
1122 | + wc_transaction_query('commit'); |
|
1123 | 1123 | |
1124 | 1124 | return $order; |
1125 | 1125 | } |
@@ -1132,9 +1132,9 @@ discard block |
||
1132 | 1132 | * |
1133 | 1133 | * @param string $message |
1134 | 1134 | */ |
1135 | - public function log( $message ) { |
|
1136 | - if ( $this->logging ) { |
|
1137 | - WC_Stripe::log( 'Apple Pay: ' . $message ); |
|
1135 | + public function log($message) { |
|
1136 | + if ($this->logging) { |
|
1137 | + WC_Stripe::log('Apple Pay: ' . $message); |
|
1138 | 1138 | } |
1139 | 1139 | } |
1140 | 1140 | } |