@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 4.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -64,41 +64,41 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __construct() { |
66 | 66 | self::$_this = $this; |
67 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
68 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
69 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
70 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
71 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
67 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
68 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
69 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
70 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
71 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
72 | 72 | |
73 | - if ( $this->testmode ) { |
|
74 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
75 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
73 | + if ($this->testmode) { |
|
74 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
75 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
76 | 76 | } |
77 | 77 | |
78 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
78 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
79 | 79 | |
80 | 80 | // Checks if Stripe Gateway is enabled. |
81 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
81 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | 85 | // Checks if Payment Request is enabled. |
86 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
86 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
87 | 87 | return; |
88 | 88 | } |
89 | 89 | |
90 | 90 | // Don't load for change payment method page. |
91 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
91 | + if (isset($_GET['change_payment_method'])) { |
|
92 | 92 | return; |
93 | 93 | } |
94 | 94 | |
95 | - $wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
95 | + $wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2); |
|
96 | 96 | |
97 | - if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) { |
|
97 | + if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
101 | + add_action('template_redirect', array($this, 'set_session')); |
|
102 | 102 | $this->init(); |
103 | 103 | } |
104 | 104 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return array The list of countries. |
110 | 110 | */ |
111 | 111 | public function get_stripe_supported_countries() { |
112 | - return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) ); |
|
112 | + return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | public function are_keys_set() { |
122 | 122 | // NOTE: updates to this function should be added to are_keys_set() |
123 | 123 | // in includes/abstracts/abstract-wc-stripe-payment-gateway.php |
124 | - if ( $this->testmode ) { |
|
125 | - return preg_match( '/^pk_test_/', $this->publishable_key ) |
|
126 | - && preg_match( '/^[rs]k_test_/', $this->secret_key ); |
|
124 | + if ($this->testmode) { |
|
125 | + return preg_match('/^pk_test_/', $this->publishable_key) |
|
126 | + && preg_match('/^[rs]k_test_/', $this->secret_key); |
|
127 | 127 | } else { |
128 | - return preg_match( '/^pk_live_/', $this->publishable_key ) |
|
129 | - && preg_match( '/^[rs]k_live_/', $this->secret_key ); |
|
128 | + return preg_match('/^pk_live_/', $this->publishable_key) |
|
129 | + && preg_match('/^[rs]k_live_/', $this->secret_key); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @since 4.0.0 |
148 | 148 | */ |
149 | 149 | public function set_session() { |
150 | - if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
150 | + if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
151 | 151 | return; |
152 | 152 | } |
153 | 153 | |
154 | - WC()->session->set_customer_session_cookie( true ); |
|
154 | + WC()->session->set_customer_session_cookie(true); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -161,30 +161,30 @@ discard block |
||
161 | 161 | * @version 4.0.0 |
162 | 162 | */ |
163 | 163 | public function init() { |
164 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
164 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
165 | 165 | |
166 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
167 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
166 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
167 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
168 | 168 | |
169 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
170 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
169 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
170 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
171 | 171 | |
172 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
173 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
172 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
173 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
174 | 174 | |
175 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
176 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
177 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
178 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
179 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
180 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
181 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
182 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
175 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
176 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
177 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
178 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
179 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
180 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
181 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
182 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
183 | 183 | |
184 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
185 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
184 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
185 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
186 | 186 | |
187 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
187 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @return string |
196 | 196 | */ |
197 | 197 | public function get_button_type() { |
198 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
198 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @return string |
207 | 207 | */ |
208 | 208 | public function get_button_theme() { |
209 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
209 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @return string |
218 | 218 | */ |
219 | 219 | public function get_button_height() { |
220 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
220 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @return string |
240 | 240 | */ |
241 | 241 | public function get_button_branded_type() { |
242 | - return isset( $this->stripe_settings['payment_request_button_branded_type'] ) ? $this->stripe_settings['payment_request_button_branded_type'] : 'default'; |
|
242 | + return isset($this->stripe_settings['payment_request_button_branded_type']) ? $this->stripe_settings['payment_request_button_branded_type'] : 'default'; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @return string |
273 | 273 | */ |
274 | 274 | public function get_button_label() { |
275 | - return isset( $this->stripe_settings['payment_request_button_label'] ) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now'; |
|
275 | + return isset($this->stripe_settings['payment_request_button_label']) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now'; |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,22 +282,22 @@ discard block |
||
282 | 282 | * @version 4.0.0 |
283 | 283 | */ |
284 | 284 | public function get_product_data() { |
285 | - if ( ! is_product() ) { |
|
285 | + if ( ! is_product()) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | 289 | global $post; |
290 | 290 | |
291 | - $product = wc_get_product( $post->ID ); |
|
291 | + $product = wc_get_product($post->ID); |
|
292 | 292 | |
293 | - if ( 'variable' === $product->get_type() ) { |
|
294 | - $attributes = wc_clean( wp_unslash( $_GET ) ); |
|
293 | + if ('variable' === $product->get_type()) { |
|
294 | + $attributes = wc_clean(wp_unslash($_GET)); |
|
295 | 295 | |
296 | - $data_store = WC_Data_Store::load( 'product' ); |
|
297 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
296 | + $data_store = WC_Data_Store::load('product'); |
|
297 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
298 | 298 | |
299 | - if ( ! empty( $variation_id ) ) { |
|
300 | - $product = wc_get_product( $variation_id ); |
|
299 | + if ( ! empty($variation_id)) { |
|
300 | + $product = wc_get_product($variation_id); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
@@ -306,27 +306,27 @@ discard block |
||
306 | 306 | |
307 | 307 | $items[] = array( |
308 | 308 | 'label' => $product->get_name(), |
309 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ), |
|
309 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($product->get_price()), |
|
310 | 310 | ); |
311 | 311 | |
312 | - if ( wc_tax_enabled() ) { |
|
312 | + if (wc_tax_enabled()) { |
|
313 | 313 | $items[] = array( |
314 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
314 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
315 | 315 | 'amount' => 0, |
316 | 316 | 'pending' => true, |
317 | 317 | ); |
318 | 318 | } |
319 | 319 | |
320 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
320 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
321 | 321 | $items[] = array( |
322 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
322 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
323 | 323 | 'amount' => 0, |
324 | 324 | 'pending' => true, |
325 | 325 | ); |
326 | 326 | |
327 | 327 | $data['shippingOptions'] = array( |
328 | 328 | 'id' => 'pending', |
329 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
329 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
330 | 330 | 'detail' => '', |
331 | 331 | 'amount' => 0, |
332 | 332 | ); |
@@ -334,37 +334,37 @@ discard block |
||
334 | 334 | |
335 | 335 | $data['displayItems'] = $items; |
336 | 336 | $data['total'] = array( |
337 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
338 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ), |
|
337 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
338 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($product->get_price()), |
|
339 | 339 | 'pending' => true, |
340 | 340 | ); |
341 | 341 | |
342 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
343 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
344 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
342 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
343 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
344 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
345 | 345 | |
346 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
346 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
350 | 350 | * Filters the gateway title to reflect Payment Request type |
351 | 351 | * |
352 | 352 | */ |
353 | - public function filter_gateway_title( $title, $id ) { |
|
353 | + public function filter_gateway_title($title, $id) { |
|
354 | 354 | global $post; |
355 | 355 | |
356 | - if ( ! is_object( $post ) ) { |
|
356 | + if ( ! is_object($post)) { |
|
357 | 357 | return $title; |
358 | 358 | } |
359 | 359 | |
360 | - $order = wc_get_order( $post->ID ); |
|
361 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
360 | + $order = wc_get_order($post->ID); |
|
361 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
362 | 362 | |
363 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
363 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
364 | 364 | return $method_title; |
365 | 365 | } |
366 | 366 | |
367 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
367 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
368 | 368 | return $method_title; |
369 | 369 | } |
370 | 370 | |
@@ -377,16 +377,16 @@ discard block |
||
377 | 377 | * @since 3.1.4 |
378 | 378 | * @version 4.0.0 |
379 | 379 | */ |
380 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
380 | + public function postal_code_validation($valid, $postcode, $country) { |
|
381 | 381 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
382 | 382 | |
383 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
383 | + if ( ! isset($gateways['stripe'])) { |
|
384 | 384 | return $valid; |
385 | 385 | } |
386 | 386 | |
387 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
387 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
388 | 388 | |
389 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
389 | + if ('apple_pay' !== $payment_request_type) { |
|
390 | 390 | return $valid; |
391 | 391 | } |
392 | 392 | |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * the order and not let it go through. The remedy for now is just to remove this validation. |
397 | 397 | * Note that this only works with shipping providers that don't validate full postal codes. |
398 | 398 | */ |
399 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
399 | + if ('GB' === $country || 'CA' === $country) { |
|
400 | 400 | return true; |
401 | 401 | } |
402 | 402 | |
@@ -411,22 +411,22 @@ discard block |
||
411 | 411 | * @param int $order_id |
412 | 412 | * @param array $posted_data The posted data from checkout form. |
413 | 413 | */ |
414 | - public function add_order_meta( $order_id, $posted_data ) { |
|
415 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
414 | + public function add_order_meta($order_id, $posted_data) { |
|
415 | + if (empty($_POST['payment_request_type'])) { |
|
416 | 416 | return; |
417 | 417 | } |
418 | 418 | |
419 | - $order = wc_get_order( $order_id ); |
|
419 | + $order = wc_get_order($order_id); |
|
420 | 420 | |
421 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
421 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
422 | 422 | |
423 | - if ( 'apple_pay' === $payment_request_type ) { |
|
424 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
423 | + if ('apple_pay' === $payment_request_type) { |
|
424 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
425 | 425 | $order->save(); |
426 | 426 | } |
427 | 427 | |
428 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
429 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
428 | + if ('payment_request_api' === $payment_request_type) { |
|
429 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
430 | 430 | $order->save(); |
431 | 431 | } |
432 | 432 | } |
@@ -464,20 +464,20 @@ discard block |
||
464 | 464 | * @return bool |
465 | 465 | */ |
466 | 466 | public function allowed_items_in_cart() { |
467 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
468 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
467 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
468 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
469 | 469 | |
470 | - if ( ! in_array( $_product->get_type(), $this->supported_product_types() ) ) { |
|
470 | + if ( ! in_array($_product->get_type(), $this->supported_product_types())) { |
|
471 | 471 | return false; |
472 | 472 | } |
473 | 473 | |
474 | 474 | // Trial subscriptions with shipping are not supported |
475 | - if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) { |
|
475 | + if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) { |
|
476 | 476 | return false; |
477 | 477 | } |
478 | 478 | |
479 | 479 | // Pre Orders compatbility where we don't support charge upon release. |
480 | - 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() ) ) { |
|
480 | + 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())) { |
|
481 | 481 | return false; |
482 | 482 | } |
483 | 483 | } |
@@ -493,59 +493,59 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public function scripts() { |
495 | 495 | // If keys are not set bail. |
496 | - if ( ! $this->are_keys_set() ) { |
|
497 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
496 | + if ( ! $this->are_keys_set()) { |
|
497 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
498 | 498 | return; |
499 | 499 | } |
500 | 500 | |
501 | 501 | // If no SSL bail. |
502 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
503 | - WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
502 | + if ( ! $this->testmode && ! is_ssl()) { |
|
503 | + WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
504 | 504 | return; |
505 | 505 | } |
506 | 506 | |
507 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
507 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
508 | 508 | return; |
509 | 509 | } |
510 | 510 | |
511 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
511 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
512 | 512 | return; |
513 | 513 | } |
514 | 514 | |
515 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
515 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
516 | 516 | |
517 | 517 | $stripe_params = array( |
518 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
518 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
519 | 519 | 'stripe' => array( |
520 | 520 | 'key' => $this->publishable_key, |
521 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
521 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
522 | 522 | ), |
523 | 523 | 'nonce' => array( |
524 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
525 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
526 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
527 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
528 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
529 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
530 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
531 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
524 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
525 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
526 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
527 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
528 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
529 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
530 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
531 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
532 | 532 | ), |
533 | 533 | 'i18n' => array( |
534 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
534 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
535 | 535 | /* translators: Do not translate the [option] placeholder */ |
536 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
536 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
537 | 537 | ), |
538 | 538 | 'checkout' => array( |
539 | 539 | 'url' => wc_get_checkout_url(), |
540 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
541 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
540 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
541 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
542 | 542 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
543 | 543 | ), |
544 | 544 | 'button' => array( |
545 | 545 | 'type' => $this->get_button_type(), |
546 | 546 | 'theme' => $this->get_button_theme(), |
547 | 547 | 'height' => $this->get_button_height(), |
548 | - 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US. |
|
548 | + 'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US. |
|
549 | 549 | 'is_custom' => $this->is_custom_button(), |
550 | 550 | 'is_branded' => $this->is_branded_button(), |
551 | 551 | 'css_selector' => $this->custom_button_selector(), |
@@ -555,15 +555,15 @@ discard block |
||
555 | 555 | 'product' => $this->get_product_data(), |
556 | 556 | ); |
557 | 557 | |
558 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
559 | - 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 ); |
|
558 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
559 | + 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); |
|
560 | 560 | |
561 | - wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) ); |
|
561 | + wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params)); |
|
562 | 562 | |
563 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
563 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
564 | 564 | |
565 | 565 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
566 | - if ( isset( $gateways['stripe'] ) ) { |
|
566 | + if (isset($gateways['stripe'])) { |
|
567 | 567 | $gateways['stripe']->payment_scripts(); |
568 | 568 | } |
569 | 569 | } |
@@ -579,31 +579,31 @@ discard block |
||
579 | 579 | |
580 | 580 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
581 | 581 | |
582 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
582 | + if ( ! isset($gateways['stripe'])) { |
|
583 | 583 | return; |
584 | 584 | } |
585 | 585 | |
586 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
586 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
587 | 587 | return; |
588 | 588 | } |
589 | 589 | |
590 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
590 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
591 | 591 | return; |
592 | 592 | } |
593 | 593 | |
594 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
594 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
595 | 595 | return; |
596 | - } else if ( ! $this->should_show_payment_button_on_cart() ) { |
|
596 | + } else if ( ! $this->should_show_payment_button_on_cart()) { |
|
597 | 597 | return; |
598 | 598 | } |
599 | 599 | ?> |
600 | 600 | <div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;display:none;"> |
601 | 601 | <div id="wc-stripe-payment-request-button"> |
602 | 602 | <?php |
603 | - if ( $this->is_custom_button() ) { |
|
604 | - $label = esc_html( $this->get_button_label() ); |
|
605 | - $class_name = esc_attr( 'button ' . $this->get_button_theme() ); |
|
606 | - $style = esc_attr( 'height:' . $this->get_button_height() . 'px;' ); |
|
603 | + if ($this->is_custom_button()) { |
|
604 | + $label = esc_html($this->get_button_label()); |
|
605 | + $class_name = esc_attr('button ' . $this->get_button_theme()); |
|
606 | + $style = esc_attr('height:' . $this->get_button_height() . 'px;'); |
|
607 | 607 | echo "<button id=\"wc-stripe-custom-button\" class=\"$class_name\" style=\"$style\"> $label </button>"; |
608 | 608 | } |
609 | 609 | ?> |
@@ -624,25 +624,25 @@ discard block |
||
624 | 624 | |
625 | 625 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
626 | 626 | |
627 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
627 | + if ( ! isset($gateways['stripe'])) { |
|
628 | 628 | return; |
629 | 629 | } |
630 | 630 | |
631 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
631 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
632 | 632 | return; |
633 | 633 | } |
634 | 634 | |
635 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
635 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
636 | 636 | return; |
637 | 637 | } |
638 | 638 | |
639 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
639 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
640 | 640 | return; |
641 | - } else if ( ! $this->should_show_payment_button_on_cart() ) { |
|
641 | + } else if ( ! $this->should_show_payment_button_on_cart()) { |
|
642 | 642 | return; |
643 | 643 | } |
644 | 644 | ?> |
645 | - <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> |
|
645 | + <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> |
|
646 | 646 | <?php |
647 | 647 | } |
648 | 648 | |
@@ -654,11 +654,11 @@ discard block |
||
654 | 654 | * @return bool |
655 | 655 | */ |
656 | 656 | private function should_show_payment_button_on_cart() { |
657 | - if ( ! apply_filters( 'wc_stripe_show_payment_request_on_cart', true ) ) { |
|
657 | + if ( ! apply_filters('wc_stripe_show_payment_request_on_cart', true)) { |
|
658 | 658 | return false; |
659 | 659 | } |
660 | - if ( ! $this->allowed_items_in_cart() ) { |
|
661 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
660 | + if ( ! $this->allowed_items_in_cart()) { |
|
661 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
662 | 662 | return false; |
663 | 663 | } |
664 | 664 | return true; |
@@ -674,32 +674,32 @@ discard block |
||
674 | 674 | private function should_show_payment_button_on_product_page() { |
675 | 675 | global $post; |
676 | 676 | |
677 | - $product = wc_get_product( $post->ID ); |
|
677 | + $product = wc_get_product($post->ID); |
|
678 | 678 | |
679 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
679 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
680 | 680 | return false; |
681 | 681 | } |
682 | 682 | |
683 | - if ( ! is_object( $product ) || ! in_array( $product->get_type(), $this->supported_product_types() ) ) { |
|
683 | + if ( ! is_object($product) || ! in_array($product->get_type(), $this->supported_product_types())) { |
|
684 | 684 | return false; |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Trial subscriptions with shipping are not supported |
688 | - if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) { |
|
688 | + if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) { |
|
689 | 689 | return false; |
690 | 690 | } |
691 | 691 | |
692 | 692 | // Pre Orders charge upon release not supported. |
693 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
694 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
693 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
694 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
695 | 695 | return false; |
696 | 696 | } |
697 | 697 | |
698 | 698 | // File upload addon not supported |
699 | - if ( class_exists( 'WC_Product_Addons_Helper' ) ) { |
|
700 | - $product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() ); |
|
701 | - foreach ( $product_addons as $addon ) { |
|
702 | - if ( 'file_upload' === $addon['type'] ) { |
|
699 | + if (class_exists('WC_Product_Addons_Helper')) { |
|
700 | + $product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id()); |
|
701 | + foreach ($product_addons as $addon) { |
|
702 | + if ('file_upload' === $addon['type']) { |
|
703 | 703 | return false; |
704 | 704 | } |
705 | 705 | } |
@@ -715,11 +715,11 @@ discard block |
||
715 | 715 | * @version 4.0.0 |
716 | 716 | */ |
717 | 717 | public function ajax_log_errors() { |
718 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
718 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
719 | 719 | |
720 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
720 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
721 | 721 | |
722 | - WC_Stripe_Logger::log( $errors ); |
|
722 | + WC_Stripe_Logger::log($errors); |
|
723 | 723 | |
724 | 724 | exit; |
725 | 725 | } |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | * @version 4.0.0 |
732 | 732 | */ |
733 | 733 | public function ajax_clear_cart() { |
734 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
734 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
735 | 735 | |
736 | 736 | WC()->cart->empty_cart(); |
737 | 737 | exit; |
@@ -741,10 +741,10 @@ discard block |
||
741 | 741 | * Get cart details. |
742 | 742 | */ |
743 | 743 | public function ajax_get_cart_details() { |
744 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
744 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
745 | 745 | |
746 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
747 | - define( 'WOOCOMMERCE_CART', true ); |
|
746 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
747 | + define('WOOCOMMERCE_CART', true); |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | WC()->cart->calculate_totals(); |
@@ -755,14 +755,14 @@ discard block |
||
755 | 755 | $data = array( |
756 | 756 | 'shipping_required' => WC()->cart->needs_shipping(), |
757 | 757 | 'order_data' => array( |
758 | - 'currency' => strtolower( $currency ), |
|
759 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
758 | + 'currency' => strtolower($currency), |
|
759 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
760 | 760 | ), |
761 | 761 | ); |
762 | 762 | |
763 | 763 | $data['order_data'] += $this->build_display_items(); |
764 | 764 | |
765 | - wp_send_json( $data ); |
|
765 | + wp_send_json($data); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | /** |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | * @see WC_Shipping::get_packages(). |
774 | 774 | */ |
775 | 775 | public function ajax_get_shipping_options() { |
776 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
776 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
777 | 777 | |
778 | 778 | $shipping_address = filter_input_array( |
779 | 779 | INPUT_POST, |
@@ -787,8 +787,8 @@ discard block |
||
787 | 787 | ) |
788 | 788 | ); |
789 | 789 | |
790 | - $data = $this->get_shipping_options( $shipping_address ); |
|
791 | - wp_send_json( $data ); |
|
790 | + $data = $this->get_shipping_options($shipping_address); |
|
791 | + wp_send_json($data); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
@@ -799,65 +799,65 @@ discard block |
||
799 | 799 | * @return array Shipping options data. |
800 | 800 | * phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag |
801 | 801 | */ |
802 | - public function get_shipping_options( $shipping_address ) { |
|
802 | + public function get_shipping_options($shipping_address) { |
|
803 | 803 | try { |
804 | 804 | // Set the shipping options. |
805 | 805 | $data = array(); |
806 | 806 | |
807 | 807 | // Remember current shipping method before resetting. |
808 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
809 | - $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $shipping_address ) ); |
|
808 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
809 | + $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $shipping_address)); |
|
810 | 810 | |
811 | 811 | $packages = WC()->shipping->get_packages(); |
812 | 812 | |
813 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
814 | - foreach ( $packages as $package_key => $package ) { |
|
815 | - if ( empty( $package['rates'] ) ) { |
|
816 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
813 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
814 | + foreach ($packages as $package_key => $package) { |
|
815 | + if (empty($package['rates'])) { |
|
816 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
817 | 817 | } |
818 | 818 | |
819 | - foreach ( $package['rates'] as $key => $rate ) { |
|
819 | + foreach ($package['rates'] as $key => $rate) { |
|
820 | 820 | $data['shipping_options'][] = array( |
821 | 821 | 'id' => $rate->id, |
822 | 822 | 'label' => $rate->label, |
823 | 823 | 'detail' => '', |
824 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
824 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
825 | 825 | ); |
826 | 826 | } |
827 | 827 | } |
828 | 828 | } else { |
829 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
829 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | // The first shipping option is automatically applied on the client. |
833 | 833 | // Keep chosen shipping method by sorting shipping options if the method still available for new address. |
834 | 834 | // Fallback to the first available shipping method. |
835 | - if ( isset( $data['shipping_options'][0] ) ) { |
|
836 | - if ( isset( $chosen_shipping_methods[0] ) ) { |
|
835 | + if (isset($data['shipping_options'][0])) { |
|
836 | + if (isset($chosen_shipping_methods[0])) { |
|
837 | 837 | $chosen_method_id = $chosen_shipping_methods[0]; |
838 | - $compare_shipping_options = function ( $a, $b ) use ( $chosen_method_id ) { |
|
839 | - if ( $a['id'] === $chosen_method_id ) { |
|
838 | + $compare_shipping_options = function($a, $b) use ($chosen_method_id) { |
|
839 | + if ($a['id'] === $chosen_method_id) { |
|
840 | 840 | return -1; |
841 | 841 | } |
842 | 842 | |
843 | - if ( $b['id'] === $chosen_method_id ) { |
|
843 | + if ($b['id'] === $chosen_method_id) { |
|
844 | 844 | return 1; |
845 | 845 | } |
846 | 846 | |
847 | 847 | return 0; |
848 | 848 | }; |
849 | - usort( $data['shipping_options'], $compare_shipping_options ); |
|
849 | + usort($data['shipping_options'], $compare_shipping_options); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | $first_shipping_method_id = $data['shipping_options'][0]['id']; |
853 | - $this->update_shipping_method( [ $first_shipping_method_id ] ); |
|
853 | + $this->update_shipping_method([$first_shipping_method_id]); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | WC()->cart->calculate_totals(); |
857 | 857 | |
858 | 858 | $data += $this->build_display_items(); |
859 | 859 | $data['result'] = 'success'; |
860 | - } catch ( Exception $e ) { |
|
860 | + } catch (Exception $e) { |
|
861 | 861 | $data += $this->build_display_items(); |
862 | 862 | $data['result'] = 'invalid_shipping_address'; |
863 | 863 | } |
@@ -869,14 +869,14 @@ discard block |
||
869 | 869 | * Update shipping method. |
870 | 870 | */ |
871 | 871 | public function ajax_update_shipping_method() { |
872 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
872 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
873 | 873 | |
874 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
875 | - define( 'WOOCOMMERCE_CART', true ); |
|
874 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
875 | + define('WOOCOMMERCE_CART', true); |
|
876 | 876 | } |
877 | 877 | |
878 | - $shipping_methods = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
879 | - $this->update_shipping_method( $shipping_methods ); |
|
878 | + $shipping_methods = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
879 | + $this->update_shipping_method($shipping_methods); |
|
880 | 880 | |
881 | 881 | WC()->cart->calculate_totals(); |
882 | 882 | |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | $data += $this->build_display_items(); |
885 | 885 | $data['result'] = 'success'; |
886 | 886 | |
887 | - wp_send_json( $data ); |
|
887 | + wp_send_json($data); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
@@ -892,16 +892,16 @@ discard block |
||
892 | 892 | * |
893 | 893 | * @param array $shipping_methods Array of selected shipping methods ids. |
894 | 894 | */ |
895 | - public function update_shipping_method( $shipping_methods ) { |
|
896 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
895 | + public function update_shipping_method($shipping_methods) { |
|
896 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
897 | 897 | |
898 | - if ( is_array( $shipping_methods ) ) { |
|
899 | - foreach ( $shipping_methods as $i => $value ) { |
|
900 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
898 | + if (is_array($shipping_methods)) { |
|
899 | + foreach ($shipping_methods as $i => $value) { |
|
900 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
901 | 901 | } |
902 | 902 | } |
903 | 903 | |
904 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
904 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
905 | 905 | } |
906 | 906 | |
907 | 907 | /** |
@@ -912,38 +912,38 @@ discard block |
||
912 | 912 | * @return array $data |
913 | 913 | */ |
914 | 914 | public function ajax_get_selected_product_data() { |
915 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
915 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
916 | 916 | |
917 | 917 | try { |
918 | - $product_id = absint( $_POST['product_id'] ); |
|
919 | - $qty = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id ); |
|
920 | - $addon_value = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0; |
|
921 | - $product = wc_get_product( $product_id ); |
|
918 | + $product_id = absint($_POST['product_id']); |
|
919 | + $qty = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id); |
|
920 | + $addon_value = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0; |
|
921 | + $product = wc_get_product($product_id); |
|
922 | 922 | $variation_id = null; |
923 | 923 | |
924 | - if ( ! is_a( $product, 'WC_Product' ) ) { |
|
925 | - throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); |
|
924 | + if ( ! is_a($product, 'WC_Product')) { |
|
925 | + throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id)); |
|
926 | 926 | } |
927 | 927 | |
928 | - if ( 'variable' === $product->get_type() && isset( $_POST['attributes'] ) ) { |
|
929 | - $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
928 | + if ('variable' === $product->get_type() && isset($_POST['attributes'])) { |
|
929 | + $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
930 | 930 | |
931 | - $data_store = WC_Data_Store::load( 'product' ); |
|
932 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
931 | + $data_store = WC_Data_Store::load('product'); |
|
932 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
933 | 933 | |
934 | - if ( ! empty( $variation_id ) ) { |
|
935 | - $product = wc_get_product( $variation_id ); |
|
934 | + if ( ! empty($variation_id)) { |
|
935 | + $product = wc_get_product($variation_id); |
|
936 | 936 | } |
937 | 937 | } |
938 | 938 | |
939 | 939 | // Force quantity to 1 if sold individually and check for existing item in cart. |
940 | - if ( $product->is_sold_individually() ) { |
|
941 | - $qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id ); |
|
940 | + if ($product->is_sold_individually()) { |
|
941 | + $qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id); |
|
942 | 942 | } |
943 | 943 | |
944 | - if ( ! $product->has_enough_stock( $qty ) ) { |
|
944 | + if ( ! $product->has_enough_stock($qty)) { |
|
945 | 945 | /* translators: 1: product name 2: quantity in stock */ |
946 | - 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 ) ) ); |
|
946 | + 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))); |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | $total = $qty * $product->get_price() + $addon_value; |
@@ -955,27 +955,27 @@ discard block |
||
955 | 955 | |
956 | 956 | $items[] = array( |
957 | 957 | 'label' => $product->get_name() . $quantity_label, |
958 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
958 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
959 | 959 | ); |
960 | 960 | |
961 | - if ( wc_tax_enabled() ) { |
|
961 | + if (wc_tax_enabled()) { |
|
962 | 962 | $items[] = array( |
963 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
963 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
964 | 964 | 'amount' => 0, |
965 | 965 | 'pending' => true, |
966 | 966 | ); |
967 | 967 | } |
968 | 968 | |
969 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
969 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
970 | 970 | $items[] = array( |
971 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
971 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
972 | 972 | 'amount' => 0, |
973 | 973 | 'pending' => true, |
974 | 974 | ); |
975 | 975 | |
976 | 976 | $data['shippingOptions'] = array( |
977 | 977 | 'id' => 'pending', |
978 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
978 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
979 | 979 | 'detail' => '', |
980 | 980 | 'amount' => 0, |
981 | 981 | ); |
@@ -984,17 +984,17 @@ discard block |
||
984 | 984 | $data['displayItems'] = $items; |
985 | 985 | $data['total'] = array( |
986 | 986 | 'label' => $this->total_label, |
987 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
987 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
988 | 988 | 'pending' => true, |
989 | 989 | ); |
990 | 990 | |
991 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
992 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
993 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
991 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
992 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
993 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
994 | 994 | |
995 | - wp_send_json( $data ); |
|
996 | - } catch ( Exception $e ) { |
|
997 | - wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) ); |
|
995 | + wp_send_json($data); |
|
996 | + } catch (Exception $e) { |
|
997 | + wp_send_json(array('error' => wp_strip_all_tags($e->getMessage()))); |
|
998 | 998 | } |
999 | 999 | } |
1000 | 1000 | |
@@ -1006,33 +1006,33 @@ discard block |
||
1006 | 1006 | * @return array $data |
1007 | 1007 | */ |
1008 | 1008 | public function ajax_add_to_cart() { |
1009 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
1009 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
1010 | 1010 | |
1011 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1012 | - define( 'WOOCOMMERCE_CART', true ); |
|
1011 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1012 | + define('WOOCOMMERCE_CART', true); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | WC()->shipping->reset_shipping(); |
1016 | 1016 | |
1017 | - $product_id = absint( $_POST['product_id'] ); |
|
1018 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
1019 | - $product = wc_get_product( $product_id ); |
|
1017 | + $product_id = absint($_POST['product_id']); |
|
1018 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
1019 | + $product = wc_get_product($product_id); |
|
1020 | 1020 | $product_type = $product->get_type(); |
1021 | 1021 | |
1022 | 1022 | // First empty the cart to prevent wrong calculation. |
1023 | 1023 | WC()->cart->empty_cart(); |
1024 | 1024 | |
1025 | - if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { |
|
1026 | - $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
1025 | + if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) { |
|
1026 | + $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
1027 | 1027 | |
1028 | - $data_store = WC_Data_Store::load( 'product' ); |
|
1029 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
1028 | + $data_store = WC_Data_Store::load('product'); |
|
1029 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
1030 | 1030 | |
1031 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
1031 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | - if ( 'simple' === $product_type || 'subscription' === $product_type ) { |
|
1035 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
1034 | + if ('simple' === $product_type || 'subscription' === $product_type) { |
|
1035 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | WC()->cart->calculate_totals(); |
@@ -1041,7 +1041,7 @@ discard block |
||
1041 | 1041 | $data += $this->build_display_items(); |
1042 | 1042 | $data['result'] = 'success'; |
1043 | 1043 | |
1044 | - wp_send_json( $data ); |
|
1044 | + wp_send_json($data); |
|
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | /** |
@@ -1054,31 +1054,31 @@ discard block |
||
1054 | 1054 | * @version 4.0.0 |
1055 | 1055 | */ |
1056 | 1056 | public function normalize_state() { |
1057 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
1058 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
1059 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
1060 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
1057 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
1058 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
1059 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
1060 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
1061 | 1061 | |
1062 | - if ( $billing_state && $billing_country ) { |
|
1063 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
1062 | + if ($billing_state && $billing_country) { |
|
1063 | + $valid_states = WC()->countries->get_states($billing_country); |
|
1064 | 1064 | |
1065 | 1065 | // Valid states found for country. |
1066 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
1067 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
1068 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
1066 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
1067 | + foreach ($valid_states as $state_abbr => $state) { |
|
1068 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
1069 | 1069 | $_POST['billing_state'] = $state_abbr; |
1070 | 1070 | } |
1071 | 1071 | } |
1072 | 1072 | } |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - if ( $shipping_state && $shipping_country ) { |
|
1076 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
1075 | + if ($shipping_state && $shipping_country) { |
|
1076 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
1077 | 1077 | |
1078 | 1078 | // Valid states found for country. |
1079 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
1080 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
1081 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
1079 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
1080 | + foreach ($valid_states as $state_abbr => $state) { |
|
1081 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
1082 | 1082 | $_POST['shipping_state'] = $state_abbr; |
1083 | 1083 | } |
1084 | 1084 | } |
@@ -1093,19 +1093,19 @@ discard block |
||
1093 | 1093 | * @version 4.0.0 |
1094 | 1094 | */ |
1095 | 1095 | public function ajax_create_order() { |
1096 | - if ( WC()->cart->is_empty() ) { |
|
1097 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
1096 | + if (WC()->cart->is_empty()) { |
|
1097 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
1101 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
1100 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
1101 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | $this->normalize_state(); |
1105 | 1105 | |
1106 | 1106 | WC()->checkout()->process_checkout(); |
1107 | 1107 | |
1108 | - die( 0 ); |
|
1108 | + die(0); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | /** |
@@ -1115,38 +1115,38 @@ discard block |
||
1115 | 1115 | * @version 4.0.0 |
1116 | 1116 | * @param array $address |
1117 | 1117 | */ |
1118 | - protected function calculate_shipping( $address = array() ) { |
|
1118 | + protected function calculate_shipping($address = array()) { |
|
1119 | 1119 | $country = $address['country']; |
1120 | 1120 | $state = $address['state']; |
1121 | 1121 | $postcode = $address['postcode']; |
1122 | 1122 | $city = $address['city']; |
1123 | 1123 | $address_1 = $address['address']; |
1124 | 1124 | $address_2 = $address['address_2']; |
1125 | - $wc_states = WC()->countries->get_states( $country ); |
|
1125 | + $wc_states = WC()->countries->get_states($country); |
|
1126 | 1126 | |
1127 | 1127 | /** |
1128 | 1128 | * In some versions of Chrome, state can be a full name. So we need |
1129 | 1129 | * to convert that to abbreviation as WC is expecting that. |
1130 | 1130 | */ |
1131 | - if ( 2 < strlen( $state ) && ! empty( $wc_states ) && ! isset( $wc_states[ $state ] ) ) { |
|
1132 | - $state = array_search( ucwords( strtolower( $state ) ), $wc_states, true ); |
|
1131 | + if (2 < strlen($state) && ! empty($wc_states) && ! isset($wc_states[$state])) { |
|
1132 | + $state = array_search(ucwords(strtolower($state)), $wc_states, true); |
|
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | WC()->shipping->reset_shipping(); |
1136 | 1136 | |
1137 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
1138 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
1137 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
1138 | + $postcode = wc_format_postcode($postcode, $country); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | - if ( $country ) { |
|
1142 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1143 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
1141 | + if ($country) { |
|
1142 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
1143 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1144 | 1144 | } else { |
1145 | 1145 | WC()->customer->set_billing_address_to_base(); |
1146 | 1146 | WC()->customer->set_shipping_address_to_base(); |
1147 | 1147 | } |
1148 | 1148 | |
1149 | - WC()->customer->set_calculated_shipping( true ); |
|
1149 | + WC()->customer->set_calculated_shipping(true); |
|
1150 | 1150 | WC()->customer->save(); |
1151 | 1151 | |
1152 | 1152 | $packages = array(); |
@@ -1162,17 +1162,17 @@ discard block |
||
1162 | 1162 | $packages[0]['destination']['address'] = $address_1; |
1163 | 1163 | $packages[0]['destination']['address_2'] = $address_2; |
1164 | 1164 | |
1165 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1166 | - if ( $item['data']->needs_shipping() ) { |
|
1167 | - if ( isset( $item['line_total'] ) ) { |
|
1165 | + foreach (WC()->cart->get_cart() as $item) { |
|
1166 | + if ($item['data']->needs_shipping()) { |
|
1167 | + if (isset($item['line_total'])) { |
|
1168 | 1168 | $packages[0]['contents_cost'] += $item['line_total']; |
1169 | 1169 | } |
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1173 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1174 | 1174 | |
1175 | - WC()->shipping->calculate_shipping( $packages ); |
|
1175 | + WC()->shipping->calculate_shipping($packages); |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | /** |
@@ -1181,19 +1181,19 @@ discard block |
||
1181 | 1181 | * @since 3.1.0 |
1182 | 1182 | * @version 4.0.0 |
1183 | 1183 | */ |
1184 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1185 | - if ( empty( $shipping_methods ) ) { |
|
1184 | + protected function build_shipping_methods($shipping_methods) { |
|
1185 | + if (empty($shipping_methods)) { |
|
1186 | 1186 | return array(); |
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | $shipping = array(); |
1190 | 1190 | |
1191 | - foreach ( $shipping_methods as $method ) { |
|
1191 | + foreach ($shipping_methods as $method) { |
|
1192 | 1192 | $shipping[] = array( |
1193 | 1193 | 'id' => $method['id'], |
1194 | 1194 | 'label' => $method['label'], |
1195 | 1195 | 'detail' => '', |
1196 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1196 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1197 | 1197 | ); |
1198 | 1198 | } |
1199 | 1199 | |
@@ -1207,8 +1207,8 @@ discard block |
||
1207 | 1207 | * @version 4.0.0 |
1208 | 1208 | */ |
1209 | 1209 | protected function build_display_items() { |
1210 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1211 | - define( 'WOOCOMMERCE_CART', true ); |
|
1210 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1211 | + define('WOOCOMMERCE_CART', true); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | $items = array(); |
@@ -1216,8 +1216,8 @@ discard block |
||
1216 | 1216 | $discounts = 0; |
1217 | 1217 | |
1218 | 1218 | // Default show only subtotal instead of itemization. |
1219 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1220 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1219 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1220 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1221 | 1221 | $amount = $cart_item['line_subtotal']; |
1222 | 1222 | $subtotal += $cart_item['line_subtotal']; |
1223 | 1223 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
@@ -1226,61 +1226,61 @@ discard block |
||
1226 | 1226 | |
1227 | 1227 | $item = array( |
1228 | 1228 | 'label' => $product_name . $quantity_label, |
1229 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1229 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1230 | 1230 | ); |
1231 | 1231 | |
1232 | 1232 | $items[] = $item; |
1233 | 1233 | } |
1234 | 1234 | } |
1235 | 1235 | |
1236 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1237 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1236 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1237 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1238 | 1238 | } else { |
1239 | - $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
1239 | + $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
1240 | 1240 | |
1241 | - foreach ( $applied_coupons as $amount ) { |
|
1241 | + foreach ($applied_coupons as $amount) { |
|
1242 | 1242 | $discounts += (float) $amount; |
1243 | 1243 | } |
1244 | 1244 | } |
1245 | 1245 | |
1246 | - $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
1247 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1248 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1249 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1250 | - $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
1246 | + $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
1247 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1248 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1249 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1250 | + $order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false); |
|
1251 | 1251 | |
1252 | - if ( wc_tax_enabled() ) { |
|
1252 | + if (wc_tax_enabled()) { |
|
1253 | 1253 | $items[] = array( |
1254 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1255 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1254 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1255 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1256 | 1256 | ); |
1257 | 1257 | } |
1258 | 1258 | |
1259 | - if ( WC()->cart->needs_shipping() ) { |
|
1259 | + if (WC()->cart->needs_shipping()) { |
|
1260 | 1260 | $items[] = array( |
1261 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1262 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1261 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1262 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1263 | 1263 | ); |
1264 | 1264 | } |
1265 | 1265 | |
1266 | - if ( WC()->cart->has_discount() ) { |
|
1266 | + if (WC()->cart->has_discount()) { |
|
1267 | 1267 | $items[] = array( |
1268 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1269 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1268 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1269 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1270 | 1270 | ); |
1271 | 1271 | } |
1272 | 1272 | |
1273 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1273 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1274 | 1274 | $cart_fees = WC()->cart->fees; |
1275 | 1275 | } else { |
1276 | 1276 | $cart_fees = WC()->cart->get_fees(); |
1277 | 1277 | } |
1278 | 1278 | |
1279 | 1279 | // Include fees and taxes as display items. |
1280 | - foreach ( $cart_fees as $key => $fee ) { |
|
1280 | + foreach ($cart_fees as $key => $fee) { |
|
1281 | 1281 | $items[] = array( |
1282 | 1282 | 'label' => $fee->name, |
1283 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1283 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1284 | 1284 | ); |
1285 | 1285 | } |
1286 | 1286 | |
@@ -1288,7 +1288,7 @@ discard block |
||
1288 | 1288 | 'displayItems' => $items, |
1289 | 1289 | 'total' => array( |
1290 | 1290 | 'label' => $this->total_label, |
1291 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1291 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1292 | 1292 | 'pending' => false, |
1293 | 1293 | ), |
1294 | 1294 | ); |