@@ -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 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | 252 | public function get_button_label() { |
| 253 | - return isset( $this->stripe_settings['payment_request_button_label'] ) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now'; |
|
| 253 | + return isset($this->stripe_settings['payment_request_button_label']) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now'; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -260,22 +260,22 @@ discard block |
||
| 260 | 260 | * @version 4.0.0 |
| 261 | 261 | */ |
| 262 | 262 | public function get_product_data() { |
| 263 | - if ( ! is_product() ) { |
|
| 263 | + if ( ! is_product()) { |
|
| 264 | 264 | return false; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | global $post; |
| 268 | 268 | |
| 269 | - $product = wc_get_product( $post->ID ); |
|
| 269 | + $product = wc_get_product($post->ID); |
|
| 270 | 270 | |
| 271 | - if ( 'variable' === $product->get_type() ) { |
|
| 272 | - $attributes = wc_clean( wp_unslash( $_GET ) ); |
|
| 271 | + if ('variable' === $product->get_type()) { |
|
| 272 | + $attributes = wc_clean(wp_unslash($_GET)); |
|
| 273 | 273 | |
| 274 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 275 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 274 | + $data_store = WC_Data_Store::load('product'); |
|
| 275 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 276 | 276 | |
| 277 | - if ( ! empty( $variation_id ) ) { |
|
| 278 | - $product = wc_get_product( $variation_id ); |
|
| 277 | + if ( ! empty($variation_id)) { |
|
| 278 | + $product = wc_get_product($variation_id); |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | |
@@ -284,27 +284,27 @@ discard block |
||
| 284 | 284 | |
| 285 | 285 | $items[] = array( |
| 286 | 286 | 'label' => $product->get_name(), |
| 287 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ), |
|
| 287 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($product->get_price()), |
|
| 288 | 288 | ); |
| 289 | 289 | |
| 290 | - if ( wc_tax_enabled() ) { |
|
| 290 | + if (wc_tax_enabled()) { |
|
| 291 | 291 | $items[] = array( |
| 292 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 292 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 293 | 293 | 'amount' => 0, |
| 294 | 294 | 'pending' => true, |
| 295 | 295 | ); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 298 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 299 | 299 | $items[] = array( |
| 300 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 300 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 301 | 301 | 'amount' => 0, |
| 302 | 302 | 'pending' => true, |
| 303 | 303 | ); |
| 304 | 304 | |
| 305 | 305 | $data['shippingOptions'] = array( |
| 306 | 306 | 'id' => 'pending', |
| 307 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 307 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 308 | 308 | 'detail' => '', |
| 309 | 309 | 'amount' => 0, |
| 310 | 310 | ); |
@@ -312,37 +312,37 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | $data['displayItems'] = $items; |
| 314 | 314 | $data['total'] = array( |
| 315 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
| 316 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ), |
|
| 315 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
| 316 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($product->get_price()), |
|
| 317 | 317 | 'pending' => true, |
| 318 | 318 | ); |
| 319 | 319 | |
| 320 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 321 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 322 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 320 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 321 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 322 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 323 | 323 | |
| 324 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
| 324 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
| 328 | 328 | * Filters the gateway title to reflect Payment Request type |
| 329 | 329 | * |
| 330 | 330 | */ |
| 331 | - public function filter_gateway_title( $title, $id ) { |
|
| 331 | + public function filter_gateway_title($title, $id) { |
|
| 332 | 332 | global $post; |
| 333 | 333 | |
| 334 | - if ( ! is_object( $post ) ) { |
|
| 334 | + if ( ! is_object($post)) { |
|
| 335 | 335 | return $title; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - $order = wc_get_order( $post->ID ); |
|
| 339 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
| 338 | + $order = wc_get_order($post->ID); |
|
| 339 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
| 340 | 340 | |
| 341 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
| 341 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
| 342 | 342 | return $method_title; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
| 345 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
| 346 | 346 | return $method_title; |
| 347 | 347 | } |
| 348 | 348 | |
@@ -355,16 +355,16 @@ discard block |
||
| 355 | 355 | * @since 3.1.4 |
| 356 | 356 | * @version 4.0.0 |
| 357 | 357 | */ |
| 358 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 358 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 359 | 359 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 360 | 360 | |
| 361 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 361 | + if ( ! isset($gateways['stripe'])) { |
|
| 362 | 362 | return $valid; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
| 365 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
| 366 | 366 | |
| 367 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
| 367 | + if ('apple_pay' !== $payment_request_type) { |
|
| 368 | 368 | return $valid; |
| 369 | 369 | } |
| 370 | 370 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 375 | 375 | * Note that this only works with shipping providers that don't validate full postal codes. |
| 376 | 376 | */ |
| 377 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 377 | + if ('GB' === $country || 'CA' === $country) { |
|
| 378 | 378 | return true; |
| 379 | 379 | } |
| 380 | 380 | |
@@ -389,22 +389,22 @@ discard block |
||
| 389 | 389 | * @param int $order_id |
| 390 | 390 | * @param array $posted_data The posted data from checkout form. |
| 391 | 391 | */ |
| 392 | - public function add_order_meta( $order_id, $posted_data ) { |
|
| 393 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
| 392 | + public function add_order_meta($order_id, $posted_data) { |
|
| 393 | + if (empty($_POST['payment_request_type'])) { |
|
| 394 | 394 | return; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - $order = wc_get_order( $order_id ); |
|
| 397 | + $order = wc_get_order($order_id); |
|
| 398 | 398 | |
| 399 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
| 399 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
| 400 | 400 | |
| 401 | - if ( 'apple_pay' === $payment_request_type ) { |
|
| 402 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
| 401 | + if ('apple_pay' === $payment_request_type) { |
|
| 402 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
| 403 | 403 | $order->save(); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
| 407 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
| 406 | + if ('payment_request_api' === $payment_request_type) { |
|
| 407 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
| 408 | 408 | $order->save(); |
| 409 | 409 | } |
| 410 | 410 | } |
@@ -442,20 +442,20 @@ discard block |
||
| 442 | 442 | * @return bool |
| 443 | 443 | */ |
| 444 | 444 | public function allowed_items_in_cart() { |
| 445 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 446 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
| 445 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 446 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
| 447 | 447 | |
| 448 | - if ( ! in_array( $_product->get_type(), $this->supported_product_types() ) ) { |
|
| 448 | + if ( ! in_array($_product->get_type(), $this->supported_product_types())) { |
|
| 449 | 449 | return false; |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | // Trial subscriptions with shipping are not supported |
| 453 | - if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) { |
|
| 453 | + if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) { |
|
| 454 | 454 | return false; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // Pre Orders compatbility where we don't support charge upon release. |
| 458 | - 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() ) ) { |
|
| 458 | + 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())) { |
|
| 459 | 459 | return false; |
| 460 | 460 | } |
| 461 | 461 | } |
@@ -471,59 +471,59 @@ discard block |
||
| 471 | 471 | */ |
| 472 | 472 | public function scripts() { |
| 473 | 473 | // If keys are not set bail. |
| 474 | - if ( ! $this->are_keys_set() ) { |
|
| 475 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
| 474 | + if ( ! $this->are_keys_set()) { |
|
| 475 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
| 476 | 476 | return; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | // If no SSL bail. |
| 480 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
| 481 | - WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
| 480 | + if ( ! $this->testmode && ! is_ssl()) { |
|
| 481 | + WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
| 482 | 482 | return; |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 485 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 486 | 486 | return; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
| 489 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
| 490 | 490 | return; |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 493 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 494 | 494 | |
| 495 | 495 | $stripe_params = array( |
| 496 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 496 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 497 | 497 | 'stripe' => array( |
| 498 | 498 | 'key' => $this->publishable_key, |
| 499 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
| 499 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
| 500 | 500 | ), |
| 501 | 501 | 'nonce' => array( |
| 502 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
| 503 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
| 504 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
| 505 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
| 506 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
| 507 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
| 508 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
| 509 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
| 502 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
| 503 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
| 504 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
| 505 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
| 506 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
| 507 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
| 508 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
| 509 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
| 510 | 510 | ), |
| 511 | 511 | 'i18n' => array( |
| 512 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
| 512 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
| 513 | 513 | /* translators: Do not translate the [option] placeholder */ |
| 514 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
| 514 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
| 515 | 515 | ), |
| 516 | 516 | 'checkout' => array( |
| 517 | 517 | 'url' => wc_get_checkout_url(), |
| 518 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
| 519 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 518 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
| 519 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 520 | 520 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 521 | 521 | ), |
| 522 | 522 | 'button' => array( |
| 523 | 523 | 'type' => $this->get_button_type(), |
| 524 | 524 | 'theme' => $this->get_button_theme(), |
| 525 | 525 | 'height' => $this->get_button_height(), |
| 526 | - 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US. |
|
| 526 | + 'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US. |
|
| 527 | 527 | 'is_custom' => $this->is_custom_button(), |
| 528 | 528 | 'css_selector' => $this->custom_button_selector(), |
| 529 | 529 | ), |
@@ -531,15 +531,15 @@ discard block |
||
| 531 | 531 | 'product' => $this->get_product_data(), |
| 532 | 532 | ); |
| 533 | 533 | |
| 534 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 535 | - 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 ); |
|
| 534 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 535 | + 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); |
|
| 536 | 536 | |
| 537 | - wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) ); |
|
| 537 | + wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params)); |
|
| 538 | 538 | |
| 539 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
| 539 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
| 540 | 540 | |
| 541 | 541 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 542 | - if ( isset( $gateways['stripe'] ) ) { |
|
| 542 | + if (isset($gateways['stripe'])) { |
|
| 543 | 543 | $gateways['stripe']->payment_scripts(); |
| 544 | 544 | } |
| 545 | 545 | } |
@@ -555,23 +555,23 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 557 | 557 | |
| 558 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 558 | + if ( ! isset($gateways['stripe'])) { |
|
| 559 | 559 | return; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 562 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 563 | 563 | return; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
| 566 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
| 567 | 567 | return; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
| 570 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
| 571 | 571 | return; |
| 572 | 572 | } else { |
| 573 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 574 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 573 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 574 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 575 | 575 | return; |
| 576 | 576 | } |
| 577 | 577 | } |
@@ -579,10 +579,10 @@ discard block |
||
| 579 | 579 | <div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;display:none;"> |
| 580 | 580 | <div id="wc-stripe-payment-request-button"> |
| 581 | 581 | <?php |
| 582 | - if ( $this->is_custom_button() ) { |
|
| 583 | - $label = esc_html( $this->get_button_label() ); |
|
| 584 | - $class_name = esc_attr( 'button ' . $this->get_button_theme() ); |
|
| 585 | - $style = esc_attr( 'height:' . $this->get_button_height() . 'px;' ); |
|
| 582 | + if ($this->is_custom_button()) { |
|
| 583 | + $label = esc_html($this->get_button_label()); |
|
| 584 | + $class_name = esc_attr('button ' . $this->get_button_theme()); |
|
| 585 | + $style = esc_attr('height:' . $this->get_button_height() . 'px;'); |
|
| 586 | 586 | echo "<button id=\"wc-stripe-custom-button\" class=\"$class_name\" style=\"$style\"> $label </button>"; |
| 587 | 587 | } |
| 588 | 588 | ?> |
@@ -603,28 +603,28 @@ discard block |
||
| 603 | 603 | |
| 604 | 604 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 605 | 605 | |
| 606 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 606 | + if ( ! isset($gateways['stripe'])) { |
|
| 607 | 607 | return; |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 610 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 611 | 611 | return; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
| 614 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
| 615 | 615 | return; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
| 618 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
| 619 | 619 | return; |
| 620 | 620 | } else { |
| 621 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 622 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 621 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 622 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 623 | 623 | return; |
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | ?> |
| 627 | - <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> |
|
| 627 | + <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> |
|
| 628 | 628 | <?php |
| 629 | 629 | } |
| 630 | 630 | |
@@ -640,32 +640,32 @@ discard block |
||
| 640 | 640 | private function should_show_payment_button_on_product_page() { |
| 641 | 641 | global $post; |
| 642 | 642 | |
| 643 | - $product = wc_get_product( $post->ID ); |
|
| 643 | + $product = wc_get_product($post->ID); |
|
| 644 | 644 | |
| 645 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
| 645 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
| 646 | 646 | return false; |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - if ( ! is_object( $product ) || ! in_array( $product->get_type(), $this->supported_product_types() ) ) { |
|
| 649 | + if ( ! is_object($product) || ! in_array($product->get_type(), $this->supported_product_types())) { |
|
| 650 | 650 | return false; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | // Trial subscriptions with shipping are not supported |
| 654 | - if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) { |
|
| 654 | + if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) { |
|
| 655 | 655 | return false; |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | // Pre Orders charge upon release not supported. |
| 659 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 660 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 659 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 660 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 661 | 661 | return false; |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | // File upload addon not supported |
| 665 | - if ( class_exists( 'WC_Product_Addons_Helper' ) ) { |
|
| 666 | - $product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() ); |
|
| 667 | - foreach ( $product_addons as $addon ) { |
|
| 668 | - if ( 'file_upload' === $addon['type'] ) { |
|
| 665 | + if (class_exists('WC_Product_Addons_Helper')) { |
|
| 666 | + $product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id()); |
|
| 667 | + foreach ($product_addons as $addon) { |
|
| 668 | + if ('file_upload' === $addon['type']) { |
|
| 669 | 669 | return false; |
| 670 | 670 | } |
| 671 | 671 | } |
@@ -681,11 +681,11 @@ discard block |
||
| 681 | 681 | * @version 4.0.0 |
| 682 | 682 | */ |
| 683 | 683 | public function ajax_log_errors() { |
| 684 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
| 684 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
| 685 | 685 | |
| 686 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
| 686 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
| 687 | 687 | |
| 688 | - WC_Stripe_Logger::log( $errors ); |
|
| 688 | + WC_Stripe_Logger::log($errors); |
|
| 689 | 689 | |
| 690 | 690 | exit; |
| 691 | 691 | } |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | * @version 4.0.0 |
| 698 | 698 | */ |
| 699 | 699 | public function ajax_clear_cart() { |
| 700 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
| 700 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
| 701 | 701 | |
| 702 | 702 | WC()->cart->empty_cart(); |
| 703 | 703 | exit; |
@@ -707,10 +707,10 @@ discard block |
||
| 707 | 707 | * Get cart details. |
| 708 | 708 | */ |
| 709 | 709 | public function ajax_get_cart_details() { |
| 710 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
| 710 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
| 711 | 711 | |
| 712 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 713 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 712 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 713 | + define('WOOCOMMERCE_CART', true); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | WC()->cart->calculate_totals(); |
@@ -721,14 +721,14 @@ discard block |
||
| 721 | 721 | $data = array( |
| 722 | 722 | 'shipping_required' => WC()->cart->needs_shipping(), |
| 723 | 723 | 'order_data' => array( |
| 724 | - 'currency' => strtolower( $currency ), |
|
| 725 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 724 | + 'currency' => strtolower($currency), |
|
| 725 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 726 | 726 | ), |
| 727 | 727 | ); |
| 728 | 728 | |
| 729 | 729 | $data['order_data'] += $this->build_display_items(); |
| 730 | 730 | |
| 731 | - wp_send_json( $data ); |
|
| 731 | + wp_send_json($data); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | * @see WC_Shipping::get_packages(). |
| 740 | 740 | */ |
| 741 | 741 | public function ajax_get_shipping_options() { |
| 742 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
| 742 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
| 743 | 743 | |
| 744 | 744 | try { |
| 745 | 745 | // Set the shipping package. |
@@ -755,34 +755,34 @@ discard block |
||
| 755 | 755 | ) |
| 756 | 756 | ); |
| 757 | 757 | |
| 758 | - $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) ); |
|
| 758 | + $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted)); |
|
| 759 | 759 | |
| 760 | 760 | // Set the shipping options. |
| 761 | 761 | $data = array(); |
| 762 | 762 | $packages = WC()->shipping->get_packages(); |
| 763 | 763 | |
| 764 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 765 | - foreach ( $packages as $package_key => $package ) { |
|
| 766 | - if ( empty( $package['rates'] ) ) { |
|
| 767 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 764 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 765 | + foreach ($packages as $package_key => $package) { |
|
| 766 | + if (empty($package['rates'])) { |
|
| 767 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 770 | + foreach ($package['rates'] as $key => $rate) { |
|
| 771 | 771 | $data['shipping_options'][] = array( |
| 772 | 772 | 'id' => $rate->id, |
| 773 | 773 | 'label' => $rate->label, |
| 774 | 774 | 'detail' => '', |
| 775 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
| 775 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
| 776 | 776 | ); |
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | } else { |
| 780 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 780 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | - if ( isset( $data[0] ) ) { |
|
| 783 | + if (isset($data[0])) { |
|
| 784 | 784 | // Auto select the first shipping method. |
| 785 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 785 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | WC()->cart->calculate_totals(); |
@@ -790,12 +790,12 @@ discard block |
||
| 790 | 790 | $data += $this->build_display_items(); |
| 791 | 791 | $data['result'] = 'success'; |
| 792 | 792 | |
| 793 | - wp_send_json( $data ); |
|
| 794 | - } catch ( Exception $e ) { |
|
| 793 | + wp_send_json($data); |
|
| 794 | + } catch (Exception $e) { |
|
| 795 | 795 | $data += $this->build_display_items(); |
| 796 | 796 | $data['result'] = 'invalid_shipping_address'; |
| 797 | 797 | |
| 798 | - wp_send_json( $data ); |
|
| 798 | + wp_send_json($data); |
|
| 799 | 799 | } |
| 800 | 800 | } |
| 801 | 801 | |
@@ -803,22 +803,22 @@ discard block |
||
| 803 | 803 | * Update shipping method. |
| 804 | 804 | */ |
| 805 | 805 | public function ajax_update_shipping_method() { |
| 806 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
| 806 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
| 807 | 807 | |
| 808 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 809 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 808 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 809 | + define('WOOCOMMERCE_CART', true); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 813 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 812 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 813 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 814 | 814 | |
| 815 | - if ( is_array( $shipping_method ) ) { |
|
| 816 | - foreach ( $shipping_method as $i => $value ) { |
|
| 817 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
| 815 | + if (is_array($shipping_method)) { |
|
| 816 | + foreach ($shipping_method as $i => $value) { |
|
| 817 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
| 818 | 818 | } |
| 819 | 819 | } |
| 820 | 820 | |
| 821 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
| 821 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
| 822 | 822 | |
| 823 | 823 | WC()->cart->calculate_totals(); |
| 824 | 824 | |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | $data += $this->build_display_items(); |
| 827 | 827 | $data['result'] = 'success'; |
| 828 | 828 | |
| 829 | - wp_send_json( $data ); |
|
| 829 | + wp_send_json($data); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
@@ -837,38 +837,38 @@ discard block |
||
| 837 | 837 | * @return array $data |
| 838 | 838 | */ |
| 839 | 839 | public function ajax_get_selected_product_data() { |
| 840 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
| 840 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
| 841 | 841 | |
| 842 | 842 | try { |
| 843 | - $product_id = absint( $_POST['product_id'] ); |
|
| 844 | - $qty = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id ); |
|
| 845 | - $addon_value = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0; |
|
| 846 | - $product = wc_get_product( $product_id ); |
|
| 843 | + $product_id = absint($_POST['product_id']); |
|
| 844 | + $qty = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id); |
|
| 845 | + $addon_value = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0; |
|
| 846 | + $product = wc_get_product($product_id); |
|
| 847 | 847 | $variation_id = null; |
| 848 | 848 | |
| 849 | - if ( ! is_a( $product, 'WC_Product' ) ) { |
|
| 850 | - throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); |
|
| 849 | + if ( ! is_a($product, 'WC_Product')) { |
|
| 850 | + throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id)); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | - if ( 'variable' === $product->get_type() && isset( $_POST['attributes'] ) ) { |
|
| 854 | - $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
| 853 | + if ('variable' === $product->get_type() && isset($_POST['attributes'])) { |
|
| 854 | + $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
| 855 | 855 | |
| 856 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 857 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 856 | + $data_store = WC_Data_Store::load('product'); |
|
| 857 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 858 | 858 | |
| 859 | - if ( ! empty( $variation_id ) ) { |
|
| 860 | - $product = wc_get_product( $variation_id ); |
|
| 859 | + if ( ! empty($variation_id)) { |
|
| 860 | + $product = wc_get_product($variation_id); |
|
| 861 | 861 | } |
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | // Force quantity to 1 if sold individually and check for existing item in cart. |
| 865 | - if ( $product->is_sold_individually() ) { |
|
| 866 | - $qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id ); |
|
| 865 | + if ($product->is_sold_individually()) { |
|
| 866 | + $qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id); |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | - if ( ! $product->has_enough_stock( $qty ) ) { |
|
| 869 | + if ( ! $product->has_enough_stock($qty)) { |
|
| 870 | 870 | /* translators: 1: product name 2: quantity in stock */ |
| 871 | - 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 ) ) ); |
|
| 871 | + 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))); |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | $total = $qty * $product->get_price() + $addon_value; |
@@ -880,27 +880,27 @@ discard block |
||
| 880 | 880 | |
| 881 | 881 | $items[] = array( |
| 882 | 882 | 'label' => $product->get_name() . $quantity_label, |
| 883 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 883 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 884 | 884 | ); |
| 885 | 885 | |
| 886 | - if ( wc_tax_enabled() ) { |
|
| 886 | + if (wc_tax_enabled()) { |
|
| 887 | 887 | $items[] = array( |
| 888 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 888 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 889 | 889 | 'amount' => 0, |
| 890 | 890 | 'pending' => true, |
| 891 | 891 | ); |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 894 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 895 | 895 | $items[] = array( |
| 896 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 896 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 897 | 897 | 'amount' => 0, |
| 898 | 898 | 'pending' => true, |
| 899 | 899 | ); |
| 900 | 900 | |
| 901 | 901 | $data['shippingOptions'] = array( |
| 902 | 902 | 'id' => 'pending', |
| 903 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 903 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 904 | 904 | 'detail' => '', |
| 905 | 905 | 'amount' => 0, |
| 906 | 906 | ); |
@@ -909,17 +909,17 @@ discard block |
||
| 909 | 909 | $data['displayItems'] = $items; |
| 910 | 910 | $data['total'] = array( |
| 911 | 911 | 'label' => $this->total_label, |
| 912 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 912 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 913 | 913 | 'pending' => true, |
| 914 | 914 | ); |
| 915 | 915 | |
| 916 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 917 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 918 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 916 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 917 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 918 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 919 | 919 | |
| 920 | - wp_send_json( $data ); |
|
| 921 | - } catch ( Exception $e ) { |
|
| 922 | - wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) ); |
|
| 920 | + wp_send_json($data); |
|
| 921 | + } catch (Exception $e) { |
|
| 922 | + wp_send_json(array('error' => wp_strip_all_tags($e->getMessage()))); |
|
| 923 | 923 | } |
| 924 | 924 | } |
| 925 | 925 | |
@@ -931,33 +931,33 @@ discard block |
||
| 931 | 931 | * @return array $data |
| 932 | 932 | */ |
| 933 | 933 | public function ajax_add_to_cart() { |
| 934 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
| 934 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
| 935 | 935 | |
| 936 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 937 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 936 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 937 | + define('WOOCOMMERCE_CART', true); |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | WC()->shipping->reset_shipping(); |
| 941 | 941 | |
| 942 | - $product_id = absint( $_POST['product_id'] ); |
|
| 943 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 944 | - $product = wc_get_product( $product_id ); |
|
| 942 | + $product_id = absint($_POST['product_id']); |
|
| 943 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 944 | + $product = wc_get_product($product_id); |
|
| 945 | 945 | $product_type = $product->get_type(); |
| 946 | 946 | |
| 947 | 947 | // First empty the cart to prevent wrong calculation. |
| 948 | 948 | WC()->cart->empty_cart(); |
| 949 | 949 | |
| 950 | - if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { |
|
| 951 | - $attributes = wc_clean( wp_unslash( $_POST['attributes'] ) ); |
|
| 950 | + if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) { |
|
| 951 | + $attributes = wc_clean(wp_unslash($_POST['attributes'])); |
|
| 952 | 952 | |
| 953 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 954 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 953 | + $data_store = WC_Data_Store::load('product'); |
|
| 954 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 955 | 955 | |
| 956 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 956 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | - if ( 'simple' === $product_type || 'subscription' === $product_type ) { |
|
| 960 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 959 | + if ('simple' === $product_type || 'subscription' === $product_type) { |
|
| 960 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | WC()->cart->calculate_totals(); |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | $data += $this->build_display_items(); |
| 967 | 967 | $data['result'] = 'success'; |
| 968 | 968 | |
| 969 | - wp_send_json( $data ); |
|
| 969 | + wp_send_json($data); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -979,31 +979,31 @@ discard block |
||
| 979 | 979 | * @version 4.0.0 |
| 980 | 980 | */ |
| 981 | 981 | public function normalize_state() { |
| 982 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
| 983 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
| 984 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
| 985 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
| 982 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
| 983 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
| 984 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
| 985 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
| 986 | 986 | |
| 987 | - if ( $billing_state && $billing_country ) { |
|
| 988 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
| 987 | + if ($billing_state && $billing_country) { |
|
| 988 | + $valid_states = WC()->countries->get_states($billing_country); |
|
| 989 | 989 | |
| 990 | 990 | // Valid states found for country. |
| 991 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 992 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 993 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
| 991 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 992 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 993 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
| 994 | 994 | $_POST['billing_state'] = $state_abbr; |
| 995 | 995 | } |
| 996 | 996 | } |
| 997 | 997 | } |
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | - if ( $shipping_state && $shipping_country ) { |
|
| 1001 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
| 1000 | + if ($shipping_state && $shipping_country) { |
|
| 1001 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
| 1002 | 1002 | |
| 1003 | 1003 | // Valid states found for country. |
| 1004 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 1005 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 1006 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
| 1004 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 1005 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 1006 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
| 1007 | 1007 | $_POST['shipping_state'] = $state_abbr; |
| 1008 | 1008 | } |
| 1009 | 1009 | } |
@@ -1018,19 +1018,19 @@ discard block |
||
| 1018 | 1018 | * @version 4.0.0 |
| 1019 | 1019 | */ |
| 1020 | 1020 | public function ajax_create_order() { |
| 1021 | - if ( WC()->cart->is_empty() ) { |
|
| 1022 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
| 1021 | + if (WC()->cart->is_empty()) { |
|
| 1022 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
| 1026 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 1025 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
| 1026 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | $this->normalize_state(); |
| 1030 | 1030 | |
| 1031 | 1031 | WC()->checkout()->process_checkout(); |
| 1032 | 1032 | |
| 1033 | - die( 0 ); |
|
| 1033 | + die(0); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | /** |
@@ -1040,38 +1040,38 @@ discard block |
||
| 1040 | 1040 | * @version 4.0.0 |
| 1041 | 1041 | * @param array $address |
| 1042 | 1042 | */ |
| 1043 | - protected function calculate_shipping( $address = array() ) { |
|
| 1043 | + protected function calculate_shipping($address = array()) { |
|
| 1044 | 1044 | $country = $address['country']; |
| 1045 | 1045 | $state = $address['state']; |
| 1046 | 1046 | $postcode = $address['postcode']; |
| 1047 | 1047 | $city = $address['city']; |
| 1048 | 1048 | $address_1 = $address['address']; |
| 1049 | 1049 | $address_2 = $address['address_2']; |
| 1050 | - $wc_states = WC()->countries->get_states( $country ); |
|
| 1050 | + $wc_states = WC()->countries->get_states($country); |
|
| 1051 | 1051 | |
| 1052 | 1052 | /** |
| 1053 | 1053 | * In some versions of Chrome, state can be a full name. So we need |
| 1054 | 1054 | * to convert that to abbreviation as WC is expecting that. |
| 1055 | 1055 | */ |
| 1056 | - if ( 2 < strlen( $state ) && ! empty( $wc_states ) && ! isset( $wc_states[ $state ] ) ) { |
|
| 1057 | - $state = array_search( ucwords( strtolower( $state ) ), $wc_states, true ); |
|
| 1056 | + if (2 < strlen($state) && ! empty($wc_states) && ! isset($wc_states[$state])) { |
|
| 1057 | + $state = array_search(ucwords(strtolower($state)), $wc_states, true); |
|
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | WC()->shipping->reset_shipping(); |
| 1061 | 1061 | |
| 1062 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 1063 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 1062 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
| 1063 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | - if ( $country ) { |
|
| 1067 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 1068 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 1066 | + if ($country) { |
|
| 1067 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 1068 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 1069 | 1069 | } else { |
| 1070 | 1070 | WC()->customer->set_billing_address_to_base(); |
| 1071 | 1071 | WC()->customer->set_shipping_address_to_base(); |
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | - WC()->customer->set_calculated_shipping( true ); |
|
| 1074 | + WC()->customer->set_calculated_shipping(true); |
|
| 1075 | 1075 | WC()->customer->save(); |
| 1076 | 1076 | |
| 1077 | 1077 | $packages = array(); |
@@ -1087,17 +1087,17 @@ discard block |
||
| 1087 | 1087 | $packages[0]['destination']['address'] = $address_1; |
| 1088 | 1088 | $packages[0]['destination']['address_2'] = $address_2; |
| 1089 | 1089 | |
| 1090 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 1091 | - if ( $item['data']->needs_shipping() ) { |
|
| 1092 | - if ( isset( $item['line_total'] ) ) { |
|
| 1090 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 1091 | + if ($item['data']->needs_shipping()) { |
|
| 1092 | + if (isset($item['line_total'])) { |
|
| 1093 | 1093 | $packages[0]['contents_cost'] += $item['line_total']; |
| 1094 | 1094 | } |
| 1095 | 1095 | } |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 1098 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 1099 | 1099 | |
| 1100 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 1100 | + WC()->shipping->calculate_shipping($packages); |
|
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | /** |
@@ -1106,19 +1106,19 @@ discard block |
||
| 1106 | 1106 | * @since 3.1.0 |
| 1107 | 1107 | * @version 4.0.0 |
| 1108 | 1108 | */ |
| 1109 | - protected function build_shipping_methods( $shipping_methods ) { |
|
| 1110 | - if ( empty( $shipping_methods ) ) { |
|
| 1109 | + protected function build_shipping_methods($shipping_methods) { |
|
| 1110 | + if (empty($shipping_methods)) { |
|
| 1111 | 1111 | return array(); |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | $shipping = array(); |
| 1115 | 1115 | |
| 1116 | - foreach ( $shipping_methods as $method ) { |
|
| 1116 | + foreach ($shipping_methods as $method) { |
|
| 1117 | 1117 | $shipping[] = array( |
| 1118 | 1118 | 'id' => $method['id'], |
| 1119 | 1119 | 'label' => $method['label'], |
| 1120 | 1120 | 'detail' => '', |
| 1121 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
| 1121 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
| 1122 | 1122 | ); |
| 1123 | 1123 | } |
| 1124 | 1124 | |
@@ -1132,8 +1132,8 @@ discard block |
||
| 1132 | 1132 | * @version 4.0.0 |
| 1133 | 1133 | */ |
| 1134 | 1134 | protected function build_display_items() { |
| 1135 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 1136 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 1135 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 1136 | + define('WOOCOMMERCE_CART', true); |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | $items = array(); |
@@ -1141,8 +1141,8 @@ discard block |
||
| 1141 | 1141 | $discounts = 0; |
| 1142 | 1142 | |
| 1143 | 1143 | // Default show only subtotal instead of itemization. |
| 1144 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
| 1145 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 1144 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
| 1145 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 1146 | 1146 | $amount = $cart_item['line_subtotal']; |
| 1147 | 1147 | $subtotal += $cart_item['line_subtotal']; |
| 1148 | 1148 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
@@ -1151,61 +1151,61 @@ discard block |
||
| 1151 | 1151 | |
| 1152 | 1152 | $item = array( |
| 1153 | 1153 | 'label' => $product_name . $quantity_label, |
| 1154 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
| 1154 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
| 1155 | 1155 | ); |
| 1156 | 1156 | |
| 1157 | 1157 | $items[] = $item; |
| 1158 | 1158 | } |
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1162 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
| 1161 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1162 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
| 1163 | 1163 | } else { |
| 1164 | - $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
| 1164 | + $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
| 1165 | 1165 | |
| 1166 | - foreach ( $applied_coupons as $amount ) { |
|
| 1166 | + foreach ($applied_coupons as $amount) { |
|
| 1167 | 1167 | $discounts += (float) $amount; |
| 1168 | 1168 | } |
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | - $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
| 1172 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
| 1173 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
| 1174 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
| 1175 | - $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
| 1171 | + $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
| 1172 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
| 1173 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
| 1174 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
| 1175 | + $order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false); |
|
| 1176 | 1176 | |
| 1177 | - if ( wc_tax_enabled() ) { |
|
| 1177 | + if (wc_tax_enabled()) { |
|
| 1178 | 1178 | $items[] = array( |
| 1179 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
| 1180 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
| 1179 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
| 1180 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
| 1181 | 1181 | ); |
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | - if ( WC()->cart->needs_shipping() ) { |
|
| 1184 | + if (WC()->cart->needs_shipping()) { |
|
| 1185 | 1185 | $items[] = array( |
| 1186 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
| 1187 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
| 1186 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
| 1187 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
| 1188 | 1188 | ); |
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | - if ( WC()->cart->has_discount() ) { |
|
| 1191 | + if (WC()->cart->has_discount()) { |
|
| 1192 | 1192 | $items[] = array( |
| 1193 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
| 1194 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
| 1193 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
| 1194 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
| 1195 | 1195 | ); |
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1198 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1199 | 1199 | $cart_fees = WC()->cart->fees; |
| 1200 | 1200 | } else { |
| 1201 | 1201 | $cart_fees = WC()->cart->get_fees(); |
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | // Include fees and taxes as display items. |
| 1205 | - foreach ( $cart_fees as $key => $fee ) { |
|
| 1205 | + foreach ($cart_fees as $key => $fee) { |
|
| 1206 | 1206 | $items[] = array( |
| 1207 | 1207 | 'label' => $fee->name, |
| 1208 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
| 1208 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
| 1209 | 1209 | ); |
| 1210 | 1210 | } |
| 1211 | 1211 | |
@@ -1213,7 +1213,7 @@ discard block |
||
| 1213 | 1213 | 'displayItems' => $items, |
| 1214 | 1214 | 'total' => array( |
| 1215 | 1215 | 'label' => $this->total_label, |
| 1216 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
| 1216 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
| 1217 | 1217 | 'pending' => false, |
| 1218 | 1218 | ), |
| 1219 | 1219 | ); |