@@ -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 | } |
@@ -466,28 +466,28 @@ discard block |
||
466 | 466 | public function allowed_items_in_cart() { |
467 | 467 | $allowed = true; |
468 | 468 | |
469 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
470 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
469 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
470 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
471 | 471 | |
472 | - if ( ! in_array( $_product->get_type(), $this->supported_product_types() ) ) { |
|
472 | + if ( ! in_array($_product->get_type(), $this->supported_product_types())) { |
|
473 | 473 | $allowed = false; |
474 | 474 | break; |
475 | 475 | } |
476 | 476 | |
477 | 477 | // Trial subscriptions with shipping are not supported |
478 | - if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) { |
|
478 | + if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) { |
|
479 | 479 | $allowed = false; |
480 | 480 | break; |
481 | 481 | } |
482 | 482 | |
483 | 483 | // Pre Orders compatbility where we don't support charge upon release. |
484 | - 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() ) ) { |
|
484 | + 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())) { |
|
485 | 485 | $allowed = false; |
486 | 486 | break; |
487 | 487 | } |
488 | 488 | } |
489 | 489 | |
490 | - return apply_filters( 'wc_stripe_show_payment_request_on_cart', $allowed ); |
|
490 | + return apply_filters('wc_stripe_show_payment_request_on_cart', $allowed); |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | /** |
@@ -498,59 +498,59 @@ discard block |
||
498 | 498 | */ |
499 | 499 | public function scripts() { |
500 | 500 | // If keys are not set bail. |
501 | - if ( ! $this->are_keys_set() ) { |
|
502 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
501 | + if ( ! $this->are_keys_set()) { |
|
502 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | |
506 | 506 | // If no SSL bail. |
507 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
508 | - WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
507 | + if ( ! $this->testmode && ! is_ssl()) { |
|
508 | + WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
509 | 509 | return; |
510 | 510 | } |
511 | 511 | |
512 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
512 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
516 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
516 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
517 | 517 | return; |
518 | 518 | } |
519 | 519 | |
520 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
520 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
521 | 521 | |
522 | 522 | $stripe_params = array( |
523 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
523 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
524 | 524 | 'stripe' => array( |
525 | 525 | 'key' => $this->publishable_key, |
526 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
526 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
527 | 527 | ), |
528 | 528 | 'nonce' => array( |
529 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
530 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
531 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
532 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
533 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
534 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
535 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
536 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
529 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
530 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
531 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
532 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
533 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
534 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
535 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
536 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
537 | 537 | ), |
538 | 538 | 'i18n' => array( |
539 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
539 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
540 | 540 | /* translators: Do not translate the [option] placeholder */ |
541 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
541 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
542 | 542 | ), |
543 | 543 | 'checkout' => array( |
544 | 544 | 'url' => wc_get_checkout_url(), |
545 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
546 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
545 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
546 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
547 | 547 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
548 | 548 | ), |
549 | 549 | 'button' => array( |
550 | 550 | 'type' => $this->get_button_type(), |
551 | 551 | 'theme' => $this->get_button_theme(), |
552 | 552 | 'height' => $this->get_button_height(), |
553 | - 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US. |
|
553 | + 'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US. |
|
554 | 554 | 'is_custom' => $this->is_custom_button(), |
555 | 555 | 'is_branded' => $this->is_branded_button(), |
556 | 556 | 'css_selector' => $this->custom_button_selector(), |
@@ -560,15 +560,15 @@ discard block |
||
560 | 560 | 'product' => $this->get_product_data(), |
561 | 561 | ); |
562 | 562 | |
563 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
564 | - 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 ); |
|
563 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
564 | + 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); |
|
565 | 565 | |
566 | - wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) ); |
|
566 | + wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params)); |
|
567 | 567 | |
568 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
568 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
569 | 569 | |
570 | 570 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
571 | - if ( isset( $gateways['stripe'] ) ) { |
|
571 | + if (isset($gateways['stripe'])) { |
|
572 | 572 | $gateways['stripe']->payment_scripts(); |
573 | 573 | } |
574 | 574 | } |
@@ -584,23 +584,23 @@ discard block |
||
584 | 584 | |
585 | 585 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
586 | 586 | |
587 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
587 | + if ( ! isset($gateways['stripe'])) { |
|
588 | 588 | return; |
589 | 589 | } |
590 | 590 | |
591 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
591 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
592 | 592 | return; |
593 | 593 | } |
594 | 594 | |
595 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
595 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
596 | 596 | return; |
597 | 597 | } |
598 | 598 | |
599 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
599 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
600 | 600 | return; |
601 | 601 | } else { |
602 | - if ( ! $this->allowed_items_in_cart() ) { |
|
603 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
602 | + if ( ! $this->allowed_items_in_cart()) { |
|
603 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
604 | 604 | return; |
605 | 605 | } |
606 | 606 | } |
@@ -608,10 +608,10 @@ discard block |
||
608 | 608 | <div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;display:none;"> |
609 | 609 | <div id="wc-stripe-payment-request-button"> |
610 | 610 | <?php |
611 | - if ( $this->is_custom_button() ) { |
|
612 | - $label = esc_html( $this->get_button_label() ); |
|
613 | - $class_name = esc_attr( 'button ' . $this->get_button_theme() ); |
|
614 | - $style = esc_attr( 'height:' . $this->get_button_height() . 'px;' ); |
|
611 | + if ($this->is_custom_button()) { |
|
612 | + $label = esc_html($this->get_button_label()); |
|
613 | + $class_name = esc_attr('button ' . $this->get_button_theme()); |
|
614 | + $style = esc_attr('height:' . $this->get_button_height() . 'px;'); |
|
615 | 615 | echo "<button id=\"wc-stripe-custom-button\" class=\"$class_name\" style=\"$style\"> $label </button>"; |
616 | 616 | } |
617 | 617 | ?> |
@@ -632,28 +632,28 @@ discard block |
||
632 | 632 | |
633 | 633 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
634 | 634 | |
635 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
635 | + if ( ! isset($gateways['stripe'])) { |
|
636 | 636 | return; |
637 | 637 | } |
638 | 638 | |
639 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
639 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
640 | 640 | return; |
641 | 641 | } |
642 | 642 | |
643 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
643 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
644 | 644 | return; |
645 | 645 | } |
646 | 646 | |
647 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
647 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
648 | 648 | return; |
649 | 649 | } else { |
650 | - if ( ! $this->allowed_items_in_cart() ) { |
|
651 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
650 | + if ( ! $this->allowed_items_in_cart()) { |
|
651 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
652 | 652 | return; |
653 | 653 | } |
654 | 654 | } |
655 | 655 | ?> |
656 | - <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> |
|
656 | + <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> |
|
657 | 657 | <?php |
658 | 658 | } |
659 | 659 | |
@@ -669,32 +669,32 @@ discard block |
||
669 | 669 | private function should_show_payment_button_on_product_page() { |
670 | 670 | global $post; |
671 | 671 | |
672 | - $product = wc_get_product( $post->ID ); |
|
672 | + $product = wc_get_product($post->ID); |
|
673 | 673 | |
674 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
674 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
675 | 675 | return false; |
676 | 676 | } |
677 | 677 | |
678 | - if ( ! is_object( $product ) || ! in_array( $product->get_type(), $this->supported_product_types() ) ) { |
|
678 | + if ( ! is_object($product) || ! in_array($product->get_type(), $this->supported_product_types())) { |
|
679 | 679 | return false; |
680 | 680 | } |
681 | 681 | |
682 | 682 | // Trial subscriptions with shipping are not supported |
683 | - if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) { |
|
683 | + if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) { |
|
684 | 684 | return false; |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Pre Orders charge upon release not supported. |
688 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
689 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
688 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
689 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
690 | 690 | return false; |
691 | 691 | } |
692 | 692 | |
693 | 693 | // File upload addon not supported |
694 | - if ( class_exists( 'WC_Product_Addons_Helper' ) ) { |
|
695 | - $product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() ); |
|
696 | - foreach ( $product_addons as $addon ) { |
|
697 | - if ( 'file_upload' === $addon['type'] ) { |
|
694 | + if (class_exists('WC_Product_Addons_Helper')) { |
|
695 | + $product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id()); |
|
696 | + foreach ($product_addons as $addon) { |
|
697 | + if ('file_upload' === $addon['type']) { |
|
698 | 698 | return false; |
699 | 699 | } |
700 | 700 | } |
@@ -710,11 +710,11 @@ discard block |
||
710 | 710 | * @version 4.0.0 |
711 | 711 | */ |
712 | 712 | public function ajax_log_errors() { |
713 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
713 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
714 | 714 | |
715 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
715 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
716 | 716 | |
717 | - WC_Stripe_Logger::log( $errors ); |
|
717 | + WC_Stripe_Logger::log($errors); |
|
718 | 718 | |
719 | 719 | exit; |
720 | 720 | } |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | * @version 4.0.0 |
727 | 727 | */ |
728 | 728 | public function ajax_clear_cart() { |
729 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
729 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
730 | 730 | |
731 | 731 | WC()->cart->empty_cart(); |
732 | 732 | exit; |
@@ -736,10 +736,10 @@ discard block |
||
736 | 736 | * Get cart details. |
737 | 737 | */ |
738 | 738 | public function ajax_get_cart_details() { |
739 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
739 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
740 | 740 | |
741 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
742 | - define( 'WOOCOMMERCE_CART', true ); |
|
741 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
742 | + define('WOOCOMMERCE_CART', true); |
|
743 | 743 | } |
744 | 744 | |
745 | 745 | WC()->cart->calculate_totals(); |
@@ -750,14 +750,14 @@ discard block |
||
750 | 750 | $data = array( |
751 | 751 | 'shipping_required' => WC()->cart->needs_shipping(), |
752 | 752 | 'order_data' => array( |
753 | - 'currency' => strtolower( $currency ), |
|
754 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
753 | + 'currency' => strtolower($currency), |
|
754 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
755 | 755 | ), |
756 | 756 | ); |
757 | 757 | |
758 | 758 | $data['order_data'] += $this->build_display_items(); |
759 | 759 | |
760 | - wp_send_json( $data ); |
|
760 | + wp_send_json($data); |
|
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | * @see WC_Shipping::get_packages(). |
769 | 769 | */ |
770 | 770 | public function ajax_get_shipping_options() { |
771 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
771 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
772 | 772 | |
773 | 773 | $shipping_address = filter_input_array( |
774 | 774 | INPUT_POST, |
@@ -782,8 +782,8 @@ discard block |
||
782 | 782 | ) |
783 | 783 | ); |
784 | 784 | |
785 | - $data = $this->get_shipping_options( $shipping_address ); |
|
786 | - wp_send_json( $data ); |
|
785 | + $data = $this->get_shipping_options($shipping_address); |
|
786 | + wp_send_json($data); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -794,65 +794,65 @@ discard block |
||
794 | 794 | * @return array Shipping options data. |
795 | 795 | * phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag |
796 | 796 | */ |
797 | - public function get_shipping_options( $shipping_address ) { |
|
797 | + public function get_shipping_options($shipping_address) { |
|
798 | 798 | try { |
799 | 799 | // Set the shipping options. |
800 | 800 | $data = array(); |
801 | 801 | |
802 | 802 | // Remember current shipping method before resetting. |
803 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
804 | - $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $shipping_address ) ); |
|
803 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
804 | + $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $shipping_address)); |
|
805 | 805 | |
806 | 806 | $packages = WC()->shipping->get_packages(); |
807 | 807 | |
808 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
809 | - foreach ( $packages as $package_key => $package ) { |
|
810 | - if ( empty( $package['rates'] ) ) { |
|
811 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
808 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
809 | + foreach ($packages as $package_key => $package) { |
|
810 | + if (empty($package['rates'])) { |
|
811 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
812 | 812 | } |
813 | 813 | |
814 | - foreach ( $package['rates'] as $key => $rate ) { |
|
814 | + foreach ($package['rates'] as $key => $rate) { |
|
815 | 815 | $data['shipping_options'][] = array( |
816 | 816 | 'id' => $rate->id, |
817 | 817 | 'label' => $rate->label, |
818 | 818 | 'detail' => '', |
819 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
819 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
820 | 820 | ); |
821 | 821 | } |
822 | 822 | } |
823 | 823 | } else { |
824 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
824 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | // The first shipping option is automatically applied on the client. |
828 | 828 | // Keep chosen shipping method by sorting shipping options if the method still available for new address. |
829 | 829 | // Fallback to the first available shipping method. |
830 | - if ( isset( $data['shipping_options'][0] ) ) { |
|
831 | - if ( isset( $chosen_shipping_methods[0] ) ) { |
|
830 | + if (isset($data['shipping_options'][0])) { |
|
831 | + if (isset($chosen_shipping_methods[0])) { |
|
832 | 832 | $chosen_method_id = $chosen_shipping_methods[0]; |
833 | - $compare_shipping_options = function ( $a, $b ) use ( $chosen_method_id ) { |
|
834 | - if ( $a['id'] === $chosen_method_id ) { |
|
833 | + $compare_shipping_options = function($a, $b) use ($chosen_method_id) { |
|
834 | + if ($a['id'] === $chosen_method_id) { |
|
835 | 835 | return -1; |
836 | 836 | } |
837 | 837 | |
838 | - if ( $b['id'] === $chosen_method_id ) { |
|
838 | + if ($b['id'] === $chosen_method_id) { |
|
839 | 839 | return 1; |
840 | 840 | } |
841 | 841 | |
842 | 842 | return 0; |
843 | 843 | }; |
844 | - usort( $data['shipping_options'], $compare_shipping_options ); |
|
844 | + usort($data['shipping_options'], $compare_shipping_options); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | $first_shipping_method_id = $data['shipping_options'][0]['id']; |
848 | - $this->update_shipping_method( [ $first_shipping_method_id ] ); |
|
848 | + $this->update_shipping_method([$first_shipping_method_id]); |
|
849 | 849 | } |
850 | 850 | |
851 | 851 | WC()->cart->calculate_totals(); |
852 | 852 | |
853 | 853 | $data += $this->build_display_items(); |
854 | 854 | $data['result'] = 'success'; |
855 | - } catch ( Exception $e ) { |
|
855 | + } catch (Exception $e) { |
|
856 | 856 | $data += $this->build_display_items(); |
857 | 857 | $data['result'] = 'invalid_shipping_address'; |
858 | 858 | } |
@@ -864,14 +864,14 @@ discard block |
||
864 | 864 | * Update shipping method. |
865 | 865 | */ |
866 | 866 | public function ajax_update_shipping_method() { |
867 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
867 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
868 | 868 | |
869 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
870 | - define( 'WOOCOMMERCE_CART', true ); |
|
869 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
870 | + define('WOOCOMMERCE_CART', true); |
|
871 | 871 | } |
872 | 872 | |
873 | - $shipping_methods = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
874 | - $this->update_shipping_method( $shipping_methods ); |
|
873 | + $shipping_methods = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
874 | + $this->update_shipping_method($shipping_methods); |
|
875 | 875 | |
876 | 876 | WC()->cart->calculate_totals(); |
877 | 877 | |
@@ -879,7 +879,7 @@ discard block |
||
879 | 879 | $data += $this->build_display_items(); |
880 | 880 | $data['result'] = 'success'; |
881 | 881 | |
882 | - wp_send_json( $data ); |
|
882 | + wp_send_json($data); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -887,16 +887,16 @@ discard block |
||
887 | 887 | * |
888 | 888 | * @param array $shipping_methods Array of selected shipping methods ids. |
889 | 889 | */ |
890 | - public function update_shipping_method( $shipping_methods ) { |
|
891 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
890 | + public function update_shipping_method($shipping_methods) { |
|
891 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
892 | 892 | |
893 | - if ( is_array( $shipping_methods ) ) { |
|
894 | - foreach ( $shipping_methods as $i => $value ) { |
|
895 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
893 | + if (is_array($shipping_methods)) { |
|
894 | + foreach ($shipping_methods as $i => $value) { |
|
895 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
896 | 896 | } |
897 | 897 | } |
898 | 898 | |
899 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
899 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | /** |
@@ -907,38 +907,38 @@ discard block |
||
907 | 907 | * @return array $data |
908 | 908 | */ |
909 | 909 | public function ajax_get_selected_product_data() { |
910 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
910 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
911 | 911 | |
912 | 912 | try { |
913 | - $product_id = absint( $_POST['product_id'] ); |
|
914 | - $qty = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id ); |
|
915 | - $addon_value = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0; |
|
916 | - $product = wc_get_product( $product_id ); |
|
913 | + $product_id = absint($_POST['product_id']); |
|
914 | + $qty = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id); |
|
915 | + $addon_value = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0; |
|
916 | + $product = wc_get_product($product_id); |
|
917 | 917 | $variation_id = null; |
918 | 918 | |
919 | - if ( ! is_a( $product, 'WC_Product' ) ) { |
|
920 | - throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); |
|
919 | + if ( ! is_a($product, 'WC_Product')) { |
|
920 | + throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id)); |
|
921 | 921 | } |
922 | 922 | |
923 | - if ( 'variable' === $product->get_type() && isset( $_POST['attributes'] ) ) { |
|
924 | - $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
923 | + if ('variable' === $product->get_type() && isset($_POST['attributes'])) { |
|
924 | + $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
925 | 925 | |
926 | - $data_store = WC_Data_Store::load( 'product' ); |
|
927 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
926 | + $data_store = WC_Data_Store::load('product'); |
|
927 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
928 | 928 | |
929 | - if ( ! empty( $variation_id ) ) { |
|
930 | - $product = wc_get_product( $variation_id ); |
|
929 | + if ( ! empty($variation_id)) { |
|
930 | + $product = wc_get_product($variation_id); |
|
931 | 931 | } |
932 | 932 | } |
933 | 933 | |
934 | 934 | // Force quantity to 1 if sold individually and check for existing item in cart. |
935 | - if ( $product->is_sold_individually() ) { |
|
936 | - $qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id ); |
|
935 | + if ($product->is_sold_individually()) { |
|
936 | + $qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id); |
|
937 | 937 | } |
938 | 938 | |
939 | - if ( ! $product->has_enough_stock( $qty ) ) { |
|
939 | + if ( ! $product->has_enough_stock($qty)) { |
|
940 | 940 | /* translators: 1: product name 2: quantity in stock */ |
941 | - 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 ) ) ); |
|
941 | + 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))); |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | $total = $qty * $product->get_price() + $addon_value; |
@@ -950,27 +950,27 @@ discard block |
||
950 | 950 | |
951 | 951 | $items[] = array( |
952 | 952 | 'label' => $product->get_name() . $quantity_label, |
953 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
953 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
954 | 954 | ); |
955 | 955 | |
956 | - if ( wc_tax_enabled() ) { |
|
956 | + if (wc_tax_enabled()) { |
|
957 | 957 | $items[] = array( |
958 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
958 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
959 | 959 | 'amount' => 0, |
960 | 960 | 'pending' => true, |
961 | 961 | ); |
962 | 962 | } |
963 | 963 | |
964 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
964 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
965 | 965 | $items[] = array( |
966 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
966 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
967 | 967 | 'amount' => 0, |
968 | 968 | 'pending' => true, |
969 | 969 | ); |
970 | 970 | |
971 | 971 | $data['shippingOptions'] = array( |
972 | 972 | 'id' => 'pending', |
973 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
973 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
974 | 974 | 'detail' => '', |
975 | 975 | 'amount' => 0, |
976 | 976 | ); |
@@ -979,17 +979,17 @@ discard block |
||
979 | 979 | $data['displayItems'] = $items; |
980 | 980 | $data['total'] = array( |
981 | 981 | 'label' => $this->total_label, |
982 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
982 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
983 | 983 | 'pending' => true, |
984 | 984 | ); |
985 | 985 | |
986 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
987 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
988 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
986 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
987 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
988 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
989 | 989 | |
990 | - wp_send_json( $data ); |
|
991 | - } catch ( Exception $e ) { |
|
992 | - wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) ); |
|
990 | + wp_send_json($data); |
|
991 | + } catch (Exception $e) { |
|
992 | + wp_send_json(array('error' => wp_strip_all_tags($e->getMessage()))); |
|
993 | 993 | } |
994 | 994 | } |
995 | 995 | |
@@ -1001,33 +1001,33 @@ discard block |
||
1001 | 1001 | * @return array $data |
1002 | 1002 | */ |
1003 | 1003 | public function ajax_add_to_cart() { |
1004 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
1004 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
1005 | 1005 | |
1006 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1007 | - define( 'WOOCOMMERCE_CART', true ); |
|
1006 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1007 | + define('WOOCOMMERCE_CART', true); |
|
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | WC()->shipping->reset_shipping(); |
1011 | 1011 | |
1012 | - $product_id = absint( $_POST['product_id'] ); |
|
1013 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
1014 | - $product = wc_get_product( $product_id ); |
|
1012 | + $product_id = absint($_POST['product_id']); |
|
1013 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
1014 | + $product = wc_get_product($product_id); |
|
1015 | 1015 | $product_type = $product->get_type(); |
1016 | 1016 | |
1017 | 1017 | // First empty the cart to prevent wrong calculation. |
1018 | 1018 | WC()->cart->empty_cart(); |
1019 | 1019 | |
1020 | - if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { |
|
1021 | - $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
1020 | + if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) { |
|
1021 | + $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
1022 | 1022 | |
1023 | - $data_store = WC_Data_Store::load( 'product' ); |
|
1024 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
1023 | + $data_store = WC_Data_Store::load('product'); |
|
1024 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
1025 | 1025 | |
1026 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
1026 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | - if ( 'simple' === $product_type || 'subscription' === $product_type ) { |
|
1030 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
1029 | + if ('simple' === $product_type || 'subscription' === $product_type) { |
|
1030 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | WC()->cart->calculate_totals(); |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | $data += $this->build_display_items(); |
1037 | 1037 | $data['result'] = 'success'; |
1038 | 1038 | |
1039 | - wp_send_json( $data ); |
|
1039 | + wp_send_json($data); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | /** |
@@ -1049,31 +1049,31 @@ discard block |
||
1049 | 1049 | * @version 4.0.0 |
1050 | 1050 | */ |
1051 | 1051 | public function normalize_state() { |
1052 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
1053 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
1054 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
1055 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
1052 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
1053 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
1054 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
1055 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
1056 | 1056 | |
1057 | - if ( $billing_state && $billing_country ) { |
|
1058 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
1057 | + if ($billing_state && $billing_country) { |
|
1058 | + $valid_states = WC()->countries->get_states($billing_country); |
|
1059 | 1059 | |
1060 | 1060 | // Valid states found for country. |
1061 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
1062 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
1063 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
1061 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
1062 | + foreach ($valid_states as $state_abbr => $state) { |
|
1063 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
1064 | 1064 | $_POST['billing_state'] = $state_abbr; |
1065 | 1065 | } |
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | } |
1069 | 1069 | |
1070 | - if ( $shipping_state && $shipping_country ) { |
|
1071 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
1070 | + if ($shipping_state && $shipping_country) { |
|
1071 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
1072 | 1072 | |
1073 | 1073 | // Valid states found for country. |
1074 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
1075 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
1076 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
1074 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
1075 | + foreach ($valid_states as $state_abbr => $state) { |
|
1076 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
1077 | 1077 | $_POST['shipping_state'] = $state_abbr; |
1078 | 1078 | } |
1079 | 1079 | } |
@@ -1088,19 +1088,19 @@ discard block |
||
1088 | 1088 | * @version 4.0.0 |
1089 | 1089 | */ |
1090 | 1090 | public function ajax_create_order() { |
1091 | - if ( WC()->cart->is_empty() ) { |
|
1092 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
1091 | + if (WC()->cart->is_empty()) { |
|
1092 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
1096 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
1095 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
1096 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
1097 | 1097 | } |
1098 | 1098 | |
1099 | 1099 | $this->normalize_state(); |
1100 | 1100 | |
1101 | 1101 | WC()->checkout()->process_checkout(); |
1102 | 1102 | |
1103 | - die( 0 ); |
|
1103 | + die(0); |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | /** |
@@ -1110,38 +1110,38 @@ discard block |
||
1110 | 1110 | * @version 4.0.0 |
1111 | 1111 | * @param array $address |
1112 | 1112 | */ |
1113 | - protected function calculate_shipping( $address = array() ) { |
|
1113 | + protected function calculate_shipping($address = array()) { |
|
1114 | 1114 | $country = $address['country']; |
1115 | 1115 | $state = $address['state']; |
1116 | 1116 | $postcode = $address['postcode']; |
1117 | 1117 | $city = $address['city']; |
1118 | 1118 | $address_1 = $address['address']; |
1119 | 1119 | $address_2 = $address['address_2']; |
1120 | - $wc_states = WC()->countries->get_states( $country ); |
|
1120 | + $wc_states = WC()->countries->get_states($country); |
|
1121 | 1121 | |
1122 | 1122 | /** |
1123 | 1123 | * In some versions of Chrome, state can be a full name. So we need |
1124 | 1124 | * to convert that to abbreviation as WC is expecting that. |
1125 | 1125 | */ |
1126 | - if ( 2 < strlen( $state ) && ! empty( $wc_states ) && ! isset( $wc_states[ $state ] ) ) { |
|
1127 | - $state = array_search( ucwords( strtolower( $state ) ), $wc_states, true ); |
|
1126 | + if (2 < strlen($state) && ! empty($wc_states) && ! isset($wc_states[$state])) { |
|
1127 | + $state = array_search(ucwords(strtolower($state)), $wc_states, true); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | WC()->shipping->reset_shipping(); |
1131 | 1131 | |
1132 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
1133 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
1132 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
1133 | + $postcode = wc_format_postcode($postcode, $country); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | - if ( $country ) { |
|
1137 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1138 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
1136 | + if ($country) { |
|
1137 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
1138 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1139 | 1139 | } else { |
1140 | 1140 | WC()->customer->set_billing_address_to_base(); |
1141 | 1141 | WC()->customer->set_shipping_address_to_base(); |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - WC()->customer->set_calculated_shipping( true ); |
|
1144 | + WC()->customer->set_calculated_shipping(true); |
|
1145 | 1145 | WC()->customer->save(); |
1146 | 1146 | |
1147 | 1147 | $packages = array(); |
@@ -1157,17 +1157,17 @@ discard block |
||
1157 | 1157 | $packages[0]['destination']['address'] = $address_1; |
1158 | 1158 | $packages[0]['destination']['address_2'] = $address_2; |
1159 | 1159 | |
1160 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1161 | - if ( $item['data']->needs_shipping() ) { |
|
1162 | - if ( isset( $item['line_total'] ) ) { |
|
1160 | + foreach (WC()->cart->get_cart() as $item) { |
|
1161 | + if ($item['data']->needs_shipping()) { |
|
1162 | + if (isset($item['line_total'])) { |
|
1163 | 1163 | $packages[0]['contents_cost'] += $item['line_total']; |
1164 | 1164 | } |
1165 | 1165 | } |
1166 | 1166 | } |
1167 | 1167 | |
1168 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1168 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1169 | 1169 | |
1170 | - WC()->shipping->calculate_shipping( $packages ); |
|
1170 | + WC()->shipping->calculate_shipping($packages); |
|
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | /** |
@@ -1176,19 +1176,19 @@ discard block |
||
1176 | 1176 | * @since 3.1.0 |
1177 | 1177 | * @version 4.0.0 |
1178 | 1178 | */ |
1179 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1180 | - if ( empty( $shipping_methods ) ) { |
|
1179 | + protected function build_shipping_methods($shipping_methods) { |
|
1180 | + if (empty($shipping_methods)) { |
|
1181 | 1181 | return array(); |
1182 | 1182 | } |
1183 | 1183 | |
1184 | 1184 | $shipping = array(); |
1185 | 1185 | |
1186 | - foreach ( $shipping_methods as $method ) { |
|
1186 | + foreach ($shipping_methods as $method) { |
|
1187 | 1187 | $shipping[] = array( |
1188 | 1188 | 'id' => $method['id'], |
1189 | 1189 | 'label' => $method['label'], |
1190 | 1190 | 'detail' => '', |
1191 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1191 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1192 | 1192 | ); |
1193 | 1193 | } |
1194 | 1194 | |
@@ -1202,8 +1202,8 @@ discard block |
||
1202 | 1202 | * @version 4.0.0 |
1203 | 1203 | */ |
1204 | 1204 | protected function build_display_items() { |
1205 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1206 | - define( 'WOOCOMMERCE_CART', true ); |
|
1205 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1206 | + define('WOOCOMMERCE_CART', true); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | $items = array(); |
@@ -1211,8 +1211,8 @@ discard block |
||
1211 | 1211 | $discounts = 0; |
1212 | 1212 | |
1213 | 1213 | // Default show only subtotal instead of itemization. |
1214 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1215 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1214 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1215 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1216 | 1216 | $amount = $cart_item['line_subtotal']; |
1217 | 1217 | $subtotal += $cart_item['line_subtotal']; |
1218 | 1218 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
@@ -1221,61 +1221,61 @@ discard block |
||
1221 | 1221 | |
1222 | 1222 | $item = array( |
1223 | 1223 | 'label' => $product_name . $quantity_label, |
1224 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1224 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1225 | 1225 | ); |
1226 | 1226 | |
1227 | 1227 | $items[] = $item; |
1228 | 1228 | } |
1229 | 1229 | } |
1230 | 1230 | |
1231 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1232 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1231 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1232 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1233 | 1233 | } else { |
1234 | - $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
1234 | + $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
1235 | 1235 | |
1236 | - foreach ( $applied_coupons as $amount ) { |
|
1236 | + foreach ($applied_coupons as $amount) { |
|
1237 | 1237 | $discounts += (float) $amount; |
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | |
1241 | - $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
1242 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1243 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1244 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1245 | - $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
1241 | + $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
1242 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1243 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1244 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1245 | + $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 | 1246 | |
1247 | - if ( wc_tax_enabled() ) { |
|
1247 | + if (wc_tax_enabled()) { |
|
1248 | 1248 | $items[] = array( |
1249 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1250 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1249 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1250 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1251 | 1251 | ); |
1252 | 1252 | } |
1253 | 1253 | |
1254 | - if ( WC()->cart->needs_shipping() ) { |
|
1254 | + if (WC()->cart->needs_shipping()) { |
|
1255 | 1255 | $items[] = array( |
1256 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1257 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1256 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1257 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1258 | 1258 | ); |
1259 | 1259 | } |
1260 | 1260 | |
1261 | - if ( WC()->cart->has_discount() ) { |
|
1261 | + if (WC()->cart->has_discount()) { |
|
1262 | 1262 | $items[] = array( |
1263 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1264 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1263 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1264 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1265 | 1265 | ); |
1266 | 1266 | } |
1267 | 1267 | |
1268 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1268 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1269 | 1269 | $cart_fees = WC()->cart->fees; |
1270 | 1270 | } else { |
1271 | 1271 | $cart_fees = WC()->cart->get_fees(); |
1272 | 1272 | } |
1273 | 1273 | |
1274 | 1274 | // Include fees and taxes as display items. |
1275 | - foreach ( $cart_fees as $key => $fee ) { |
|
1275 | + foreach ($cart_fees as $key => $fee) { |
|
1276 | 1276 | $items[] = array( |
1277 | 1277 | 'label' => $fee->name, |
1278 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1278 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1279 | 1279 | ); |
1280 | 1280 | } |
1281 | 1281 | |
@@ -1283,7 +1283,7 @@ discard block |
||
1283 | 1283 | 'displayItems' => $items, |
1284 | 1284 | 'total' => array( |
1285 | 1285 | 'label' => $this->total_label, |
1286 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1286 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1287 | 1287 | 'pending' => false, |
1288 | 1288 | ), |
1289 | 1289 | ); |