@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * Get this instance. |
| 131 | 131 | * |
| 132 | 132 | * @since 4.0.6 |
| 133 | - * @return class |
|
| 133 | + * @return WC_Stripe_Payment_Request |
|
| 134 | 134 | */ |
| 135 | 135 | public static function instance() { |
| 136 | 136 | return self::$_this; |
@@ -604,7 +604,6 @@ discard block |
||
| 604 | 604 | * |
| 605 | 605 | * @since 4.3.2 |
| 606 | 606 | * |
| 607 | - * @param object $post |
|
| 608 | 607 | * |
| 609 | 608 | * @return bool |
| 610 | 609 | */ |
@@ -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 | /** |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @return bool |
| 120 | 120 | */ |
| 121 | 121 | public function are_keys_set() { |
| 122 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
| 122 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -143,11 +143,11 @@ discard block |
||
| 143 | 143 | * @since 4.0.0 |
| 144 | 144 | */ |
| 145 | 145 | public function set_session() { |
| 146 | - if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
| 146 | + if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - WC()->session->set_customer_session_cookie( true ); |
|
| 150 | + WC()->session->set_customer_session_cookie(true); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -157,40 +157,40 @@ discard block |
||
| 157 | 157 | * @version 4.0.0 |
| 158 | 158 | */ |
| 159 | 159 | public function init() { |
| 160 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
| 160 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
| 161 | 161 | |
| 162 | 162 | /* |
| 163 | 163 | * In order to display the Payment Request button in the correct position, |
| 164 | 164 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
| 165 | 165 | * CSS is used to position the button. |
| 166 | 166 | */ |
| 167 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 168 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 169 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 167 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 168 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
| 169 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 170 | 170 | } else { |
| 171 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 172 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 171 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
| 172 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 176 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 175 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
| 176 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 177 | 177 | |
| 178 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 179 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 178 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
| 179 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 180 | 180 | |
| 181 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
| 182 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
| 183 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
| 184 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
| 185 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
| 186 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
| 187 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
| 188 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
| 181 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
| 182 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
| 183 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
| 184 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
| 185 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
| 186 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
| 187 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
| 188 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
| 189 | 189 | |
| 190 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 191 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
| 190 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 191 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
| 192 | 192 | |
| 193 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
| 193 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return string |
| 202 | 202 | */ |
| 203 | 203 | public function get_button_type() { |
| 204 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 204 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | 214 | public function get_button_theme() { |
| 215 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 215 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @return string |
| 224 | 224 | */ |
| 225 | 225 | public function get_button_height() { |
| 226 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
| 226 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -233,40 +233,40 @@ discard block |
||
| 233 | 233 | * @version 4.0.0 |
| 234 | 234 | */ |
| 235 | 235 | public function get_product_data() { |
| 236 | - if ( ! is_product() ) { |
|
| 236 | + if ( ! is_product()) { |
|
| 237 | 237 | return false; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | global $post; |
| 241 | 241 | |
| 242 | - $product = wc_get_product( $post->ID ); |
|
| 242 | + $product = wc_get_product($post->ID); |
|
| 243 | 243 | |
| 244 | 244 | $data = array(); |
| 245 | 245 | $items = array(); |
| 246 | 246 | |
| 247 | 247 | $items[] = array( |
| 248 | - 'label' => WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name(), |
|
| 249 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ), |
|
| 248 | + 'label' => WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name(), |
|
| 249 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()), |
|
| 250 | 250 | ); |
| 251 | 251 | |
| 252 | - if ( wc_tax_enabled() ) { |
|
| 252 | + if (wc_tax_enabled()) { |
|
| 253 | 253 | $items[] = array( |
| 254 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 254 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 255 | 255 | 'amount' => 0, |
| 256 | 256 | 'pending' => true, |
| 257 | 257 | ); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 260 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 261 | 261 | $items[] = array( |
| 262 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 262 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 263 | 263 | 'amount' => 0, |
| 264 | 264 | 'pending' => true, |
| 265 | 265 | ); |
| 266 | 266 | |
| 267 | 267 | $data['shippingOptions'] = array( |
| 268 | 268 | 'id' => 'pending', |
| 269 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 269 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 270 | 270 | 'detail' => '', |
| 271 | 271 | 'amount' => 0, |
| 272 | 272 | ); |
@@ -274,41 +274,41 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | $data['displayItems'] = $items; |
| 276 | 276 | $data['total'] = array( |
| 277 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
| 278 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ), |
|
| 277 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
| 278 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()), |
|
| 279 | 279 | 'pending' => true, |
| 280 | 280 | ); |
| 281 | 281 | |
| 282 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 283 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 284 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 282 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 283 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 284 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 285 | 285 | |
| 286 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
| 286 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Filters the gateway title to reflect Payment Request type |
| 291 | 291 | * |
| 292 | 292 | */ |
| 293 | - public function filter_gateway_title( $title, $id ) { |
|
| 293 | + public function filter_gateway_title($title, $id) { |
|
| 294 | 294 | global $post; |
| 295 | 295 | |
| 296 | - if ( ! is_object( $post ) ) { |
|
| 296 | + if ( ! is_object($post)) { |
|
| 297 | 297 | return $title; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 301 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 300 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 301 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 302 | 302 | } else { |
| 303 | - $order = wc_get_order( $post->ID ); |
|
| 304 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
| 303 | + $order = wc_get_order($post->ID); |
|
| 304 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
| 307 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
| 308 | 308 | return $method_title; |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
| 311 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
| 312 | 312 | return $method_title; |
| 313 | 313 | } |
| 314 | 314 | |
@@ -321,16 +321,16 @@ discard block |
||
| 321 | 321 | * @since 3.1.4 |
| 322 | 322 | * @version 4.0.0 |
| 323 | 323 | */ |
| 324 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 324 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 325 | 325 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 326 | 326 | |
| 327 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 327 | + if ( ! isset($gateways['stripe'])) { |
|
| 328 | 328 | return $valid; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
| 331 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
| 332 | 332 | |
| 333 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
| 333 | + if ('apple_pay' !== $payment_request_type) { |
|
| 334 | 334 | return $valid; |
| 335 | 335 | } |
| 336 | 336 | |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 341 | 341 | * Note that this only works with shipping providers that don't validate full postal codes. |
| 342 | 342 | */ |
| 343 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 343 | + if ('GB' === $country || 'CA' === $country) { |
|
| 344 | 344 | return true; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -355,29 +355,29 @@ discard block |
||
| 355 | 355 | * @param int $order_id |
| 356 | 356 | * @param array $posted_data The posted data from checkout form. |
| 357 | 357 | */ |
| 358 | - public function add_order_meta( $order_id, $posted_data ) { |
|
| 359 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
| 358 | + public function add_order_meta($order_id, $posted_data) { |
|
| 359 | + if (empty($_POST['payment_request_type'])) { |
|
| 360 | 360 | return; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - $order = wc_get_order( $order_id ); |
|
| 363 | + $order = wc_get_order($order_id); |
|
| 364 | 364 | |
| 365 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
| 365 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
| 366 | 366 | |
| 367 | - if ( 'apple_pay' === $payment_request_type ) { |
|
| 368 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 369 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
| 367 | + if ('apple_pay' === $payment_request_type) { |
|
| 368 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 369 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
| 370 | 370 | } else { |
| 371 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
| 371 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
| 372 | 372 | $order->save(); |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
| 377 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 378 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
| 376 | + if ('payment_request_api' === $payment_request_type) { |
|
| 377 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 378 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
| 379 | 379 | } else { |
| 380 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
| 380 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
| 381 | 381 | $order->save(); |
| 382 | 382 | } |
| 383 | 383 | } |
@@ -416,20 +416,20 @@ discard block |
||
| 416 | 416 | * @return bool |
| 417 | 417 | */ |
| 418 | 418 | public function allowed_items_in_cart() { |
| 419 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 420 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
| 419 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 420 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
| 421 | 421 | |
| 422 | - if ( ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
| 422 | + if ( ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
| 423 | 423 | return false; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | // Trial subscriptions with shipping are not supported |
| 427 | - if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) { |
|
| 427 | + if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) { |
|
| 428 | 428 | return false; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | // Pre Orders compatbility where we don't support charge upon release. |
| 432 | - 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() ) ) { |
|
| 432 | + 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())) { |
|
| 433 | 433 | return false; |
| 434 | 434 | } |
| 435 | 435 | } |
@@ -445,73 +445,73 @@ discard block |
||
| 445 | 445 | */ |
| 446 | 446 | public function scripts() { |
| 447 | 447 | // If keys are not set bail. |
| 448 | - if ( ! $this->are_keys_set() ) { |
|
| 449 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
| 448 | + if ( ! $this->are_keys_set()) { |
|
| 449 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
| 450 | 450 | return; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | // If no SSL bail. |
| 454 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
| 455 | - WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
| 454 | + if ( ! $this->testmode && ! is_ssl()) { |
|
| 455 | + WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
| 456 | 456 | return; |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 459 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 460 | 460 | return; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
| 463 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
| 464 | 464 | return; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 467 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 468 | 468 | |
| 469 | 469 | $stripe_params = array( |
| 470 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 470 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 471 | 471 | 'stripe' => array( |
| 472 | 472 | 'key' => $this->publishable_key, |
| 473 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
| 473 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
| 474 | 474 | ), |
| 475 | 475 | 'nonce' => array( |
| 476 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
| 477 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
| 478 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
| 479 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
| 480 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
| 481 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
| 482 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
| 483 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
| 476 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
| 477 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
| 478 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
| 479 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
| 480 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
| 481 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
| 482 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
| 483 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
| 484 | 484 | ), |
| 485 | 485 | 'i18n' => array( |
| 486 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
| 486 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
| 487 | 487 | /* translators: Do not translate the [option] placeholder */ |
| 488 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
| 488 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
| 489 | 489 | ), |
| 490 | 490 | 'checkout' => array( |
| 491 | 491 | 'url' => wc_get_checkout_url(), |
| 492 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
| 493 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 492 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
| 493 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 494 | 494 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 495 | 495 | ), |
| 496 | 496 | 'button' => array( |
| 497 | 497 | 'type' => $this->get_button_type(), |
| 498 | 498 | 'theme' => $this->get_button_theme(), |
| 499 | 499 | 'height' => $this->get_button_height(), |
| 500 | - 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US. |
|
| 500 | + 'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US. |
|
| 501 | 501 | ), |
| 502 | 502 | 'is_product_page' => is_product(), |
| 503 | 503 | 'product' => $this->get_product_data(), |
| 504 | 504 | ); |
| 505 | 505 | |
| 506 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 507 | - 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 ); |
|
| 506 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 507 | + 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); |
|
| 508 | 508 | |
| 509 | - wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) ); |
|
| 509 | + wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params)); |
|
| 510 | 510 | |
| 511 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
| 511 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
| 512 | 512 | |
| 513 | 513 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 514 | - if ( isset( $gateways['stripe'] ) ) { |
|
| 514 | + if (isset($gateways['stripe'])) { |
|
| 515 | 515 | $gateways['stripe']->payment_scripts(); |
| 516 | 516 | } |
| 517 | 517 | } |
@@ -527,23 +527,23 @@ discard block |
||
| 527 | 527 | |
| 528 | 528 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 529 | 529 | |
| 530 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 530 | + if ( ! isset($gateways['stripe'])) { |
|
| 531 | 531 | return; |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 534 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 535 | 535 | return; |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
| 538 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
| 539 | 539 | return; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
| 542 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
| 543 | 543 | return; |
| 544 | 544 | } else { |
| 545 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 546 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 545 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 546 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 547 | 547 | return; |
| 548 | 548 | } |
| 549 | 549 | } |
@@ -567,28 +567,28 @@ discard block |
||
| 567 | 567 | |
| 568 | 568 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 569 | 569 | |
| 570 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 570 | + if ( ! isset($gateways['stripe'])) { |
|
| 571 | 571 | return; |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 574 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 575 | 575 | return; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
| 578 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
| 579 | 579 | return; |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) { |
|
| 582 | + if (is_product() && ! $this->should_show_payment_button_on_product_page()) { |
|
| 583 | 583 | return; |
| 584 | 584 | } else { |
| 585 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 586 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 585 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 586 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 587 | 587 | return; |
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | ?> |
| 591 | - <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> |
|
| 591 | + <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> |
|
| 592 | 592 | <?php |
| 593 | 593 | } |
| 594 | 594 | |
@@ -604,32 +604,32 @@ discard block |
||
| 604 | 604 | private function should_show_payment_button_on_product_page() { |
| 605 | 605 | global $post; |
| 606 | 606 | |
| 607 | - $product = wc_get_product( $post->ID ); |
|
| 607 | + $product = wc_get_product($post->ID); |
|
| 608 | 608 | |
| 609 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
| 609 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
| 610 | 610 | return false; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 613 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 614 | 614 | return false; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | // Trial subscriptions with shipping are not supported |
| 618 | - if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) { |
|
| 618 | + if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) { |
|
| 619 | 619 | return false; |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | // Pre Orders charge upon release not supported. |
| 623 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 624 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 623 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 624 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 625 | 625 | return false; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | // File upload addon not supported |
| 629 | - if ( class_exists( 'WC_Product_Addons_Helper' ) ) { |
|
| 630 | - $product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() ); |
|
| 631 | - foreach ( $product_addons as $addon ) { |
|
| 632 | - if ( 'file_upload' === $addon['type'] ) { |
|
| 629 | + if (class_exists('WC_Product_Addons_Helper')) { |
|
| 630 | + $product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id()); |
|
| 631 | + foreach ($product_addons as $addon) { |
|
| 632 | + if ('file_upload' === $addon['type']) { |
|
| 633 | 633 | return false; |
| 634 | 634 | } |
| 635 | 635 | } |
@@ -645,11 +645,11 @@ discard block |
||
| 645 | 645 | * @version 4.0.0 |
| 646 | 646 | */ |
| 647 | 647 | public function ajax_log_errors() { |
| 648 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
| 648 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
| 649 | 649 | |
| 650 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
| 650 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
| 651 | 651 | |
| 652 | - WC_Stripe_Logger::log( $errors ); |
|
| 652 | + WC_Stripe_Logger::log($errors); |
|
| 653 | 653 | |
| 654 | 654 | exit; |
| 655 | 655 | } |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | * @version 4.0.0 |
| 662 | 662 | */ |
| 663 | 663 | public function ajax_clear_cart() { |
| 664 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
| 664 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
| 665 | 665 | |
| 666 | 666 | WC()->cart->empty_cart(); |
| 667 | 667 | exit; |
@@ -671,10 +671,10 @@ discard block |
||
| 671 | 671 | * Get cart details. |
| 672 | 672 | */ |
| 673 | 673 | public function ajax_get_cart_details() { |
| 674 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
| 674 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
| 675 | 675 | |
| 676 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 677 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 676 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 677 | + define('WOOCOMMERCE_CART', true); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | WC()->cart->calculate_totals(); |
@@ -685,14 +685,14 @@ discard block |
||
| 685 | 685 | $data = array( |
| 686 | 686 | 'shipping_required' => WC()->cart->needs_shipping(), |
| 687 | 687 | 'order_data' => array( |
| 688 | - 'currency' => strtolower( $currency ), |
|
| 689 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 688 | + 'currency' => strtolower($currency), |
|
| 689 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 690 | 690 | ), |
| 691 | 691 | ); |
| 692 | 692 | |
| 693 | 693 | $data['order_data'] += $this->build_display_items(); |
| 694 | 694 | |
| 695 | - wp_send_json( $data ); |
|
| 695 | + wp_send_json($data); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | * @see WC_Shipping::get_packages(). |
| 704 | 704 | */ |
| 705 | 705 | public function ajax_get_shipping_options() { |
| 706 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
| 706 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
| 707 | 707 | |
| 708 | 708 | try { |
| 709 | 709 | // Set the shipping package. |
@@ -719,34 +719,34 @@ discard block |
||
| 719 | 719 | ) |
| 720 | 720 | ); |
| 721 | 721 | |
| 722 | - $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) ); |
|
| 722 | + $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted)); |
|
| 723 | 723 | |
| 724 | 724 | // Set the shipping options. |
| 725 | 725 | $data = array(); |
| 726 | 726 | $packages = WC()->shipping->get_packages(); |
| 727 | 727 | |
| 728 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 729 | - foreach ( $packages as $package_key => $package ) { |
|
| 730 | - if ( empty( $package['rates'] ) ) { |
|
| 731 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 728 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 729 | + foreach ($packages as $package_key => $package) { |
|
| 730 | + if (empty($package['rates'])) { |
|
| 731 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 734 | + foreach ($package['rates'] as $key => $rate) { |
|
| 735 | 735 | $data['shipping_options'][] = array( |
| 736 | 736 | 'id' => $rate->id, |
| 737 | 737 | 'label' => $rate->label, |
| 738 | 738 | 'detail' => '', |
| 739 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
| 739 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
| 740 | 740 | ); |
| 741 | 741 | } |
| 742 | 742 | } |
| 743 | 743 | } else { |
| 744 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 744 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - if ( isset( $data[0] ) ) { |
|
| 747 | + if (isset($data[0])) { |
|
| 748 | 748 | // Auto select the first shipping method. |
| 749 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 749 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | WC()->cart->calculate_totals(); |
@@ -754,12 +754,12 @@ discard block |
||
| 754 | 754 | $data += $this->build_display_items(); |
| 755 | 755 | $data['result'] = 'success'; |
| 756 | 756 | |
| 757 | - wp_send_json( $data ); |
|
| 758 | - } catch ( Exception $e ) { |
|
| 757 | + wp_send_json($data); |
|
| 758 | + } catch (Exception $e) { |
|
| 759 | 759 | $data += $this->build_display_items(); |
| 760 | 760 | $data['result'] = 'invalid_shipping_address'; |
| 761 | 761 | |
| 762 | - wp_send_json( $data ); |
|
| 762 | + wp_send_json($data); |
|
| 763 | 763 | } |
| 764 | 764 | } |
| 765 | 765 | |
@@ -767,22 +767,22 @@ discard block |
||
| 767 | 767 | * Update shipping method. |
| 768 | 768 | */ |
| 769 | 769 | public function ajax_update_shipping_method() { |
| 770 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
| 770 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
| 771 | 771 | |
| 772 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 773 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 772 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 773 | + define('WOOCOMMERCE_CART', true); |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 777 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 776 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 777 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 778 | 778 | |
| 779 | - if ( is_array( $shipping_method ) ) { |
|
| 780 | - foreach ( $shipping_method as $i => $value ) { |
|
| 781 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
| 779 | + if (is_array($shipping_method)) { |
|
| 780 | + foreach ($shipping_method as $i => $value) { |
|
| 781 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
| 782 | 782 | } |
| 783 | 783 | } |
| 784 | 784 | |
| 785 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
| 785 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
| 786 | 786 | |
| 787 | 787 | WC()->cart->calculate_totals(); |
| 788 | 788 | |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | $data += $this->build_display_items(); |
| 791 | 791 | $data['result'] = 'success'; |
| 792 | 792 | |
| 793 | - wp_send_json( $data ); |
|
| 793 | + wp_send_json($data); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | /** |
@@ -801,47 +801,47 @@ discard block |
||
| 801 | 801 | * @return array $data |
| 802 | 802 | */ |
| 803 | 803 | public function ajax_get_selected_product_data() { |
| 804 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
| 804 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
| 805 | 805 | |
| 806 | 806 | try { |
| 807 | - $product_id = absint( $_POST['product_id'] ); |
|
| 808 | - $qty = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id ); |
|
| 809 | - $addon_value = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0; |
|
| 810 | - $product = wc_get_product( $product_id ); |
|
| 807 | + $product_id = absint($_POST['product_id']); |
|
| 808 | + $qty = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id); |
|
| 809 | + $addon_value = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0; |
|
| 810 | + $product = wc_get_product($product_id); |
|
| 811 | 811 | $variation_id = null; |
| 812 | 812 | |
| 813 | - if ( ! is_a( $product, 'WC_Product' ) ) { |
|
| 814 | - throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); |
|
| 813 | + if ( ! is_a($product, 'WC_Product')) { |
|
| 814 | + throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id)); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | - if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 818 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 817 | + if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 818 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 819 | 819 | |
| 820 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 821 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 820 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 821 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 822 | 822 | } else { |
| 823 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 824 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 823 | + $data_store = WC_Data_Store::load('product'); |
|
| 824 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | - if ( ! empty( $variation_id ) ) { |
|
| 828 | - $product = wc_get_product( $variation_id ); |
|
| 827 | + if ( ! empty($variation_id)) { |
|
| 828 | + $product = wc_get_product($variation_id); |
|
| 829 | 829 | } |
| 830 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) { |
|
| 831 | - $product = wc_get_product( $product_id ); |
|
| 830 | + } elseif ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) { |
|
| 831 | + $product = wc_get_product($product_id); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | // Force quantity to 1 if sold individually and check for existing item in cart. |
| 835 | - if ( $product->is_sold_individually() ) { |
|
| 836 | - $qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id ); |
|
| 835 | + if ($product->is_sold_individually()) { |
|
| 836 | + $qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id); |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | - if ( ! $product->has_enough_stock( $qty ) ) { |
|
| 839 | + if ( ! $product->has_enough_stock($qty)) { |
|
| 840 | 840 | /* translators: 1: product name 2: quantity in stock */ |
| 841 | - 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 ) ) ); |
|
| 841 | + 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))); |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | - $total = $qty * ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ) + $addon_value; |
|
| 844 | + $total = $qty * (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()) + $addon_value; |
|
| 845 | 845 | |
| 846 | 846 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
| 847 | 847 | |
@@ -849,28 +849,28 @@ discard block |
||
| 849 | 849 | $items = array(); |
| 850 | 850 | |
| 851 | 851 | $items[] = array( |
| 852 | - 'label' => ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name() ) . $quantity_label, |
|
| 853 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 852 | + 'label' => (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name()) . $quantity_label, |
|
| 853 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 854 | 854 | ); |
| 855 | 855 | |
| 856 | - if ( wc_tax_enabled() ) { |
|
| 856 | + if (wc_tax_enabled()) { |
|
| 857 | 857 | $items[] = array( |
| 858 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 858 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 859 | 859 | 'amount' => 0, |
| 860 | 860 | 'pending' => true, |
| 861 | 861 | ); |
| 862 | 862 | } |
| 863 | 863 | |
| 864 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 864 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 865 | 865 | $items[] = array( |
| 866 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 866 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 867 | 867 | 'amount' => 0, |
| 868 | 868 | 'pending' => true, |
| 869 | 869 | ); |
| 870 | 870 | |
| 871 | 871 | $data['shippingOptions'] = array( |
| 872 | 872 | 'id' => 'pending', |
| 873 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 873 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 874 | 874 | 'detail' => '', |
| 875 | 875 | 'amount' => 0, |
| 876 | 876 | ); |
@@ -879,17 +879,17 @@ discard block |
||
| 879 | 879 | $data['displayItems'] = $items; |
| 880 | 880 | $data['total'] = array( |
| 881 | 881 | 'label' => $this->total_label, |
| 882 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 882 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 883 | 883 | 'pending' => true, |
| 884 | 884 | ); |
| 885 | 885 | |
| 886 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 887 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 888 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 886 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 887 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 888 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 889 | 889 | |
| 890 | - wp_send_json( $data ); |
|
| 891 | - } catch ( Exception $e ) { |
|
| 892 | - wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) ); |
|
| 890 | + wp_send_json($data); |
|
| 891 | + } catch (Exception $e) { |
|
| 892 | + wp_send_json(array('error' => wp_strip_all_tags($e->getMessage()))); |
|
| 893 | 893 | } |
| 894 | 894 | } |
| 895 | 895 | |
@@ -901,37 +901,37 @@ discard block |
||
| 901 | 901 | * @return array $data |
| 902 | 902 | */ |
| 903 | 903 | public function ajax_add_to_cart() { |
| 904 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
| 904 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
| 905 | 905 | |
| 906 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 907 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 906 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 907 | + define('WOOCOMMERCE_CART', true); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | WC()->shipping->reset_shipping(); |
| 911 | 911 | |
| 912 | - $product_id = absint( $_POST['product_id'] ); |
|
| 913 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 914 | - $product = wc_get_product( $product_id ); |
|
| 915 | - $product_type = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type(); |
|
| 912 | + $product_id = absint($_POST['product_id']); |
|
| 913 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 914 | + $product = wc_get_product($product_id); |
|
| 915 | + $product_type = WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type(); |
|
| 916 | 916 | |
| 917 | 917 | // First empty the cart to prevent wrong calculation. |
| 918 | 918 | WC()->cart->empty_cart(); |
| 919 | 919 | |
| 920 | - if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { |
|
| 921 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 920 | + if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) { |
|
| 921 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 922 | 922 | |
| 923 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 924 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 923 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 924 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 925 | 925 | } else { |
| 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 | 929 | |
| 930 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 930 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | - if ( 'simple' === $product_type || 'subscription' === $product_type ) { |
|
| 934 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 933 | + if ('simple' === $product_type || 'subscription' === $product_type) { |
|
| 934 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | WC()->cart->calculate_totals(); |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | $data += $this->build_display_items(); |
| 941 | 941 | $data['result'] = 'success'; |
| 942 | 942 | |
| 943 | - wp_send_json( $data ); |
|
| 943 | + wp_send_json($data); |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | /** |
@@ -953,31 +953,31 @@ discard block |
||
| 953 | 953 | * @version 4.0.0 |
| 954 | 954 | */ |
| 955 | 955 | public function normalize_state() { |
| 956 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
| 957 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
| 958 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
| 959 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
| 956 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
| 957 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
| 958 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
| 959 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
| 960 | 960 | |
| 961 | - if ( $billing_state && $billing_country ) { |
|
| 962 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
| 961 | + if ($billing_state && $billing_country) { |
|
| 962 | + $valid_states = WC()->countries->get_states($billing_country); |
|
| 963 | 963 | |
| 964 | 964 | // Valid states found for country. |
| 965 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 966 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 967 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
| 965 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 966 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 967 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
| 968 | 968 | $_POST['billing_state'] = $state_abbr; |
| 969 | 969 | } |
| 970 | 970 | } |
| 971 | 971 | } |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | - if ( $shipping_state && $shipping_country ) { |
|
| 975 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
| 974 | + if ($shipping_state && $shipping_country) { |
|
| 975 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
| 976 | 976 | |
| 977 | 977 | // Valid states found for country. |
| 978 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 979 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 980 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
| 978 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 979 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 980 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
| 981 | 981 | $_POST['shipping_state'] = $state_abbr; |
| 982 | 982 | } |
| 983 | 983 | } |
@@ -992,19 +992,19 @@ discard block |
||
| 992 | 992 | * @version 4.0.0 |
| 993 | 993 | */ |
| 994 | 994 | public function ajax_create_order() { |
| 995 | - if ( WC()->cart->is_empty() ) { |
|
| 996 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
| 995 | + if (WC()->cart->is_empty()) { |
|
| 996 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
| 997 | 997 | } |
| 998 | 998 | |
| 999 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
| 1000 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 999 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
| 1000 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | $this->normalize_state(); |
| 1004 | 1004 | |
| 1005 | 1005 | WC()->checkout()->process_checkout(); |
| 1006 | 1006 | |
| 1007 | - die( 0 ); |
|
| 1007 | + die(0); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1014,41 +1014,41 @@ discard block |
||
| 1014 | 1014 | * @version 4.0.0 |
| 1015 | 1015 | * @param array $address |
| 1016 | 1016 | */ |
| 1017 | - protected function calculate_shipping( $address = array() ) { |
|
| 1017 | + protected function calculate_shipping($address = array()) { |
|
| 1018 | 1018 | $country = $address['country']; |
| 1019 | 1019 | $state = $address['state']; |
| 1020 | 1020 | $postcode = $address['postcode']; |
| 1021 | 1021 | $city = $address['city']; |
| 1022 | 1022 | $address_1 = $address['address']; |
| 1023 | 1023 | $address_2 = $address['address_2']; |
| 1024 | - $wc_states = WC()->countries->get_states( $country ); |
|
| 1024 | + $wc_states = WC()->countries->get_states($country); |
|
| 1025 | 1025 | |
| 1026 | 1026 | /** |
| 1027 | 1027 | * In some versions of Chrome, state can be a full name. So we need |
| 1028 | 1028 | * to convert that to abbreviation as WC is expecting that. |
| 1029 | 1029 | */ |
| 1030 | - if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) { |
|
| 1031 | - $state = array_search( ucwords( strtolower( $state ) ), $wc_states, true ); |
|
| 1030 | + if (2 < strlen($state) && ! empty($wc_states)) { |
|
| 1031 | + $state = array_search(ucwords(strtolower($state)), $wc_states, true); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | WC()->shipping->reset_shipping(); |
| 1035 | 1035 | |
| 1036 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 1037 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 1036 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
| 1037 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | - if ( $country ) { |
|
| 1041 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 1042 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 1040 | + if ($country) { |
|
| 1041 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 1042 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 1043 | 1043 | } else { |
| 1044 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
|
| 1045 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
|
| 1044 | + WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
|
| 1045 | + WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 1049 | - WC()->customer->calculated_shipping( true ); |
|
| 1048 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 1049 | + WC()->customer->calculated_shipping(true); |
|
| 1050 | 1050 | } else { |
| 1051 | - WC()->customer->set_calculated_shipping( true ); |
|
| 1051 | + WC()->customer->set_calculated_shipping(true); |
|
| 1052 | 1052 | WC()->customer->save(); |
| 1053 | 1053 | } |
| 1054 | 1054 | |
@@ -1065,17 +1065,17 @@ discard block |
||
| 1065 | 1065 | $packages[0]['destination']['address'] = $address_1; |
| 1066 | 1066 | $packages[0]['destination']['address_2'] = $address_2; |
| 1067 | 1067 | |
| 1068 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 1069 | - if ( $item['data']->needs_shipping() ) { |
|
| 1070 | - if ( isset( $item['line_total'] ) ) { |
|
| 1068 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 1069 | + if ($item['data']->needs_shipping()) { |
|
| 1070 | + if (isset($item['line_total'])) { |
|
| 1071 | 1071 | $packages[0]['contents_cost'] += $item['line_total']; |
| 1072 | 1072 | } |
| 1073 | 1073 | } |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 1076 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 1077 | 1077 | |
| 1078 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 1078 | + WC()->shipping->calculate_shipping($packages); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | /** |
@@ -1084,19 +1084,19 @@ discard block |
||
| 1084 | 1084 | * @since 3.1.0 |
| 1085 | 1085 | * @version 4.0.0 |
| 1086 | 1086 | */ |
| 1087 | - protected function build_shipping_methods( $shipping_methods ) { |
|
| 1088 | - if ( empty( $shipping_methods ) ) { |
|
| 1087 | + protected function build_shipping_methods($shipping_methods) { |
|
| 1088 | + if (empty($shipping_methods)) { |
|
| 1089 | 1089 | return array(); |
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | $shipping = array(); |
| 1093 | 1093 | |
| 1094 | - foreach ( $shipping_methods as $method ) { |
|
| 1094 | + foreach ($shipping_methods as $method) { |
|
| 1095 | 1095 | $shipping[] = array( |
| 1096 | 1096 | 'id' => $method['id'], |
| 1097 | 1097 | 'label' => $method['label'], |
| 1098 | 1098 | 'detail' => '', |
| 1099 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
| 1099 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
| 1100 | 1100 | ); |
| 1101 | 1101 | } |
| 1102 | 1102 | |
@@ -1110,8 +1110,8 @@ discard block |
||
| 1110 | 1110 | * @version 4.0.0 |
| 1111 | 1111 | */ |
| 1112 | 1112 | protected function build_display_items() { |
| 1113 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 1114 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 1113 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 1114 | + define('WOOCOMMERCE_CART', true); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | $items = array(); |
@@ -1119,71 +1119,71 @@ discard block |
||
| 1119 | 1119 | $discounts = 0; |
| 1120 | 1120 | |
| 1121 | 1121 | // Default show only subtotal instead of itemization. |
| 1122 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
| 1123 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 1122 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
| 1123 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 1124 | 1124 | $amount = $cart_item['line_subtotal']; |
| 1125 | 1125 | $subtotal += $cart_item['line_subtotal']; |
| 1126 | 1126 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
| 1127 | 1127 | |
| 1128 | - $product_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
| 1128 | + $product_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
| 1129 | 1129 | |
| 1130 | 1130 | $item = array( |
| 1131 | 1131 | 'label' => $product_name . $quantity_label, |
| 1132 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
| 1132 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
| 1133 | 1133 | ); |
| 1134 | 1134 | |
| 1135 | 1135 | $items[] = $item; |
| 1136 | 1136 | } |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1140 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
| 1139 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1140 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
| 1141 | 1141 | } else { |
| 1142 | - $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
| 1142 | + $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
| 1143 | 1143 | |
| 1144 | - foreach ( $applied_coupons as $amount ) { |
|
| 1144 | + foreach ($applied_coupons as $amount) { |
|
| 1145 | 1145 | $discounts += (float) $amount; |
| 1146 | 1146 | } |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | - $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
| 1150 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
| 1151 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
| 1152 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
| 1153 | - $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
| 1149 | + $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
| 1150 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
| 1151 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
| 1152 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
| 1153 | + $order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false); |
|
| 1154 | 1154 | |
| 1155 | - if ( wc_tax_enabled() ) { |
|
| 1155 | + if (wc_tax_enabled()) { |
|
| 1156 | 1156 | $items[] = array( |
| 1157 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
| 1158 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
| 1157 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
| 1158 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
| 1159 | 1159 | ); |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | - if ( WC()->cart->needs_shipping() ) { |
|
| 1162 | + if (WC()->cart->needs_shipping()) { |
|
| 1163 | 1163 | $items[] = array( |
| 1164 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
| 1165 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
| 1164 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
| 1165 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
| 1166 | 1166 | ); |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | - if ( WC()->cart->has_discount() ) { |
|
| 1169 | + if (WC()->cart->has_discount()) { |
|
| 1170 | 1170 | $items[] = array( |
| 1171 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
| 1172 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
| 1171 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
| 1172 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
| 1173 | 1173 | ); |
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1176 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1177 | 1177 | $cart_fees = WC()->cart->fees; |
| 1178 | 1178 | } else { |
| 1179 | 1179 | $cart_fees = WC()->cart->get_fees(); |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | // Include fees and taxes as display items. |
| 1183 | - foreach ( $cart_fees as $key => $fee ) { |
|
| 1183 | + foreach ($cart_fees as $key => $fee) { |
|
| 1184 | 1184 | $items[] = array( |
| 1185 | 1185 | 'label' => $fee->name, |
| 1186 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
| 1186 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
| 1187 | 1187 | ); |
| 1188 | 1188 | } |
| 1189 | 1189 | |
@@ -1191,7 +1191,7 @@ discard block |
||
| 1191 | 1191 | 'displayItems' => $items, |
| 1192 | 1192 | 'total' => array( |
| 1193 | 1193 | 'label' => $this->total_label, |
| 1194 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
| 1194 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
| 1195 | 1195 | 'pending' => false, |
| 1196 | 1196 | ), |
| 1197 | 1197 | ); |