@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 4.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -66,35 +66,35 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | self::$_this = $this; |
69 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
70 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
71 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
72 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
73 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
69 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
70 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
71 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
72 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
73 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
74 | 74 | |
75 | - if ( $this->testmode ) { |
|
76 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
77 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
75 | + if ($this->testmode) { |
|
76 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
77 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
78 | 78 | } |
79 | 79 | |
80 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
80 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
81 | 81 | |
82 | 82 | // Checks if Stripe Gateway is enabled. |
83 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
83 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | |
87 | 87 | // Checks if Payment Request is enabled. |
88 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
88 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
89 | 89 | return; |
90 | 90 | } |
91 | 91 | |
92 | 92 | // Don't load for change payment method page. |
93 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
93 | + if (isset($_GET['change_payment_method'])) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | 96 | |
97 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
97 | + add_action('template_redirect', array($this, 'set_session')); |
|
98 | 98 | $this->init(); |
99 | 99 | } |
100 | 100 | |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | public function are_keys_set() { |
108 | 108 | // NOTE: updates to this function should be added to are_keys_set() |
109 | 109 | // in includes/abstracts/abstract-wc-stripe-payment-gateway.php |
110 | - if ( $this->testmode ) { |
|
111 | - return preg_match( '/^pk_test_/', $this->publishable_key ) |
|
112 | - && preg_match( '/^[rs]k_test_/', $this->secret_key ); |
|
110 | + if ($this->testmode) { |
|
111 | + return preg_match('/^pk_test_/', $this->publishable_key) |
|
112 | + && preg_match('/^[rs]k_test_/', $this->secret_key); |
|
113 | 113 | } else { |
114 | - return preg_match( '/^pk_live_/', $this->publishable_key ) |
|
115 | - && preg_match( '/^[rs]k_live_/', $this->secret_key ); |
|
114 | + return preg_match('/^pk_live_/', $this->publishable_key) |
|
115 | + && preg_match('/^[rs]k_live_/', $this->secret_key); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | * @since 4.0.0 |
134 | 134 | */ |
135 | 135 | public function set_session() { |
136 | - if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
136 | + if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
140 | - WC()->session->set_customer_session_cookie( true ); |
|
140 | + WC()->session->set_customer_session_cookie(true); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -147,30 +147,30 @@ discard block |
||
147 | 147 | * @version 4.0.0 |
148 | 148 | */ |
149 | 149 | public function init() { |
150 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
150 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
151 | 151 | |
152 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
153 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
152 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
153 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
154 | 154 | |
155 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
156 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
155 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
156 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
157 | 157 | |
158 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
159 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
158 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
159 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
160 | 160 | |
161 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
162 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
163 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
164 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
165 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
166 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
167 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
168 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
161 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
162 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
163 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
164 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
165 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
166 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
167 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
168 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
169 | 169 | |
170 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
171 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
170 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
171 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
172 | 172 | |
173 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
173 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @return string |
182 | 182 | */ |
183 | 183 | public function get_button_type() { |
184 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
184 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @return string |
193 | 193 | */ |
194 | 194 | public function get_button_theme() { |
195 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
195 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function get_button_height() { |
206 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
206 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @return string |
226 | 226 | */ |
227 | 227 | public function get_button_branded_type() { |
228 | - return isset( $this->stripe_settings['payment_request_button_branded_type'] ) ? $this->stripe_settings['payment_request_button_branded_type'] : 'default'; |
|
228 | + return isset($this->stripe_settings['payment_request_button_branded_type']) ? $this->stripe_settings['payment_request_button_branded_type'] : 'default'; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @return string |
259 | 259 | */ |
260 | 260 | public function get_button_label() { |
261 | - return isset( $this->stripe_settings['payment_request_button_label'] ) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now'; |
|
261 | + return isset($this->stripe_settings['payment_request_button_label']) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now'; |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -268,22 +268,22 @@ discard block |
||
268 | 268 | * @version 4.0.0 |
269 | 269 | */ |
270 | 270 | public function get_product_data() { |
271 | - if ( ! is_product() ) { |
|
271 | + if ( ! is_product()) { |
|
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | |
275 | 275 | global $post; |
276 | 276 | |
277 | - $product = wc_get_product( $post->ID ); |
|
277 | + $product = wc_get_product($post->ID); |
|
278 | 278 | |
279 | - if ( 'variable' === $product->get_type() ) { |
|
280 | - $attributes = wc_clean( wp_unslash( $_GET ) ); |
|
279 | + if ('variable' === $product->get_type()) { |
|
280 | + $attributes = wc_clean(wp_unslash($_GET)); |
|
281 | 281 | |
282 | - $data_store = WC_Data_Store::load( 'product' ); |
|
283 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
282 | + $data_store = WC_Data_Store::load('product'); |
|
283 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
284 | 284 | |
285 | - if ( ! empty( $variation_id ) ) { |
|
286 | - $product = wc_get_product( $variation_id ); |
|
285 | + if ( ! empty($variation_id)) { |
|
286 | + $product = wc_get_product($variation_id); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
@@ -292,27 +292,27 @@ discard block |
||
292 | 292 | |
293 | 293 | $items[] = array( |
294 | 294 | 'label' => $product->get_name(), |
295 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ), |
|
295 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($product->get_price()), |
|
296 | 296 | ); |
297 | 297 | |
298 | - if ( wc_tax_enabled() ) { |
|
298 | + if (wc_tax_enabled()) { |
|
299 | 299 | $items[] = array( |
300 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
300 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
301 | 301 | 'amount' => 0, |
302 | 302 | 'pending' => true, |
303 | 303 | ); |
304 | 304 | } |
305 | 305 | |
306 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
306 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
307 | 307 | $items[] = array( |
308 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
308 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
309 | 309 | 'amount' => 0, |
310 | 310 | 'pending' => true, |
311 | 311 | ); |
312 | 312 | |
313 | 313 | $data['shippingOptions'] = array( |
314 | 314 | 'id' => 'pending', |
315 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
315 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
316 | 316 | 'detail' => '', |
317 | 317 | 'amount' => 0, |
318 | 318 | ); |
@@ -320,37 +320,37 @@ discard block |
||
320 | 320 | |
321 | 321 | $data['displayItems'] = $items; |
322 | 322 | $data['total'] = array( |
323 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
324 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ), |
|
323 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
324 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($product->get_price()), |
|
325 | 325 | 'pending' => true, |
326 | 326 | ); |
327 | 327 | |
328 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
329 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
330 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
328 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
329 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
330 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
331 | 331 | |
332 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
332 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | 336 | * Filters the gateway title to reflect Payment Request type |
337 | 337 | * |
338 | 338 | */ |
339 | - public function filter_gateway_title( $title, $id ) { |
|
339 | + public function filter_gateway_title($title, $id) { |
|
340 | 340 | global $post; |
341 | 341 | |
342 | - if ( ! is_object( $post ) ) { |
|
342 | + if ( ! is_object($post)) { |
|
343 | 343 | return $title; |
344 | 344 | } |
345 | 345 | |
346 | - $order = wc_get_order( $post->ID ); |
|
347 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
346 | + $order = wc_get_order($post->ID); |
|
347 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
348 | 348 | |
349 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
349 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
350 | 350 | return $method_title; |
351 | 351 | } |
352 | 352 | |
353 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
353 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
354 | 354 | return $method_title; |
355 | 355 | } |
356 | 356 | |
@@ -363,16 +363,16 @@ discard block |
||
363 | 363 | * @since 3.1.4 |
364 | 364 | * @version 4.0.0 |
365 | 365 | */ |
366 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
366 | + public function postal_code_validation($valid, $postcode, $country) { |
|
367 | 367 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
368 | 368 | |
369 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
369 | + if ( ! isset($gateways['stripe'])) { |
|
370 | 370 | return $valid; |
371 | 371 | } |
372 | 372 | |
373 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
373 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
374 | 374 | |
375 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
375 | + if ('apple_pay' !== $payment_request_type) { |
|
376 | 376 | return $valid; |
377 | 377 | } |
378 | 378 | |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | * the order and not let it go through. The remedy for now is just to remove this validation. |
383 | 383 | * Note that this only works with shipping providers that don't validate full postal codes. |
384 | 384 | */ |
385 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
385 | + if ('GB' === $country || 'CA' === $country) { |
|
386 | 386 | return true; |
387 | 387 | } |
388 | 388 | |
@@ -397,22 +397,22 @@ discard block |
||
397 | 397 | * @param int $order_id |
398 | 398 | * @param array $posted_data The posted data from checkout form. |
399 | 399 | */ |
400 | - public function add_order_meta( $order_id, $posted_data ) { |
|
401 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
400 | + public function add_order_meta($order_id, $posted_data) { |
|
401 | + if (empty($_POST['payment_request_type'])) { |
|
402 | 402 | return; |
403 | 403 | } |
404 | 404 | |
405 | - $order = wc_get_order( $order_id ); |
|
405 | + $order = wc_get_order($order_id); |
|
406 | 406 | |
407 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
407 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
408 | 408 | |
409 | - if ( 'apple_pay' === $payment_request_type ) { |
|
410 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
409 | + if ('apple_pay' === $payment_request_type) { |
|
410 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
411 | 411 | $order->save(); |
412 | 412 | } |
413 | 413 | |
414 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
415 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
414 | + if ('payment_request_api' === $payment_request_type) { |
|
415 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
416 | 416 | $order->save(); |
417 | 417 | } |
418 | 418 | } |
@@ -450,20 +450,20 @@ discard block |
||
450 | 450 | * @return bool |
451 | 451 | */ |
452 | 452 | public function allowed_items_in_cart() { |
453 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
454 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
453 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
454 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
455 | 455 | |
456 | - if ( ! in_array( $_product->get_type(), $this->supported_product_types() ) ) { |
|
456 | + if ( ! in_array($_product->get_type(), $this->supported_product_types())) { |
|
457 | 457 | return false; |
458 | 458 | } |
459 | 459 | |
460 | 460 | // Trial subscriptions with shipping are not supported |
461 | - if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) { |
|
461 | + if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) { |
|
462 | 462 | return false; |
463 | 463 | } |
464 | 464 | |
465 | 465 | // Pre Orders compatbility where we don't support charge upon release. |
466 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
466 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
467 | 467 | return false; |
468 | 468 | } |
469 | 469 | } |
@@ -479,59 +479,59 @@ discard block |
||
479 | 479 | */ |
480 | 480 | public function scripts() { |
481 | 481 | // If keys are not set bail. |
482 | - if ( ! $this->are_keys_set() ) { |
|
483 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
482 | + if ( ! $this->are_keys_set()) { |
|
483 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
484 | 484 | return; |
485 | 485 | } |
486 | 486 | |
487 | 487 | // If no SSL bail. |
488 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
489 | - WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
488 | + if ( ! $this->testmode && ! is_ssl()) { |
|
489 | + WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
490 | 490 | return; |
491 | 491 | } |
492 | 492 | |
493 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
493 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
494 | 494 | return; |
495 | 495 | } |
496 | 496 | |
497 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
497 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
498 | 498 | return; |
499 | 499 | } |
500 | 500 | |
501 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
501 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
502 | 502 | |
503 | 503 | $stripe_params = array( |
504 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
504 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
505 | 505 | 'stripe' => array( |
506 | 506 | 'key' => $this->publishable_key, |
507 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
507 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
508 | 508 | ), |
509 | 509 | 'nonce' => array( |
510 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
511 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
512 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
513 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
514 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
515 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
516 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
517 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
510 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
511 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
512 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
513 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
514 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
515 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
516 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
517 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
518 | 518 | ), |
519 | 519 | 'i18n' => array( |
520 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
520 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
521 | 521 | /* translators: Do not translate the [option] placeholder */ |
522 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
522 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
523 | 523 | ), |
524 | 524 | 'checkout' => array( |
525 | 525 | 'url' => wc_get_checkout_url(), |
526 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
527 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
526 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
527 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
528 | 528 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
529 | 529 | ), |
530 | 530 | 'button' => array( |
531 | 531 | 'type' => $this->get_button_type(), |
532 | 532 | 'theme' => $this->get_button_theme(), |
533 | 533 | 'height' => $this->get_button_height(), |
534 | - 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US. |
|
534 | + 'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US. |
|
535 | 535 | 'is_custom' => $this->is_custom_button(), |
536 | 536 | 'is_branded' => $this->is_branded_button(), |
537 | 537 | 'css_selector' => $this->custom_button_selector(), |
@@ -541,15 +541,15 @@ discard block |
||
541 | 541 | 'product' => $this->get_product_data(), |
542 | 542 | ); |
543 | 543 | |
544 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
545 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
544 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
545 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
546 | 546 | |
547 | - wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) ); |
|
547 | + wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params)); |
|
548 | 548 | |
549 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
549 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
550 | 550 | |
551 | 551 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
552 | - if ( isset( $gateways['stripe'] ) ) { |
|
552 | + if (isset($gateways['stripe'])) { |
|
553 | 553 | $gateways['stripe']->payment_scripts(); |
554 | 554 | } |
555 | 555 | } |
@@ -565,31 +565,31 @@ discard block |
||
565 | 565 | |
566 | 566 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
567 | 567 | |
568 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
568 | + if ( ! isset($gateways['stripe'])) { |
|
569 | 569 | return; |
570 | 570 | } |
571 | 571 | |
572 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
572 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
573 | 573 | return; |
574 | 574 | } |
575 | 575 | |
576 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
576 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
577 | 577 | return; |
578 | 578 | } |
579 | 579 | |
580 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
580 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
581 | 581 | return; |
582 | - } else if ( ! $this->should_show_payment_button_on_cart() ) { |
|
582 | + } else if ( ! $this->should_show_payment_button_on_cart()) { |
|
583 | 583 | return; |
584 | 584 | } |
585 | 585 | ?> |
586 | 586 | <div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;display:none;"> |
587 | 587 | <div id="wc-stripe-payment-request-button"> |
588 | 588 | <?php |
589 | - if ( $this->is_custom_button() ) { |
|
590 | - $label = esc_html( $this->get_button_label() ); |
|
591 | - $class_name = esc_attr( 'button ' . $this->get_button_theme() ); |
|
592 | - $style = esc_attr( 'height:' . $this->get_button_height() . 'px;' ); |
|
589 | + if ($this->is_custom_button()) { |
|
590 | + $label = esc_html($this->get_button_label()); |
|
591 | + $class_name = esc_attr('button ' . $this->get_button_theme()); |
|
592 | + $style = esc_attr('height:' . $this->get_button_height() . 'px;'); |
|
593 | 593 | echo "<button id=\"wc-stripe-custom-button\" class=\"$class_name\" style=\"$style\"> $label </button>"; |
594 | 594 | } |
595 | 595 | ?> |
@@ -610,25 +610,25 @@ discard block |
||
610 | 610 | |
611 | 611 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
612 | 612 | |
613 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
613 | + if ( ! isset($gateways['stripe'])) { |
|
614 | 614 | return; |
615 | 615 | } |
616 | 616 | |
617 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
617 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
618 | 618 | return; |
619 | 619 | } |
620 | 620 | |
621 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
621 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
622 | 622 | return; |
623 | 623 | } |
624 | 624 | |
625 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
625 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
626 | 626 | return; |
627 | - } else if ( ! $this->should_show_payment_button_on_cart() ) { |
|
627 | + } else if ( ! $this->should_show_payment_button_on_cart()) { |
|
628 | 628 | return; |
629 | 629 | } |
630 | 630 | ?> |
631 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> —</p> |
|
631 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> —</p> |
|
632 | 632 | <?php |
633 | 633 | } |
634 | 634 | |
@@ -640,11 +640,11 @@ discard block |
||
640 | 640 | * @return bool |
641 | 641 | */ |
642 | 642 | private function should_show_payment_button_on_cart() { |
643 | - if ( ! apply_filters( 'wc_stripe_show_payment_request_on_cart', true ) ) { |
|
643 | + if ( ! apply_filters('wc_stripe_show_payment_request_on_cart', true)) { |
|
644 | 644 | return false; |
645 | 645 | } |
646 | - if ( ! $this->allowed_items_in_cart() ) { |
|
647 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
646 | + if ( ! $this->allowed_items_in_cart()) { |
|
647 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
648 | 648 | return false; |
649 | 649 | } |
650 | 650 | return true; |
@@ -660,32 +660,32 @@ discard block |
||
660 | 660 | private function should_show_payment_button_on_product_page() { |
661 | 661 | global $post; |
662 | 662 | |
663 | - $product = wc_get_product( $post->ID ); |
|
663 | + $product = wc_get_product($post->ID); |
|
664 | 664 | |
665 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
665 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
666 | 666 | return false; |
667 | 667 | } |
668 | 668 | |
669 | - if ( ! is_object( $product ) || ! in_array( $product->get_type(), $this->supported_product_types() ) ) { |
|
669 | + if ( ! is_object($product) || ! in_array($product->get_type(), $this->supported_product_types())) { |
|
670 | 670 | return false; |
671 | 671 | } |
672 | 672 | |
673 | 673 | // Trial subscriptions with shipping are not supported |
674 | - if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) { |
|
674 | + if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) { |
|
675 | 675 | return false; |
676 | 676 | } |
677 | 677 | |
678 | 678 | // Pre Orders charge upon release not supported. |
679 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
680 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
679 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
680 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
681 | 681 | return false; |
682 | 682 | } |
683 | 683 | |
684 | 684 | // File upload addon not supported |
685 | - if ( class_exists( 'WC_Product_Addons_Helper' ) ) { |
|
686 | - $product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() ); |
|
687 | - foreach ( $product_addons as $addon ) { |
|
688 | - if ( 'file_upload' === $addon['type'] ) { |
|
685 | + if (class_exists('WC_Product_Addons_Helper')) { |
|
686 | + $product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id()); |
|
687 | + foreach ($product_addons as $addon) { |
|
688 | + if ('file_upload' === $addon['type']) { |
|
689 | 689 | return false; |
690 | 690 | } |
691 | 691 | } |
@@ -701,11 +701,11 @@ discard block |
||
701 | 701 | * @version 4.0.0 |
702 | 702 | */ |
703 | 703 | public function ajax_log_errors() { |
704 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
704 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
705 | 705 | |
706 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
706 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
707 | 707 | |
708 | - WC_Stripe_Logger::log( $errors ); |
|
708 | + WC_Stripe_Logger::log($errors); |
|
709 | 709 | |
710 | 710 | exit; |
711 | 711 | } |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | * @version 4.0.0 |
718 | 718 | */ |
719 | 719 | public function ajax_clear_cart() { |
720 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
720 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
721 | 721 | |
722 | 722 | WC()->cart->empty_cart(); |
723 | 723 | exit; |
@@ -727,10 +727,10 @@ discard block |
||
727 | 727 | * Get cart details. |
728 | 728 | */ |
729 | 729 | public function ajax_get_cart_details() { |
730 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
730 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
731 | 731 | |
732 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
733 | - define( 'WOOCOMMERCE_CART', true ); |
|
732 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
733 | + define('WOOCOMMERCE_CART', true); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | WC()->cart->calculate_totals(); |
@@ -741,14 +741,14 @@ discard block |
||
741 | 741 | $data = array( |
742 | 742 | 'shipping_required' => WC()->cart->needs_shipping(), |
743 | 743 | 'order_data' => array( |
744 | - 'currency' => strtolower( $currency ), |
|
745 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
744 | + 'currency' => strtolower($currency), |
|
745 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
746 | 746 | ), |
747 | 747 | ); |
748 | 748 | |
749 | 749 | $data['order_data'] += $this->build_display_items(); |
750 | 750 | |
751 | - wp_send_json( $data ); |
|
751 | + wp_send_json($data); |
|
752 | 752 | } |
753 | 753 | |
754 | 754 | /** |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * @see WC_Shipping::get_packages(). |
760 | 760 | */ |
761 | 761 | public function ajax_get_shipping_options() { |
762 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
762 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
763 | 763 | |
764 | 764 | $shipping_address = filter_input_array( |
765 | 765 | INPUT_POST, |
@@ -772,11 +772,11 @@ discard block |
||
772 | 772 | 'address_2' => FILTER_SANITIZE_STRING, |
773 | 773 | ) |
774 | 774 | ); |
775 | - $product_view_options = filter_input_array( INPUT_POST, [ 'is_product_page' => FILTER_SANITIZE_STRING ] ); |
|
776 | - $should_show_itemized_view = ! isset( $product_view_options['is_product_page'] ) ?: filter_var( $product_view_options['is_product_page'], FILTER_VALIDATE_BOOLEAN ); |
|
775 | + $product_view_options = filter_input_array(INPUT_POST, ['is_product_page' => FILTER_SANITIZE_STRING]); |
|
776 | + $should_show_itemized_view = ! isset($product_view_options['is_product_page']) ?: filter_var($product_view_options['is_product_page'], FILTER_VALIDATE_BOOLEAN); |
|
777 | 777 | |
778 | - $data = $this->get_shipping_options( $shipping_address, $should_show_itemized_view ); |
|
779 | - wp_send_json( $data ); |
|
778 | + $data = $this->get_shipping_options($shipping_address, $should_show_itemized_view); |
|
779 | + wp_send_json($data); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
@@ -788,66 +788,66 @@ discard block |
||
788 | 788 | * @return array Shipping options data. |
789 | 789 | * phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag |
790 | 790 | */ |
791 | - public function get_shipping_options( $shipping_address, $itemized_display_items = false ) { |
|
791 | + public function get_shipping_options($shipping_address, $itemized_display_items = false) { |
|
792 | 792 | try { |
793 | 793 | // Set the shipping options. |
794 | 794 | $data = array(); |
795 | 795 | |
796 | 796 | // Remember current shipping method before resetting. |
797 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
798 | - $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $shipping_address ) ); |
|
797 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
798 | + $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $shipping_address)); |
|
799 | 799 | |
800 | 800 | $packages = WC()->shipping->get_packages(); |
801 | 801 | |
802 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
803 | - foreach ( $packages as $package_key => $package ) { |
|
804 | - if ( empty( $package['rates'] ) ) { |
|
805 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
802 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
803 | + foreach ($packages as $package_key => $package) { |
|
804 | + if (empty($package['rates'])) { |
|
805 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
806 | 806 | } |
807 | 807 | |
808 | - foreach ( $package['rates'] as $key => $rate ) { |
|
808 | + foreach ($package['rates'] as $key => $rate) { |
|
809 | 809 | $data['shipping_options'][] = array( |
810 | 810 | 'id' => $rate->id, |
811 | 811 | 'label' => $rate->label, |
812 | 812 | 'detail' => '', |
813 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
813 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
814 | 814 | ); |
815 | 815 | } |
816 | 816 | } |
817 | 817 | } else { |
818 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
818 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | // The first shipping option is automatically applied on the client. |
822 | 822 | // Keep chosen shipping method by sorting shipping options if the method still available for new address. |
823 | 823 | // Fallback to the first available shipping method. |
824 | - if ( isset( $data['shipping_options'][0] ) ) { |
|
825 | - if ( isset( $chosen_shipping_methods[0] ) ) { |
|
824 | + if (isset($data['shipping_options'][0])) { |
|
825 | + if (isset($chosen_shipping_methods[0])) { |
|
826 | 826 | $chosen_method_id = $chosen_shipping_methods[0]; |
827 | - $compare_shipping_options = function ( $a, $b ) use ( $chosen_method_id ) { |
|
828 | - if ( $a['id'] === $chosen_method_id ) { |
|
827 | + $compare_shipping_options = function($a, $b) use ($chosen_method_id) { |
|
828 | + if ($a['id'] === $chosen_method_id) { |
|
829 | 829 | return -1; |
830 | 830 | } |
831 | 831 | |
832 | - if ( $b['id'] === $chosen_method_id ) { |
|
832 | + if ($b['id'] === $chosen_method_id) { |
|
833 | 833 | return 1; |
834 | 834 | } |
835 | 835 | |
836 | 836 | return 0; |
837 | 837 | }; |
838 | - usort( $data['shipping_options'], $compare_shipping_options ); |
|
838 | + usort($data['shipping_options'], $compare_shipping_options); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | $first_shipping_method_id = $data['shipping_options'][0]['id']; |
842 | - $this->update_shipping_method( [ $first_shipping_method_id ] ); |
|
842 | + $this->update_shipping_method([$first_shipping_method_id]); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | WC()->cart->calculate_totals(); |
846 | 846 | |
847 | - $data += $this->build_display_items( $itemized_display_items ); |
|
847 | + $data += $this->build_display_items($itemized_display_items); |
|
848 | 848 | $data['result'] = 'success'; |
849 | - } catch ( Exception $e ) { |
|
850 | - $data += $this->build_display_items( $itemized_display_items ); |
|
849 | + } catch (Exception $e) { |
|
850 | + $data += $this->build_display_items($itemized_display_items); |
|
851 | 851 | $data['result'] = 'invalid_shipping_address'; |
852 | 852 | } |
853 | 853 | |
@@ -858,25 +858,25 @@ discard block |
||
858 | 858 | * Update shipping method. |
859 | 859 | */ |
860 | 860 | public function ajax_update_shipping_method() { |
861 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
861 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
862 | 862 | |
863 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
864 | - define( 'WOOCOMMERCE_CART', true ); |
|
863 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
864 | + define('WOOCOMMERCE_CART', true); |
|
865 | 865 | } |
866 | 866 | |
867 | - $shipping_methods = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
868 | - $this->update_shipping_method( $shipping_methods ); |
|
867 | + $shipping_methods = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
868 | + $this->update_shipping_method($shipping_methods); |
|
869 | 869 | |
870 | 870 | WC()->cart->calculate_totals(); |
871 | 871 | |
872 | - $product_view_options = filter_input_array( INPUT_POST, [ 'is_product_page' => FILTER_SANITIZE_STRING ] ); |
|
873 | - $should_show_itemized_view = ! isset( $product_view_options['is_product_page'] ) ?: filter_var( $product_view_options['is_product_page'], FILTER_VALIDATE_BOOLEAN ); |
|
872 | + $product_view_options = filter_input_array(INPUT_POST, ['is_product_page' => FILTER_SANITIZE_STRING]); |
|
873 | + $should_show_itemized_view = ! isset($product_view_options['is_product_page']) ?: filter_var($product_view_options['is_product_page'], FILTER_VALIDATE_BOOLEAN); |
|
874 | 874 | |
875 | 875 | $data = array(); |
876 | - $data += $this->build_display_items( $should_show_itemized_view ); |
|
876 | + $data += $this->build_display_items($should_show_itemized_view); |
|
877 | 877 | $data['result'] = 'success'; |
878 | 878 | |
879 | - wp_send_json( $data ); |
|
879 | + wp_send_json($data); |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | /** |
@@ -884,16 +884,16 @@ discard block |
||
884 | 884 | * |
885 | 885 | * @param array $shipping_methods Array of selected shipping methods ids. |
886 | 886 | */ |
887 | - public function update_shipping_method( $shipping_methods ) { |
|
888 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
887 | + public function update_shipping_method($shipping_methods) { |
|
888 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
889 | 889 | |
890 | - if ( is_array( $shipping_methods ) ) { |
|
891 | - foreach ( $shipping_methods as $i => $value ) { |
|
892 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
890 | + if (is_array($shipping_methods)) { |
|
891 | + foreach ($shipping_methods as $i => $value) { |
|
892 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
893 | 893 | } |
894 | 894 | } |
895 | 895 | |
896 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
896 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | /** |
@@ -904,38 +904,38 @@ discard block |
||
904 | 904 | * @return array $data |
905 | 905 | */ |
906 | 906 | public function ajax_get_selected_product_data() { |
907 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
907 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
908 | 908 | |
909 | 909 | try { |
910 | - $product_id = absint( $_POST['product_id'] ); |
|
911 | - $qty = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id ); |
|
912 | - $addon_value = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0; |
|
913 | - $product = wc_get_product( $product_id ); |
|
910 | + $product_id = absint($_POST['product_id']); |
|
911 | + $qty = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id); |
|
912 | + $addon_value = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0; |
|
913 | + $product = wc_get_product($product_id); |
|
914 | 914 | $variation_id = null; |
915 | 915 | |
916 | - if ( ! is_a( $product, 'WC_Product' ) ) { |
|
917 | - throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); |
|
916 | + if ( ! is_a($product, 'WC_Product')) { |
|
917 | + throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id)); |
|
918 | 918 | } |
919 | 919 | |
920 | - if ( 'variable' === $product->get_type() && isset( $_POST['attributes'] ) ) { |
|
921 | - $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
920 | + if ('variable' === $product->get_type() && isset($_POST['attributes'])) { |
|
921 | + $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
922 | 922 | |
923 | - $data_store = WC_Data_Store::load( 'product' ); |
|
924 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
923 | + $data_store = WC_Data_Store::load('product'); |
|
924 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
925 | 925 | |
926 | - if ( ! empty( $variation_id ) ) { |
|
927 | - $product = wc_get_product( $variation_id ); |
|
926 | + if ( ! empty($variation_id)) { |
|
927 | + $product = wc_get_product($variation_id); |
|
928 | 928 | } |
929 | 929 | } |
930 | 930 | |
931 | 931 | // Force quantity to 1 if sold individually and check for existing item in cart. |
932 | - if ( $product->is_sold_individually() ) { |
|
933 | - $qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id ); |
|
932 | + if ($product->is_sold_individually()) { |
|
933 | + $qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id); |
|
934 | 934 | } |
935 | 935 | |
936 | - if ( ! $product->has_enough_stock( $qty ) ) { |
|
936 | + if ( ! $product->has_enough_stock($qty)) { |
|
937 | 937 | /* translators: 1: product name 2: quantity in stock */ |
938 | - throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) ); |
|
938 | + throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product))); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | $total = $qty * $product->get_price() + $addon_value; |
@@ -947,27 +947,27 @@ discard block |
||
947 | 947 | |
948 | 948 | $items[] = array( |
949 | 949 | 'label' => $product->get_name() . $quantity_label, |
950 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
950 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
951 | 951 | ); |
952 | 952 | |
953 | - if ( wc_tax_enabled() ) { |
|
953 | + if (wc_tax_enabled()) { |
|
954 | 954 | $items[] = array( |
955 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
955 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
956 | 956 | 'amount' => 0, |
957 | 957 | 'pending' => true, |
958 | 958 | ); |
959 | 959 | } |
960 | 960 | |
961 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
961 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
962 | 962 | $items[] = array( |
963 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
963 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
964 | 964 | 'amount' => 0, |
965 | 965 | 'pending' => true, |
966 | 966 | ); |
967 | 967 | |
968 | 968 | $data['shippingOptions'] = array( |
969 | 969 | 'id' => 'pending', |
970 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
970 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
971 | 971 | 'detail' => '', |
972 | 972 | 'amount' => 0, |
973 | 973 | ); |
@@ -976,17 +976,17 @@ discard block |
||
976 | 976 | $data['displayItems'] = $items; |
977 | 977 | $data['total'] = array( |
978 | 978 | 'label' => $this->total_label, |
979 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
979 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
980 | 980 | 'pending' => true, |
981 | 981 | ); |
982 | 982 | |
983 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
984 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
985 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
983 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
984 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
985 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
986 | 986 | |
987 | - wp_send_json( $data ); |
|
988 | - } catch ( Exception $e ) { |
|
989 | - wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) ); |
|
987 | + wp_send_json($data); |
|
988 | + } catch (Exception $e) { |
|
989 | + wp_send_json(array('error' => wp_strip_all_tags($e->getMessage()))); |
|
990 | 990 | } |
991 | 991 | } |
992 | 992 | |
@@ -998,33 +998,33 @@ discard block |
||
998 | 998 | * @return array $data |
999 | 999 | */ |
1000 | 1000 | public function ajax_add_to_cart() { |
1001 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
1001 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
1002 | 1002 | |
1003 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1004 | - define( 'WOOCOMMERCE_CART', true ); |
|
1003 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1004 | + define('WOOCOMMERCE_CART', true); |
|
1005 | 1005 | } |
1006 | 1006 | |
1007 | 1007 | WC()->shipping->reset_shipping(); |
1008 | 1008 | |
1009 | - $product_id = absint( $_POST['product_id'] ); |
|
1010 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
1011 | - $product = wc_get_product( $product_id ); |
|
1009 | + $product_id = absint($_POST['product_id']); |
|
1010 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
1011 | + $product = wc_get_product($product_id); |
|
1012 | 1012 | $product_type = $product->get_type(); |
1013 | 1013 | |
1014 | 1014 | // First empty the cart to prevent wrong calculation. |
1015 | 1015 | WC()->cart->empty_cart(); |
1016 | 1016 | |
1017 | - if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { |
|
1018 | - $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
1017 | + if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) { |
|
1018 | + $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
1019 | 1019 | |
1020 | - $data_store = WC_Data_Store::load( 'product' ); |
|
1021 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
1020 | + $data_store = WC_Data_Store::load('product'); |
|
1021 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
1022 | 1022 | |
1023 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
1023 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | - if ( 'simple' === $product_type || 'subscription' === $product_type ) { |
|
1027 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
1026 | + if ('simple' === $product_type || 'subscription' === $product_type) { |
|
1027 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | 1030 | WC()->cart->calculate_totals(); |
@@ -1033,7 +1033,7 @@ discard block |
||
1033 | 1033 | $data += $this->build_display_items(); |
1034 | 1034 | $data['result'] = 'success'; |
1035 | 1035 | |
1036 | - wp_send_json( $data ); |
|
1036 | + wp_send_json($data); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | /** |
@@ -1046,31 +1046,31 @@ discard block |
||
1046 | 1046 | * @version 4.0.0 |
1047 | 1047 | */ |
1048 | 1048 | public function normalize_state() { |
1049 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
1050 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
1051 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
1052 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
1049 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
1050 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
1051 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
1052 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
1053 | 1053 | |
1054 | - if ( $billing_state && $billing_country ) { |
|
1055 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
1054 | + if ($billing_state && $billing_country) { |
|
1055 | + $valid_states = WC()->countries->get_states($billing_country); |
|
1056 | 1056 | |
1057 | 1057 | // Valid states found for country. |
1058 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
1059 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
1060 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
1058 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
1059 | + foreach ($valid_states as $state_abbr => $state) { |
|
1060 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
1061 | 1061 | $_POST['billing_state'] = $state_abbr; |
1062 | 1062 | } |
1063 | 1063 | } |
1064 | 1064 | } |
1065 | 1065 | } |
1066 | 1066 | |
1067 | - if ( $shipping_state && $shipping_country ) { |
|
1068 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
1067 | + if ($shipping_state && $shipping_country) { |
|
1068 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
1069 | 1069 | |
1070 | 1070 | // Valid states found for country. |
1071 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
1072 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
1073 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
1071 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
1072 | + foreach ($valid_states as $state_abbr => $state) { |
|
1073 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
1074 | 1074 | $_POST['shipping_state'] = $state_abbr; |
1075 | 1075 | } |
1076 | 1076 | } |
@@ -1085,19 +1085,19 @@ discard block |
||
1085 | 1085 | * @version 4.0.0 |
1086 | 1086 | */ |
1087 | 1087 | public function ajax_create_order() { |
1088 | - if ( WC()->cart->is_empty() ) { |
|
1089 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
1088 | + if (WC()->cart->is_empty()) { |
|
1089 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
1093 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
1092 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
1093 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | $this->normalize_state(); |
1097 | 1097 | |
1098 | 1098 | WC()->checkout()->process_checkout(); |
1099 | 1099 | |
1100 | - die( 0 ); |
|
1100 | + die(0); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | /** |
@@ -1107,38 +1107,38 @@ discard block |
||
1107 | 1107 | * @version 4.0.0 |
1108 | 1108 | * @param array $address |
1109 | 1109 | */ |
1110 | - protected function calculate_shipping( $address = array() ) { |
|
1110 | + protected function calculate_shipping($address = array()) { |
|
1111 | 1111 | $country = $address['country']; |
1112 | 1112 | $state = $address['state']; |
1113 | 1113 | $postcode = $address['postcode']; |
1114 | 1114 | $city = $address['city']; |
1115 | 1115 | $address_1 = $address['address']; |
1116 | 1116 | $address_2 = $address['address_2']; |
1117 | - $wc_states = WC()->countries->get_states( $country ); |
|
1117 | + $wc_states = WC()->countries->get_states($country); |
|
1118 | 1118 | |
1119 | 1119 | /** |
1120 | 1120 | * In some versions of Chrome, state can be a full name. So we need |
1121 | 1121 | * to convert that to abbreviation as WC is expecting that. |
1122 | 1122 | */ |
1123 | - if ( 2 < strlen( $state ) && ! empty( $wc_states ) && ! isset( $wc_states[ $state ] ) ) { |
|
1124 | - $state = array_search( ucwords( strtolower( $state ) ), $wc_states, true ); |
|
1123 | + if (2 < strlen($state) && ! empty($wc_states) && ! isset($wc_states[$state])) { |
|
1124 | + $state = array_search(ucwords(strtolower($state)), $wc_states, true); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | WC()->shipping->reset_shipping(); |
1128 | 1128 | |
1129 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
1130 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
1129 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
1130 | + $postcode = wc_format_postcode($postcode, $country); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | - if ( $country ) { |
|
1134 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1135 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
1133 | + if ($country) { |
|
1134 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
1135 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1136 | 1136 | } else { |
1137 | 1137 | WC()->customer->set_billing_address_to_base(); |
1138 | 1138 | WC()->customer->set_shipping_address_to_base(); |
1139 | 1139 | } |
1140 | 1140 | |
1141 | - WC()->customer->set_calculated_shipping( true ); |
|
1141 | + WC()->customer->set_calculated_shipping(true); |
|
1142 | 1142 | WC()->customer->save(); |
1143 | 1143 | |
1144 | 1144 | $packages = array(); |
@@ -1154,17 +1154,17 @@ discard block |
||
1154 | 1154 | $packages[0]['destination']['address'] = $address_1; |
1155 | 1155 | $packages[0]['destination']['address_2'] = $address_2; |
1156 | 1156 | |
1157 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1158 | - if ( $item['data']->needs_shipping() ) { |
|
1159 | - if ( isset( $item['line_total'] ) ) { |
|
1157 | + foreach (WC()->cart->get_cart() as $item) { |
|
1158 | + if ($item['data']->needs_shipping()) { |
|
1159 | + if (isset($item['line_total'])) { |
|
1160 | 1160 | $packages[0]['contents_cost'] += $item['line_total']; |
1161 | 1161 | } |
1162 | 1162 | } |
1163 | 1163 | } |
1164 | 1164 | |
1165 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1165 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1166 | 1166 | |
1167 | - WC()->shipping->calculate_shipping( $packages ); |
|
1167 | + WC()->shipping->calculate_shipping($packages); |
|
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | /** |
@@ -1173,19 +1173,19 @@ discard block |
||
1173 | 1173 | * @since 3.1.0 |
1174 | 1174 | * @version 4.0.0 |
1175 | 1175 | */ |
1176 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1177 | - if ( empty( $shipping_methods ) ) { |
|
1176 | + protected function build_shipping_methods($shipping_methods) { |
|
1177 | + if (empty($shipping_methods)) { |
|
1178 | 1178 | return array(); |
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | $shipping = array(); |
1182 | 1182 | |
1183 | - foreach ( $shipping_methods as $method ) { |
|
1183 | + foreach ($shipping_methods as $method) { |
|
1184 | 1184 | $shipping[] = array( |
1185 | 1185 | 'id' => $method['id'], |
1186 | 1186 | 'label' => $method['label'], |
1187 | 1187 | 'detail' => '', |
1188 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1188 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1189 | 1189 | ); |
1190 | 1190 | } |
1191 | 1191 | |
@@ -1198,9 +1198,9 @@ discard block |
||
1198 | 1198 | * @since 3.1.0 |
1199 | 1199 | * @version 4.0.0 |
1200 | 1200 | */ |
1201 | - protected function build_display_items( $itemized_display_items = false ) { |
|
1202 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1203 | - define( 'WOOCOMMERCE_CART', true ); |
|
1201 | + protected function build_display_items($itemized_display_items = false) { |
|
1202 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1203 | + define('WOOCOMMERCE_CART', true); |
|
1204 | 1204 | } |
1205 | 1205 | |
1206 | 1206 | $items = array(); |
@@ -1208,8 +1208,8 @@ discard block |
||
1208 | 1208 | $discounts = 0; |
1209 | 1209 | |
1210 | 1210 | // Default show only subtotal instead of itemization. |
1211 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) || $itemized_display_items ) { |
|
1212 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1211 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true) || $itemized_display_items) { |
|
1212 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1213 | 1213 | $amount = $cart_item['line_subtotal']; |
1214 | 1214 | $subtotal += $cart_item['line_subtotal']; |
1215 | 1215 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
@@ -1218,61 +1218,61 @@ discard block |
||
1218 | 1218 | |
1219 | 1219 | $item = array( |
1220 | 1220 | 'label' => $product_name . $quantity_label, |
1221 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1221 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1222 | 1222 | ); |
1223 | 1223 | |
1224 | 1224 | $items[] = $item; |
1225 | 1225 | } |
1226 | 1226 | } |
1227 | 1227 | |
1228 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1229 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1228 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1229 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1230 | 1230 | } else { |
1231 | - $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
1231 | + $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
1232 | 1232 | |
1233 | - foreach ( $applied_coupons as $amount ) { |
|
1233 | + foreach ($applied_coupons as $amount) { |
|
1234 | 1234 | $discounts += (float) $amount; |
1235 | 1235 | } |
1236 | 1236 | } |
1237 | 1237 | |
1238 | - $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
1239 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1240 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1241 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1242 | - $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
1238 | + $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
1239 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1240 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1241 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1242 | + $order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false); |
|
1243 | 1243 | |
1244 | - if ( wc_tax_enabled() ) { |
|
1244 | + if (wc_tax_enabled()) { |
|
1245 | 1245 | $items[] = array( |
1246 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1247 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1246 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1247 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1248 | 1248 | ); |
1249 | 1249 | } |
1250 | 1250 | |
1251 | - if ( WC()->cart->needs_shipping() ) { |
|
1251 | + if (WC()->cart->needs_shipping()) { |
|
1252 | 1252 | $items[] = array( |
1253 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1254 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1253 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1254 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1255 | 1255 | ); |
1256 | 1256 | } |
1257 | 1257 | |
1258 | - if ( WC()->cart->has_discount() ) { |
|
1258 | + if (WC()->cart->has_discount()) { |
|
1259 | 1259 | $items[] = array( |
1260 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1261 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1260 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1261 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1262 | 1262 | ); |
1263 | 1263 | } |
1264 | 1264 | |
1265 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1265 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1266 | 1266 | $cart_fees = WC()->cart->fees; |
1267 | 1267 | } else { |
1268 | 1268 | $cart_fees = WC()->cart->get_fees(); |
1269 | 1269 | } |
1270 | 1270 | |
1271 | 1271 | // Include fees and taxes as display items. |
1272 | - foreach ( $cart_fees as $key => $fee ) { |
|
1272 | + foreach ($cart_fees as $key => $fee) { |
|
1273 | 1273 | $items[] = array( |
1274 | 1274 | 'label' => $fee->name, |
1275 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1275 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1276 | 1276 | ); |
1277 | 1277 | } |
1278 | 1278 | |
@@ -1280,7 +1280,7 @@ discard block |
||
1280 | 1280 | 'displayItems' => $items, |
1281 | 1281 | 'total' => array( |
1282 | 1282 | 'label' => $this->total_label, |
1283 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1283 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1284 | 1284 | 'pending' => false, |
1285 | 1285 | ), |
1286 | 1286 | ); |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Required minimums and constants |
24 | 24 | */ |
25 | -define( 'WC_STRIPE_VERSION', '4.5.0' ); |
|
26 | -define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
27 | -define( 'WC_STRIPE_MIN_WC_VER', '3.0' ); |
|
28 | -define( 'WC_STRIPE_FUTURE_MIN_WC_VER', '3.0' ); |
|
29 | -define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
30 | -define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
31 | -define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
25 | +define('WC_STRIPE_VERSION', '4.5.0'); |
|
26 | +define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
27 | +define('WC_STRIPE_MIN_WC_VER', '3.0'); |
|
28 | +define('WC_STRIPE_FUTURE_MIN_WC_VER', '3.0'); |
|
29 | +define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
30 | +define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
31 | +define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
32 | 32 | |
33 | 33 | // phpcs:disable WordPress.Files.FileName |
34 | 34 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | function woocommerce_stripe_missing_wc_notice() { |
42 | 42 | /* translators: 1. URL link. */ |
43 | - echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Stripe requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-gateway-stripe' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>'; |
|
43 | + echo '<div class="error"><p><strong>' . sprintf(esc_html__('Stripe requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-gateway-stripe'), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>') . '</strong></p></div>'; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function woocommerce_stripe_wc_not_supported() { |
53 | 53 | /* translators: $1. Minimum WooCommerce version. $2. Current WooCommerce version. */ |
54 | - echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Stripe requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is no longer supported.', 'woocommerce-gateway-stripe' ), WC_STRIPE_MIN_WC_VER, WC_VERSION ) . '</strong></p></div>'; |
|
54 | + echo '<div class="error"><p><strong>' . sprintf(esc_html__('Stripe requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is no longer supported.', 'woocommerce-gateway-stripe'), WC_STRIPE_MIN_WC_VER, WC_VERSION) . '</strong></p></div>'; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | function woocommerce_stripe_wc_country_not_supported() { |
64 | - echo '<div class="error"><p><strong>' . __( 'Stripe is not available in your store\'s country and will not be available for buyers to choose during checkout.', 'woocommerce-gateway-stripe' ) . '</strong></p></div>'; |
|
64 | + echo '<div class="error"><p><strong>' . __('Stripe is not available in your store\'s country and will not be available for buyers to choose during checkout.', 'woocommerce-gateway-stripe') . '</strong></p></div>'; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @return bool |
73 | 73 | */ |
74 | 74 | function woocommerce_stripe_wc_country_is_supported_country() { |
75 | - $wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
75 | + $wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2); |
|
76 | 76 | |
77 | 77 | $supported_countries = apply_filters( |
78 | 78 | 'wc_stripe_supported_countries', |
@@ -118,30 +118,30 @@ discard block |
||
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | |
121 | - return in_array( $wc_default_country, $supported_countries ); |
|
121 | + return in_array($wc_default_country, $supported_countries); |
|
122 | 122 | } |
123 | 123 | |
124 | -add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' ); |
|
124 | +add_action('plugins_loaded', 'woocommerce_gateway_stripe_init'); |
|
125 | 125 | |
126 | 126 | function woocommerce_gateway_stripe_init() { |
127 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
127 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
128 | 128 | |
129 | - if ( ! class_exists( 'WooCommerce' ) ) { |
|
130 | - add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' ); |
|
129 | + if ( ! class_exists('WooCommerce')) { |
|
130 | + add_action('admin_notices', 'woocommerce_stripe_missing_wc_notice'); |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
135 | - add_action( 'admin_notices', 'woocommerce_stripe_wc_not_supported' ); |
|
134 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
135 | + add_action('admin_notices', 'woocommerce_stripe_wc_not_supported'); |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | - if ( ! woocommerce_stripe_wc_country_is_supported_country() ) { |
|
140 | - add_action( 'admin_notices', 'woocommerce_stripe_wc_country_not_supported' ); |
|
139 | + if ( ! woocommerce_stripe_wc_country_is_supported_country()) { |
|
140 | + add_action('admin_notices', 'woocommerce_stripe_wc_country_not_supported'); |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
144 | - if ( ! class_exists( 'WC_Stripe' ) ) : |
|
144 | + if ( ! class_exists('WC_Stripe')) : |
|
145 | 145 | |
146 | 146 | class WC_Stripe { |
147 | 147 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @return Singleton The *Singleton* instance. |
157 | 157 | */ |
158 | 158 | public static function get_instance() { |
159 | - if ( null === self::$instance ) { |
|
159 | + if (null === self::$instance) { |
|
160 | 160 | self::$instance = new self(); |
161 | 161 | } |
162 | 162 | return self::$instance; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * *Singleton* via the `new` operator from outside of this class. |
184 | 184 | */ |
185 | 185 | private function __construct() { |
186 | - add_action( 'admin_init', array( $this, 'install' ) ); |
|
186 | + add_action('admin_init', array($this, 'install')); |
|
187 | 187 | $this->init(); |
188 | 188 | } |
189 | 189 | |
@@ -194,53 +194,53 @@ discard block |
||
194 | 194 | * @version 4.0.0 |
195 | 195 | */ |
196 | 196 | public function init() { |
197 | - if ( is_admin() ) { |
|
198 | - require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-privacy.php'; |
|
197 | + if (is_admin()) { |
|
198 | + require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-privacy.php'; |
|
199 | 199 | } |
200 | 200 | |
201 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php'; |
|
202 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php'; |
|
203 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php'; |
|
204 | - include_once dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php'; |
|
205 | - require_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; |
|
206 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php'; |
|
207 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php'; |
|
208 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php'; |
|
209 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; |
|
210 | - require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php'; |
|
211 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; |
|
212 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; |
|
213 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; |
|
214 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php'; |
|
215 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'; |
|
216 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'; |
|
217 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'; |
|
218 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'; |
|
219 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php'; |
|
220 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; |
|
221 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php'; |
|
222 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php'; |
|
223 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php'; |
|
224 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php'; |
|
225 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php'; |
|
226 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-intent-controller.php'; |
|
227 | - |
|
228 | - if ( is_admin() ) { |
|
229 | - require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php'; |
|
201 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'; |
|
202 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'; |
|
203 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'; |
|
204 | + include_once dirname(__FILE__) . '/includes/class-wc-stripe-api.php'; |
|
205 | + require_once dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; |
|
206 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'; |
|
207 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'; |
|
208 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php'; |
|
209 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; |
|
210 | + require_once dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'; |
|
211 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; |
|
212 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; |
|
213 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; |
|
214 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php'; |
|
215 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'; |
|
216 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'; |
|
217 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'; |
|
218 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'; |
|
219 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php'; |
|
220 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; |
|
221 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php'; |
|
222 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php'; |
|
223 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'; |
|
224 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'; |
|
225 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'; |
|
226 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-intent-controller.php'; |
|
227 | + |
|
228 | + if (is_admin()) { |
|
229 | + require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php'; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | // REMOVE IN THE FUTURE. |
233 | - require_once dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php'; |
|
233 | + require_once dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'; |
|
234 | 234 | |
235 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
236 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
237 | - add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
|
235 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
236 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
237 | + add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2); |
|
238 | 238 | |
239 | 239 | // Modify emails emails. |
240 | - add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ), 20 ); |
|
240 | + add_filter('woocommerce_email_classes', array($this, 'add_emails'), 20); |
|
241 | 241 | |
242 | - if ( version_compare( WC_VERSION, '3.4', '<' ) ) { |
|
243 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
242 | + if (version_compare(WC_VERSION, '3.4', '<')) { |
|
243 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @version 4.0.0 |
252 | 252 | */ |
253 | 253 | public function update_plugin_version() { |
254 | - delete_option( 'wc_stripe_version' ); |
|
255 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
254 | + delete_option('wc_stripe_version'); |
|
255 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -262,15 +262,15 @@ discard block |
||
262 | 262 | * @version 3.1.0 |
263 | 263 | */ |
264 | 264 | public function install() { |
265 | - if ( ! is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
265 | + if ( ! is_plugin_active(plugin_basename(__FILE__))) { |
|
266 | 266 | return; |
267 | 267 | } |
268 | 268 | |
269 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
270 | - do_action( 'woocommerce_stripe_updated' ); |
|
269 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
270 | + do_action('woocommerce_stripe_updated'); |
|
271 | 271 | |
272 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
273 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
272 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
273 | + define('WC_STRIPE_INSTALLING', true); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | $this->update_plugin_version(); |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | * @since 1.0.0 |
284 | 284 | * @version 4.0.0 |
285 | 285 | */ |
286 | - public function plugin_action_links( $links ) { |
|
286 | + public function plugin_action_links($links) { |
|
287 | 287 | $plugin_links = array( |
288 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
288 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
289 | 289 | ); |
290 | - return array_merge( $plugin_links, $links ); |
|
290 | + return array_merge($plugin_links, $links); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -298,13 +298,13 @@ discard block |
||
298 | 298 | * @param string $file Name of current file. |
299 | 299 | * @return array $links Update list of plugin links. |
300 | 300 | */ |
301 | - public function plugin_row_meta( $links, $file ) { |
|
302 | - if ( plugin_basename( __FILE__ ) === $file ) { |
|
301 | + public function plugin_row_meta($links, $file) { |
|
302 | + if (plugin_basename(__FILE__) === $file) { |
|
303 | 303 | $row_meta = array( |
304 | - 'docs' => '<a href="' . esc_url( apply_filters( 'woocommerce_gateway_stripe_docs_url', 'https://docs.woocommerce.com/document/stripe/' ) ) . '" title="' . esc_attr( __( 'View Documentation', 'woocommerce-gateway-stripe' ) ) . '">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
305 | - 'support' => '<a href="' . esc_url( apply_filters( 'woocommerce_gateway_stripe_support_url', 'https://woocommerce.com/my-account/create-a-ticket?select=18627' ) ) . '" title="' . esc_attr( __( 'Open a support request at WooCommerce.com', 'woocommerce-gateway-stripe' ) ) . '">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
304 | + 'docs' => '<a href="' . esc_url(apply_filters('woocommerce_gateway_stripe_docs_url', 'https://docs.woocommerce.com/document/stripe/')) . '" title="' . esc_attr(__('View Documentation', 'woocommerce-gateway-stripe')) . '">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
305 | + 'support' => '<a href="' . esc_url(apply_filters('woocommerce_gateway_stripe_support_url', 'https://woocommerce.com/my-account/create-a-ticket?select=18627')) . '" title="' . esc_attr(__('Open a support request at WooCommerce.com', 'woocommerce-gateway-stripe')) . '">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
306 | 306 | ); |
307 | - return array_merge( $links, $row_meta ); |
|
307 | + return array_merge($links, $row_meta); |
|
308 | 308 | } |
309 | 309 | return (array) $links; |
310 | 310 | } |
@@ -315,8 +315,8 @@ discard block |
||
315 | 315 | * @since 1.0.0 |
316 | 316 | * @version 4.0.0 |
317 | 317 | */ |
318 | - public function add_gateways( $methods ) { |
|
319 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
318 | + public function add_gateways($methods) { |
|
319 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
320 | 320 | $methods[] = 'WC_Stripe_Subs_Compat'; |
321 | 321 | $methods[] = 'WC_Stripe_Sepa_Subs_Compat'; |
322 | 322 | } else { |
@@ -342,28 +342,28 @@ discard block |
||
342 | 342 | * @since 4.0.0 |
343 | 343 | * @version 4.0.0 |
344 | 344 | */ |
345 | - public function filter_gateway_order_admin( $sections ) { |
|
346 | - unset( $sections['stripe'] ); |
|
347 | - unset( $sections['stripe_bancontact'] ); |
|
348 | - unset( $sections['stripe_sofort'] ); |
|
349 | - unset( $sections['stripe_giropay'] ); |
|
350 | - unset( $sections['stripe_eps'] ); |
|
351 | - unset( $sections['stripe_ideal'] ); |
|
352 | - unset( $sections['stripe_p24'] ); |
|
353 | - unset( $sections['stripe_alipay'] ); |
|
354 | - unset( $sections['stripe_sepa'] ); |
|
355 | - unset( $sections['stripe_multibanco'] ); |
|
345 | + public function filter_gateway_order_admin($sections) { |
|
346 | + unset($sections['stripe']); |
|
347 | + unset($sections['stripe_bancontact']); |
|
348 | + unset($sections['stripe_sofort']); |
|
349 | + unset($sections['stripe_giropay']); |
|
350 | + unset($sections['stripe_eps']); |
|
351 | + unset($sections['stripe_ideal']); |
|
352 | + unset($sections['stripe_p24']); |
|
353 | + unset($sections['stripe_alipay']); |
|
354 | + unset($sections['stripe_sepa']); |
|
355 | + unset($sections['stripe_multibanco']); |
|
356 | 356 | |
357 | 357 | $sections['stripe'] = 'Stripe'; |
358 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
359 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
360 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
361 | - $sections['stripe_eps'] = __( 'Stripe EPS', 'woocommerce-gateway-stripe' ); |
|
362 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
363 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
364 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
365 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
366 | - $sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' ); |
|
358 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
359 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
360 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
361 | + $sections['stripe_eps'] = __('Stripe EPS', 'woocommerce-gateway-stripe'); |
|
362 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
363 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
364 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
365 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
366 | + $sections['stripe_multibanco'] = __('Stripe Multibanco', 'woocommerce-gateway-stripe'); |
|
367 | 367 | |
368 | 368 | return $sections; |
369 | 369 | } |
@@ -374,16 +374,16 @@ discard block |
||
374 | 374 | * @param WC_Email[] $email_classes All existing emails. |
375 | 375 | * @return WC_Email[] |
376 | 376 | */ |
377 | - public function add_emails( $email_classes ) { |
|
377 | + public function add_emails($email_classes) { |
|
378 | 378 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php'; |
379 | 379 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php'; |
380 | 380 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php'; |
381 | 381 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php'; |
382 | 382 | |
383 | 383 | // Add all emails, generated by the gateway. |
384 | - $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication( $email_classes ); |
|
385 | - $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication( $email_classes ); |
|
386 | - $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry( $email_classes ); |
|
384 | + $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication($email_classes); |
|
385 | + $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication($email_classes); |
|
386 | + $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry($email_classes); |
|
387 | 387 | |
388 | 388 | return $email_classes; |
389 | 389 | } |
@@ -1,28 +1,28 @@ |
||
1 | 1 | <?php |
2 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); |
|
3 | -if ( ! $_tests_dir ) { |
|
2 | +$_tests_dir = getenv('WP_TESTS_DIR'); |
|
3 | +if ( ! $_tests_dir) { |
|
4 | 4 | $_tests_dir = '/tmp/wordpress-tests-lib'; |
5 | 5 | } |
6 | 6 | |
7 | 7 | require_once $_tests_dir . '/includes/functions.php'; |
8 | 8 | |
9 | 9 | function _manually_load_plugin() { |
10 | - $plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/'; |
|
10 | + $plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; |
|
11 | 11 | require $plugin_dir . 'woocommerce/woocommerce.php'; |
12 | - require dirname( __FILE__ ) . '/setup.php'; |
|
12 | + require dirname(__FILE__) . '/setup.php'; |
|
13 | 13 | require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php'; |
14 | 14 | } |
15 | 15 | |
16 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
16 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
17 | 17 | |
18 | 18 | require $_tests_dir . '/includes/bootstrap.php'; |
19 | 19 | |
20 | -$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/'; |
|
21 | -require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' ); |
|
20 | +$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/'; |
|
21 | +require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php'); |
|
22 | 22 | //require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' ); |
23 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' ); |
|
24 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' ); |
|
25 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' ); |
|
26 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' ); |
|
27 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' ); |
|
28 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' ); |
|
23 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php'); |
|
24 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php'); |
|
25 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php'); |
|
26 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php'); |
|
27 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php'); |
|
28 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php'); |
@@ -2,4 +2,4 @@ |
||
2 | 2 | /** |
3 | 3 | * Set up shared by all tests. |
4 | 4 | */ |
5 | -update_option( 'woocommerce_default_country', 'US:CA' ); |
|
5 | +update_option('woocommerce_default_country', 'US:CA'); |