@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -96,28 +96,28 @@ discard block |
||
| 96 | 96 | public function __construct() { |
| 97 | 97 | self::$_this = $this; |
| 98 | 98 | |
| 99 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
| 99 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
| 100 | 100 | |
| 101 | - $this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
| 101 | + $this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 102 | 102 | |
| 103 | 103 | // If both site title and statement descriptor is not set. Fallback. |
| 104 | - if ( empty( $this->statement_descriptor ) ) { |
|
| 104 | + if (empty($this->statement_descriptor)) { |
|
| 105 | 105 | $this->statement_descriptor = $_SERVER['SERVER_NAME']; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $this->enabled = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false; |
|
| 109 | - $this->testmode = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false; |
|
| 110 | - $this->capture = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false; |
|
| 111 | - $this->saved_cards = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false; |
|
| 112 | - $this->apple_pay = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false; |
|
| 113 | - $this->apple_pay_button = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
| 114 | - $this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
| 115 | - $this->logging = ( ! empty( $gateway_settings['logging'] ) && 'yes' === $gateway_settings['logging'] ) ? true : false; |
|
| 116 | - $this->publishable_key = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : ''; |
|
| 108 | + $this->enabled = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false; |
|
| 109 | + $this->testmode = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false; |
|
| 110 | + $this->capture = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false; |
|
| 111 | + $this->saved_cards = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false; |
|
| 112 | + $this->apple_pay = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false; |
|
| 113 | + $this->apple_pay_button = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
| 114 | + $this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
| 115 | + $this->logging = ( ! empty($gateway_settings['logging']) && 'yes' === $gateway_settings['logging']) ? true : false; |
|
| 116 | + $this->publishable_key = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : ''; |
|
| 117 | 117 | $this->is_shipping_enabled = $this->is_shipping_enabled(); |
| 118 | 118 | |
| 119 | - if ( $this->testmode ) { |
|
| 120 | - $this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : ''; |
|
| 119 | + if ($this->testmode) { |
|
| 120 | + $this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : ''; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $this->init(); |
@@ -136,53 +136,53 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | public function init() { |
| 138 | 138 | // If Apple Pay is not enabled no need to proceed further. |
| 139 | - if ( ! $this->apple_pay ) { |
|
| 139 | + if ( ! $this->apple_pay) { |
|
| 140 | 140 | return; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) ); |
|
| 144 | - add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) ); |
|
| 143 | + add_action('wp_enqueue_scripts', array($this, 'cart_scripts')); |
|
| 144 | + add_action('wp_enqueue_scripts', array($this, 'single_scripts')); |
|
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | 147 | * In order to display the Apple Pay button in the correct position, |
| 148 | 148 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
| 149 | 149 | * CSS is used to position the button. |
| 150 | 150 | */ |
| 151 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
| 152 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 151 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
| 152 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1); |
|
| 153 | 153 | } else { |
| 154 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 154 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 158 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
| 159 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 160 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
| 161 | - add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) ); |
|
| 162 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
| 163 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
| 164 | - add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) ); |
|
| 165 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) ); |
|
| 166 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
| 167 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
| 168 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 169 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
| 157 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1); |
|
| 158 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2); |
|
| 159 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1); |
|
| 160 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2); |
|
| 161 | + add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors')); |
|
| 162 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
| 163 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
| 164 | + add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart')); |
|
| 165 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single')); |
|
| 166 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
| 167 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
| 168 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 169 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
| 173 | 173 | * Filters the gateway title to reflect Apple Pay. |
| 174 | 174 | * |
| 175 | 175 | */ |
| 176 | - public function filter_gateway_title( $title, $id ) { |
|
| 176 | + public function filter_gateway_title($title, $id) { |
|
| 177 | 177 | global $post; |
| 178 | 178 | |
| 179 | - if ( ! is_object( $post ) ) { |
|
| 179 | + if ( ! is_object($post)) { |
|
| 180 | 180 | return $title; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 183 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 184 | 184 | |
| 185 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
| 185 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
| 186 | 186 | return $method_title; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -196,13 +196,13 @@ discard block |
||
| 196 | 196 | * @version 3.1.4 |
| 197 | 197 | */ |
| 198 | 198 | public function log_apple_pay_errors() { |
| 199 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 200 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 199 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 200 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
| 203 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
| 204 | 204 | |
| 205 | - $this->log( $errors ); |
|
| 205 | + $this->log($errors); |
|
| 206 | 206 | |
| 207 | 207 | exit; |
| 208 | 208 | } |
@@ -213,10 +213,10 @@ discard block |
||
| 213 | 213 | * @since 3.1.4 |
| 214 | 214 | * @version 3.1.4 |
| 215 | 215 | */ |
| 216 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 216 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 217 | 217 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 218 | 218 | |
| 219 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
| 219 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
| 220 | 220 | return $valid; |
| 221 | 221 | } |
| 222 | 222 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * when passing it back from the shippingcontactselected object. This causes WC to invalidate |
| 226 | 226 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 227 | 227 | */ |
| 228 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 228 | + if ('GB' === $country || 'CA' === $country) { |
|
| 229 | 229 | return true; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * @return bool |
| 241 | 241 | */ |
| 242 | 242 | public function is_shipping_enabled() { |
| 243 | - $shipping_enabled = get_option( 'woocommerce_ship_to_countries', '' ); |
|
| 243 | + $shipping_enabled = get_option('woocommerce_ship_to_countries', ''); |
|
| 244 | 244 | |
| 245 | - if ( 'disabled' === $shipping_enabled ) { |
|
| 245 | + if ('disabled' === $shipping_enabled) { |
|
| 246 | 246 | return false; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -256,42 +256,42 @@ discard block |
||
| 256 | 256 | * @version 3.1.4 |
| 257 | 257 | */ |
| 258 | 258 | public function single_scripts() { |
| 259 | - if ( ! is_single() ) { |
|
| 259 | + if ( ! is_single()) { |
|
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | global $post; |
| 264 | 264 | |
| 265 | - $product = wc_get_product( $post->ID ); |
|
| 265 | + $product = wc_get_product($post->ID); |
|
| 266 | 266 | |
| 267 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 267 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 268 | 268 | return; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 271 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 272 | 272 | |
| 273 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 273 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 274 | 274 | |
| 275 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 276 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay_single', plugins_url( 'assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 275 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 276 | + wp_enqueue_script('woocommerce_stripe_apple_pay_single', plugins_url('assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 277 | 277 | |
| 278 | 278 | $stripe_params = array( |
| 279 | 279 | 'key' => $this->publishable_key, |
| 280 | 280 | 'currency_code' => get_woocommerce_currency(), |
| 281 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 281 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 282 | 282 | 'label' => $this->statement_descriptor, |
| 283 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 284 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 285 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 286 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 287 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 288 | - 'needs_shipping' => ( $product->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no', |
|
| 283 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 284 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 285 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 286 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 287 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 288 | + 'needs_shipping' => ($product->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no', |
|
| 289 | 289 | 'i18n' => array( |
| 290 | - 'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
| 290 | + 'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
| 291 | 291 | ), |
| 292 | 292 | ); |
| 293 | 293 | |
| 294 | - wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) ); |
|
| 294 | + wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params)); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -301,32 +301,32 @@ discard block |
||
| 301 | 301 | * @version 3.1.0 |
| 302 | 302 | */ |
| 303 | 303 | public function cart_scripts() { |
| 304 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 304 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 305 | 305 | return; |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 308 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 309 | 309 | |
| 310 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 310 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 311 | 311 | |
| 312 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 313 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 312 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 313 | + wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 314 | 314 | |
| 315 | 315 | $stripe_params = array( |
| 316 | 316 | 'key' => $this->publishable_key, |
| 317 | 317 | 'currency_code' => get_woocommerce_currency(), |
| 318 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 318 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 319 | 319 | 'label' => $this->statement_descriptor, |
| 320 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 321 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 322 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 323 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 324 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 325 | - 'needs_shipping' => ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no', |
|
| 320 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 321 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 322 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 323 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 324 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 325 | + 'needs_shipping' => (WC()->cart->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no', |
|
| 326 | 326 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
| 327 | 327 | ); |
| 328 | 328 | |
| 329 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
| 329 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -337,11 +337,11 @@ discard block |
||
| 337 | 337 | * @return array |
| 338 | 338 | */ |
| 339 | 339 | public function supported_product_types() { |
| 340 | - return apply_filters( 'wc_stripe_apple_pay_supported_types', array( |
|
| 340 | + return apply_filters('wc_stripe_apple_pay_supported_types', array( |
|
| 341 | 341 | 'simple', |
| 342 | 342 | 'variable', |
| 343 | 343 | 'variation', |
| 344 | - ) ); |
|
| 344 | + )); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -353,10 +353,10 @@ discard block |
||
| 353 | 353 | * @return bool |
| 354 | 354 | */ |
| 355 | 355 | public function allowed_items_in_cart() { |
| 356 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 357 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
| 356 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 357 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
| 358 | 358 | |
| 359 | - if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
| 359 | + if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
| 360 | 360 | return false; |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -377,29 +377,29 @@ discard block |
||
| 377 | 377 | * In order for the Apple Pay button to show on product detail page, |
| 378 | 378 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
| 379 | 379 | */ |
| 380 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
| 381 | - $this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
| 380 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
| 381 | + $this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
| 382 | 382 | return; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if ( is_single() ) { |
|
| 385 | + if (is_single()) { |
|
| 386 | 386 | global $post; |
| 387 | 387 | |
| 388 | - $product = wc_get_product( $post->ID ); |
|
| 388 | + $product = wc_get_product($post->ID); |
|
| 389 | 389 | |
| 390 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 390 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 391 | 391 | return; |
| 392 | 392 | } |
| 393 | 393 | } else { |
| 394 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 395 | - $this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
| 394 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 395 | + $this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
| 396 | 396 | return; |
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | ?> |
| 401 | 401 | <div class="apple-pay-button-wrapper"> |
| 402 | - <button class="apple-pay-button" lang="<?php echo esc_attr( $this->apple_pay_button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $this->apple_pay_button ); ?>;" alt="<?php esc_attr_e( 'Buy with Apple Pay', 'woocommerce-gateway-stripe' ); ?>"></button> |
|
| 402 | + <button class="apple-pay-button" lang="<?php echo esc_attr($this->apple_pay_button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($this->apple_pay_button); ?>;" alt="<?php esc_attr_e('Buy with Apple Pay', 'woocommerce-gateway-stripe'); ?>"></button> |
|
| 403 | 403 | </div> |
| 404 | 404 | <?php |
| 405 | 405 | } |
@@ -417,17 +417,17 @@ discard block |
||
| 417 | 417 | * In order for the Apple Pay button to show on cart page, |
| 418 | 418 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
| 419 | 419 | */ |
| 420 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
| 421 | - $this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
| 420 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
| 421 | + $this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
| 422 | 422 | return; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 426 | - $this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
| 425 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 426 | + $this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
| 427 | 427 | return; |
| 428 | 428 | } |
| 429 | 429 | ?> |
| 430 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
| 430 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
| 431 | 431 | <?php |
| 432 | 432 | } |
| 433 | 433 | |
@@ -438,51 +438,51 @@ discard block |
||
| 438 | 438 | * @version 3.1.0 |
| 439 | 439 | */ |
| 440 | 440 | public function generate_apple_pay_single() { |
| 441 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 442 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 441 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 442 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 446 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 445 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 446 | + define('WOOCOMMERCE_CART', true); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | WC()->shipping->reset_shipping(); |
| 450 | 450 | |
| 451 | 451 | global $post; |
| 452 | 452 | |
| 453 | - $product = wc_get_product( $post->ID ); |
|
| 454 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 453 | + $product = wc_get_product($post->ID); |
|
| 454 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 455 | 455 | |
| 456 | 456 | /** |
| 457 | 457 | * If this page is single product page, we need to simulate |
| 458 | 458 | * adding the product to the cart taken account if it is a |
| 459 | 459 | * simple or variable product. |
| 460 | 460 | */ |
| 461 | - if ( is_single() ) { |
|
| 461 | + if (is_single()) { |
|
| 462 | 462 | // First empty the cart to prevent wrong calculation. |
| 463 | 463 | WC()->cart->empty_cart(); |
| 464 | 464 | |
| 465 | - if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 466 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 465 | + if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 466 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 467 | 467 | |
| 468 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
| 469 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 468 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
| 469 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 470 | 470 | } else { |
| 471 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 472 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 471 | + $data_store = WC_Data_Store::load('product'); |
|
| 472 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 475 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) { |
|
| 479 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 478 | + if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) { |
|
| 479 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | WC()->cart->calculate_totals(); |
| 484 | 484 | |
| 485 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 485 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | /** |
@@ -492,11 +492,11 @@ discard block |
||
| 492 | 492 | * @version 3.1.0 |
| 493 | 493 | */ |
| 494 | 494 | public function generate_apple_pay_cart() { |
| 495 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 496 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 495 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 496 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 499 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -517,29 +517,29 @@ discard block |
||
| 517 | 517 | * @version 3.1.0 |
| 518 | 518 | * @param array $address |
| 519 | 519 | */ |
| 520 | - public function calculate_shipping( $address = array() ) { |
|
| 521 | - $country = strtoupper( $address['countryCode'] ); |
|
| 522 | - $state = strtoupper( $address['administrativeArea'] ); |
|
| 520 | + public function calculate_shipping($address = array()) { |
|
| 521 | + $country = strtoupper($address['countryCode']); |
|
| 522 | + $state = strtoupper($address['administrativeArea']); |
|
| 523 | 523 | $postcode = $address['postalCode']; |
| 524 | 524 | $city = $address['locality']; |
| 525 | 525 | |
| 526 | 526 | WC()->shipping->reset_shipping(); |
| 527 | 527 | |
| 528 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 529 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 530 | - } elseif ( $postcode ) { |
|
| 531 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 528 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 529 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
| 530 | + } elseif ($postcode) { |
|
| 531 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - if ( $country ) { |
|
| 535 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 536 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 534 | + if ($country) { |
|
| 535 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 536 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 537 | 537 | } else { |
| 538 | 538 | WC()->customer->set_to_base(); |
| 539 | 539 | WC()->customer->set_shipping_to_base(); |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - version_compare( WC_VERSION, '3.0', '<' ) ? WC()->customer->calculated_shipping( true ) : WC()->customer->set_calculated_shipping( true ); |
|
| 542 | + version_compare(WC_VERSION, '3.0', '<') ? WC()->customer->calculated_shipping(true) : WC()->customer->set_calculated_shipping(true); |
|
| 543 | 543 | |
| 544 | 544 | WC()->customer->save(); |
| 545 | 545 | |
@@ -563,17 +563,17 @@ discard block |
||
| 563 | 563 | $packages[0]['destination']['postcode'] = $postcode; |
| 564 | 564 | $packages[0]['destination']['city'] = $city; |
| 565 | 565 | |
| 566 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 567 | - if ( $item['data']->needs_shipping() ) { |
|
| 568 | - if ( isset( $item['line_total'] ) ) { |
|
| 566 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 567 | + if ($item['data']->needs_shipping()) { |
|
| 568 | + if (isset($item['line_total'])) { |
|
| 569 | 569 | $packages[0]['contents_cost'] += $item['line_total']; |
| 570 | 570 | } |
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 574 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 575 | 575 | |
| 576 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 576 | + WC()->shipping->calculate_shipping($packages); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -583,18 +583,18 @@ discard block |
||
| 583 | 583 | * @version 3.1.0 |
| 584 | 584 | */ |
| 585 | 585 | public function get_shipping_methods() { |
| 586 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
| 587 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 586 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
| 587 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 591 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 590 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 591 | + define('WOOCOMMERCE_CART', true); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | try { |
| 595 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
| 595 | + $address = array_map('wc_clean', $_POST['address']); |
|
| 596 | 596 | |
| 597 | - $this->calculate_shipping( $address ); |
|
| 597 | + $this->calculate_shipping($address); |
|
| 598 | 598 | |
| 599 | 599 | // Set the shipping options. |
| 600 | 600 | $currency = get_woocommerce_currency(); |
@@ -602,13 +602,13 @@ discard block |
||
| 602 | 602 | |
| 603 | 603 | $packages = WC()->shipping->get_packages(); |
| 604 | 604 | |
| 605 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 606 | - foreach ( $packages as $package_key => $package ) { |
|
| 607 | - if ( empty( $package['rates'] ) ) { |
|
| 608 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 605 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 606 | + foreach ($packages as $package_key => $package) { |
|
| 607 | + if (empty($package['rates'])) { |
|
| 608 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 611 | + foreach ($package['rates'] as $key => $rate) { |
|
| 612 | 612 | $data[] = array( |
| 613 | 613 | 'id' => $rate->id, |
| 614 | 614 | 'label' => $rate->label, |
@@ -622,16 +622,16 @@ discard block |
||
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | // Auto select the first shipping method. |
| 625 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 625 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 626 | 626 | |
| 627 | 627 | WC()->cart->calculate_totals(); |
| 628 | 628 | |
| 629 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 629 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 630 | 630 | } else { |
| 631 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 631 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 632 | 632 | } |
| 633 | - } catch ( Exception $e ) { |
|
| 634 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 633 | + } catch (Exception $e) { |
|
| 634 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | |
@@ -642,29 +642,29 @@ discard block |
||
| 642 | 642 | * @version 3.1.0 |
| 643 | 643 | */ |
| 644 | 644 | public function update_shipping_method() { |
| 645 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 646 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 645 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 646 | + define('WOOCOMMERCE_CART', true); |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
| 650 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 649 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
| 650 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
| 653 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
| 654 | 654 | |
| 655 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
| 655 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
| 656 | 656 | |
| 657 | 657 | WC()->cart->calculate_totals(); |
| 658 | 658 | |
| 659 | 659 | // Send back the new cart total. |
| 660 | 660 | $currency = get_woocommerce_currency(); |
| 661 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
| 661 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
| 662 | 662 | $data = array( |
| 663 | 663 | 'total' => WC()->cart->total, |
| 664 | 664 | ); |
| 665 | 665 | |
| 666 | 666 | // Include fees and taxes as displayItems. |
| 667 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
| 667 | + foreach (WC()->cart->fees as $key => $fee) { |
|
| 668 | 668 | $data['items'][] = array( |
| 669 | 669 | 'label' => $fee->name, |
| 670 | 670 | 'amount' => array( |
@@ -673,9 +673,9 @@ discard block |
||
| 673 | 673 | ), |
| 674 | 674 | ); |
| 675 | 675 | } |
| 676 | - if ( 0 < $tax_total ) { |
|
| 676 | + if (0 < $tax_total) { |
|
| 677 | 677 | $data['items'][] = array( |
| 678 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 678 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 679 | 679 | 'amount' => array( |
| 680 | 680 | 'currency' => $currency, |
| 681 | 681 | 'value' => $tax_total, |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | ); |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | - wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 686 | + wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
@@ -694,37 +694,37 @@ discard block |
||
| 694 | 694 | * @version 3.1.0 |
| 695 | 695 | */ |
| 696 | 696 | public function process_apple_pay() { |
| 697 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
| 698 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 697 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
| 698 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | try { |
| 702 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
| 702 | + $result = array_map('wc_clean', $_POST['result']); |
|
| 703 | 703 | |
| 704 | - $order = $this->create_order( $result ); |
|
| 704 | + $order = $this->create_order($result); |
|
| 705 | 705 | |
| 706 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 706 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 707 | 707 | |
| 708 | 708 | // Handle payment. |
| 709 | - if ( $order->get_total() > 0 ) { |
|
| 709 | + if ($order->get_total() > 0) { |
|
| 710 | 710 | |
| 711 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 712 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
| 711 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 712 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | - $this->log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
| 715 | + $this->log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
| 716 | 716 | |
| 717 | 717 | // Make the request. |
| 718 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
| 718 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
| 719 | 719 | |
| 720 | - if ( is_wp_error( $response ) ) { |
|
| 720 | + if (is_wp_error($response)) { |
|
| 721 | 721 | $localized_messages = $this->get_localized_messages(); |
| 722 | 722 | |
| 723 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
| 723 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | // Process valid response. |
| 727 | - $this->process_response( $response, $order ); |
|
| 727 | + $this->process_response($response, $order); |
|
| 728 | 728 | } else { |
| 729 | 729 | $order->payment_complete(); |
| 730 | 730 | } |
@@ -732,24 +732,24 @@ discard block |
||
| 732 | 732 | // Remove cart. |
| 733 | 733 | WC()->cart->empty_cart(); |
| 734 | 734 | |
| 735 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
| 736 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
| 735 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
| 736 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
| 737 | 737 | |
| 738 | 738 | // Return thank you page redirect. |
| 739 | - wp_send_json( array( |
|
| 739 | + wp_send_json(array( |
|
| 740 | 740 | 'success' => 'true', |
| 741 | - 'redirect' => $this->get_return_url( $order ), |
|
| 742 | - ) ); |
|
| 741 | + 'redirect' => $this->get_return_url($order), |
|
| 742 | + )); |
|
| 743 | 743 | |
| 744 | - } catch ( Exception $e ) { |
|
| 745 | - WC()->session->set( 'refresh_totals', true ); |
|
| 746 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 744 | + } catch (Exception $e) { |
|
| 745 | + WC()->session->set('refresh_totals', true); |
|
| 746 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 747 | 747 | |
| 748 | - if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 749 | - $this->send_failed_order_email( $order_id ); |
|
| 748 | + if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) { |
|
| 749 | + $this->send_failed_order_email($order_id); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
| 752 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
| 753 | 753 | } |
| 754 | 754 | } |
| 755 | 755 | |
@@ -759,16 +759,16 @@ discard block |
||
| 759 | 759 | * @param string $source token |
| 760 | 760 | * @return array() |
| 761 | 761 | */ |
| 762 | - protected function generate_payment_request( $order, $source ) { |
|
| 762 | + protected function generate_payment_request($order, $source) { |
|
| 763 | 763 | $post_data = array(); |
| 764 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
| 765 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 766 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 764 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
| 765 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 766 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 767 | 767 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
| 768 | 768 | |
| 769 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
| 769 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
| 770 | 770 | |
| 771 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 771 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 772 | 772 | $post_data['receipt_email'] = $billing_email; |
| 773 | 773 | } |
| 774 | 774 | |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | * @param WC_Order $order |
| 784 | 784 | * @param object $source |
| 785 | 785 | */ |
| 786 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
| 786 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | /** |
@@ -792,14 +792,14 @@ discard block |
||
| 792 | 792 | * @since 3.1.0 |
| 793 | 793 | * @version 3.1.0 |
| 794 | 794 | */ |
| 795 | - public function build_shipping_methods( $shipping_methods ) { |
|
| 796 | - if ( empty( $shipping_methods ) ) { |
|
| 795 | + public function build_shipping_methods($shipping_methods) { |
|
| 796 | + if (empty($shipping_methods)) { |
|
| 797 | 797 | return array(); |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | $shipping = array(); |
| 801 | 801 | |
| 802 | - foreach ( $shipping_methods as $method ) { |
|
| 802 | + foreach ($shipping_methods as $method) { |
|
| 803 | 803 | $shipping[] = array( |
| 804 | 804 | 'label' => $method['label'], |
| 805 | 805 | 'detail' => '', |
@@ -818,67 +818,67 @@ discard block |
||
| 818 | 818 | * @version 3.1.0 |
| 819 | 819 | */ |
| 820 | 820 | public function build_line_items() { |
| 821 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 822 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 821 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 822 | + define('WOOCOMMERCE_CART', true); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | - $decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 ); |
|
| 825 | + $decimals = apply_filters('wc_stripe_apple_pay_decimals', 2); |
|
| 826 | 826 | |
| 827 | 827 | $items = array(); |
| 828 | 828 | $subtotal = 0; |
| 829 | 829 | |
| 830 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 831 | - $amount = wc_format_decimal( $cart_item['line_subtotal'], $decimals ); |
|
| 832 | - $subtotal += $cart_item['line_subtotal']; |
|
| 830 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 831 | + $amount = wc_format_decimal($cart_item['line_subtotal'], $decimals); |
|
| 832 | + $subtotal += $cart_item['line_subtotal']; |
|
| 833 | 833 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
| 834 | 834 | |
| 835 | - $product_name = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
| 835 | + $product_name = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
| 836 | 836 | |
| 837 | 837 | $item = array( |
| 838 | 838 | 'type' => 'final', |
| 839 | 839 | 'label' => $product_name . $quantity_label, |
| 840 | - 'amount' => wc_format_decimal( $amount, $decimals ), |
|
| 840 | + 'amount' => wc_format_decimal($amount, $decimals), |
|
| 841 | 841 | ); |
| 842 | 842 | |
| 843 | 843 | $items[] = $item; |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | // Default show only subtotal instead of itemization. |
| 847 | - if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) { |
|
| 847 | + if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) { |
|
| 848 | 848 | $items = array(); |
| 849 | 849 | $items[] = array( |
| 850 | 850 | 'type' => 'final', |
| 851 | - 'label' => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ), |
|
| 852 | - 'amount' => wc_format_decimal( $subtotal, $decimals ), |
|
| 851 | + 'label' => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')), |
|
| 852 | + 'amount' => wc_format_decimal($subtotal, $decimals), |
|
| 853 | 853 | ); |
| 854 | 854 | } |
| 855 | 855 | |
| 856 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals ); |
|
| 857 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); |
|
| 858 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $decimals ); |
|
| 859 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts; |
|
| 860 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
| 856 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals); |
|
| 857 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals); |
|
| 858 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $decimals); |
|
| 859 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts; |
|
| 860 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
| 861 | 861 | |
| 862 | - if ( wc_tax_enabled() ) { |
|
| 862 | + if (wc_tax_enabled()) { |
|
| 863 | 863 | $items[] = array( |
| 864 | 864 | 'type' => 'final', |
| 865 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
| 865 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
| 866 | 866 | 'amount' => $tax, |
| 867 | 867 | ); |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) { |
|
| 870 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled) { |
|
| 871 | 871 | $items[] = array( |
| 872 | 872 | 'type' => 'final', |
| 873 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
| 873 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
| 874 | 874 | 'amount' => $shipping, |
| 875 | 875 | ); |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | - if ( WC()->cart->has_discount() ) { |
|
| 878 | + if (WC()->cart->has_discount()) { |
|
| 879 | 879 | $items[] = array( |
| 880 | 880 | 'type' => 'final', |
| 881 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
| 881 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
| 882 | 882 | 'amount' => '-' . $discounts, |
| 883 | 883 | ); |
| 884 | 884 | } |
@@ -894,24 +894,24 @@ discard block |
||
| 894 | 894 | * @param array $data |
| 895 | 895 | * @return object $order |
| 896 | 896 | */ |
| 897 | - public function create_order( $data = array() ) { |
|
| 898 | - if ( empty( $data ) ) { |
|
| 899 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 897 | + public function create_order($data = array()) { |
|
| 898 | + if (empty($data)) { |
|
| 899 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | $order = wc_create_order(); |
| 903 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 903 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 904 | 904 | |
| 905 | - if ( is_wp_error( $order ) ) { |
|
| 906 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 907 | - } elseif ( false === $order ) { |
|
| 908 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
| 905 | + if (is_wp_error($order)) { |
|
| 906 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 907 | + } elseif (false === $order) { |
|
| 908 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
| 909 | 909 | } else { |
| 910 | - do_action( 'woocommerce_new_order', $order_id ); |
|
| 910 | + do_action('woocommerce_new_order', $order_id); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | // Store the line items to the new/resumed order |
| 914 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 914 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 915 | 915 | $item_id = $order->add_product( |
| 916 | 916 | $values['data'], |
| 917 | 917 | $values['quantity'], |
@@ -927,25 +927,25 @@ discard block |
||
| 927 | 927 | ) |
| 928 | 928 | ); |
| 929 | 929 | |
| 930 | - if ( ! $item_id ) { |
|
| 931 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
| 930 | + if ( ! $item_id) { |
|
| 931 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | // Allow plugins to add order item meta |
| 935 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 936 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
| 935 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 936 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
| 937 | 937 | } else { |
| 938 | - do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() ); |
|
| 938 | + do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id()); |
|
| 939 | 939 | } |
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | // Store fees |
| 943 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
| 944 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 945 | - $item_id = $order->add_fee( $fee ); |
|
| 943 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
| 944 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 945 | + $item_id = $order->add_fee($fee); |
|
| 946 | 946 | } else { |
| 947 | 947 | $item = new WC_Order_Item_Fee(); |
| 948 | - $item->set_props( array( |
|
| 948 | + $item->set_props(array( |
|
| 949 | 949 | 'name' => $fee->name, |
| 950 | 950 | 'tax_class' => $fee->taxable ? $fee->tax_class : 0, |
| 951 | 951 | 'total' => $fee->amount, |
@@ -954,79 +954,79 @@ discard block |
||
| 954 | 954 | 'total' => $fee->tax_data, |
| 955 | 955 | ), |
| 956 | 956 | 'order_id' => $order->get_id(), |
| 957 | - ) ); |
|
| 957 | + )); |
|
| 958 | 958 | $item_id = $item->save(); |
| 959 | - $order->add_item( $item ); |
|
| 959 | + $order->add_item($item); |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | - if ( ! $item_id ) { |
|
| 963 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
| 962 | + if ( ! $item_id) { |
|
| 963 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | // Allow plugins to add order item meta to fees |
| 967 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 968 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
| 967 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 968 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
| 969 | 969 | } else { |
| 970 | - do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() ); |
|
| 970 | + do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id()); |
|
| 971 | 971 | } |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | // Store tax rows |
| 975 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
| 976 | - $tax_amount = WC()->cart->get_tax_amount( $tax_rate_id ); |
|
| 977 | - $shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id ); |
|
| 975 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
| 976 | + $tax_amount = WC()->cart->get_tax_amount($tax_rate_id); |
|
| 977 | + $shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id); |
|
| 978 | 978 | |
| 979 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 980 | - $item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount ); |
|
| 979 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 980 | + $item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount); |
|
| 981 | 981 | } else { |
| 982 | 982 | $item = new WC_Order_Item_Tax(); |
| 983 | - $item->set_props( array( |
|
| 983 | + $item->set_props(array( |
|
| 984 | 984 | 'rate_id' => $tax_rate_id, |
| 985 | 985 | 'tax_total' => $tax_amount, |
| 986 | 986 | 'shipping_tax_total' => $shipping_tax_amount, |
| 987 | - ) ); |
|
| 988 | - $item->set_rate( $tax_rate_id ); |
|
| 989 | - $item->set_order_id( $order->get_id() ); |
|
| 987 | + )); |
|
| 988 | + $item->set_rate($tax_rate_id); |
|
| 989 | + $item->set_order_id($order->get_id()); |
|
| 990 | 990 | $item_id = $item->save(); |
| 991 | - $order->add_item( $item ); |
|
| 991 | + $order->add_item($item); |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | - if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
| 995 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
| 994 | + if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
| 995 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
| 996 | 996 | } |
| 997 | 997 | } |
| 998 | 998 | |
| 999 | 999 | // Store coupons |
| 1000 | - $discount = WC()->cart->get_coupon_discount_amount( $code ); |
|
| 1001 | - $discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code ); |
|
| 1000 | + $discount = WC()->cart->get_coupon_discount_amount($code); |
|
| 1001 | + $discount_tax = WC()->cart->get_coupon_discount_tax_amount($code); |
|
| 1002 | 1002 | |
| 1003 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
| 1004 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 1005 | - $coupon_id = $order->add_coupon( $code, $discount, $discount_tax ); |
|
| 1003 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
| 1004 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 1005 | + $coupon_id = $order->add_coupon($code, $discount, $discount_tax); |
|
| 1006 | 1006 | } else { |
| 1007 | 1007 | $item = new WC_Order_Item_Coupon(); |
| 1008 | - $item->set_props( array( |
|
| 1008 | + $item->set_props(array( |
|
| 1009 | 1009 | 'code' => $code, |
| 1010 | 1010 | 'discount' => $discount, |
| 1011 | 1011 | 'discount_tax' => $discount_tax, |
| 1012 | 1012 | 'order_id' => $order->get_id(), |
| 1013 | - ) ); |
|
| 1013 | + )); |
|
| 1014 | 1014 | $coupon_id = $item->save(); |
| 1015 | - $order->add_item( $item ); |
|
| 1015 | + $order->add_item($item); |
|
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - if ( ! $coupon_id ) { |
|
| 1019 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
| 1018 | + if ( ! $coupon_id) { |
|
| 1019 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
| 1020 | 1020 | } |
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | // Billing address |
| 1024 | 1024 | $billing_address = array(); |
| 1025 | - if ( ! empty( $data['token']['card'] ) ) { |
|
| 1025 | + if ( ! empty($data['token']['card'])) { |
|
| 1026 | 1026 | // Name from Stripe is a full name string. |
| 1027 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
| 1028 | - $lastname = array_pop( $name ); |
|
| 1029 | - $firstname = implode( ' ', $name ); |
|
| 1027 | + $name = explode(' ', $data['token']['card']['name']); |
|
| 1028 | + $lastname = array_pop($name); |
|
| 1029 | + $firstname = implode(' ', $name); |
|
| 1030 | 1030 | $billing_address['first_name'] = $firstname; |
| 1031 | 1031 | $billing_address['last_name'] = $lastname; |
| 1032 | 1032 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | |
| 1042 | 1042 | // Shipping address. |
| 1043 | 1043 | $shipping_address = array(); |
| 1044 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty( $data['shippingContact'] ) ) { |
|
| 1044 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty($data['shippingContact'])) { |
|
| 1045 | 1045 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
| 1046 | 1046 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
| 1047 | 1047 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | $shipping_address['city'] = $data['shippingContact']['locality']; |
| 1053 | 1053 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
| 1054 | 1054 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
| 1055 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
| 1055 | + } elseif ( ! empty($data['shippingContact'])) { |
|
| 1056 | 1056 | $shipping_address['first_name'] = $firstname; |
| 1057 | 1057 | $shipping_address['last_name'] = $lastname; |
| 1058 | 1058 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1065,33 +1065,33 @@ discard block |
||
| 1065 | 1065 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | - $order->set_address( $billing_address, 'billing' ); |
|
| 1069 | - $order->set_address( $shipping_address, 'shipping' ); |
|
| 1068 | + $order->set_address($billing_address, 'billing'); |
|
| 1069 | + $order->set_address($shipping_address, 'shipping'); |
|
| 1070 | 1070 | |
| 1071 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
| 1071 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
| 1072 | 1072 | |
| 1073 | 1073 | // Get the rate object selected by user. |
| 1074 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
| 1075 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 1074 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
| 1075 | + foreach ($package['rates'] as $key => $rate) { |
|
| 1076 | 1076 | // Loop through user chosen shipping methods. |
| 1077 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
| 1078 | - if ( $method === $key ) { |
|
| 1079 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 1080 | - $order->add_shipping( $rate ); |
|
| 1077 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
| 1078 | + if ($method === $key) { |
|
| 1079 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 1080 | + $order->add_shipping($rate); |
|
| 1081 | 1081 | } else { |
| 1082 | 1082 | $item = new WC_Order_Item_Shipping(); |
| 1083 | - $item->set_props( array( |
|
| 1083 | + $item->set_props(array( |
|
| 1084 | 1084 | 'method_title' => $rate->label, |
| 1085 | 1085 | 'method_id' => $rate->id, |
| 1086 | - 'total' => wc_format_decimal( $rate->cost ), |
|
| 1086 | + 'total' => wc_format_decimal($rate->cost), |
|
| 1087 | 1087 | 'taxes' => $rate->taxes, |
| 1088 | 1088 | 'order_id' => $order->get_id(), |
| 1089 | - ) ); |
|
| 1090 | - foreach ( $rate->get_meta_data() as $key => $value ) { |
|
| 1091 | - $item->add_meta_data( $key, $value, true ); |
|
| 1089 | + )); |
|
| 1090 | + foreach ($rate->get_meta_data() as $key => $value) { |
|
| 1091 | + $item->add_meta_data($key, $value, true); |
|
| 1092 | 1092 | } |
| 1093 | 1093 | $item->save(); |
| 1094 | - $order->add_item( $item ); |
|
| 1094 | + $order->add_item($item); |
|
| 1095 | 1095 | } |
| 1096 | 1096 | } |
| 1097 | 1097 | } |
@@ -1099,27 +1099,27 @@ discard block |
||
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 1102 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
| 1102 | + $order->set_payment_method($available_gateways['stripe']); |
|
| 1103 | 1103 | |
| 1104 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 1105 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
| 1106 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
| 1107 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
| 1108 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
| 1109 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
| 1110 | - $order->set_total( WC()->cart->total ); |
|
| 1104 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 1105 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
| 1106 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
| 1107 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
| 1108 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
| 1109 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
| 1110 | + $order->set_total(WC()->cart->total); |
|
| 1111 | 1111 | } else { |
| 1112 | - $order->set_shipping_total( WC()->cart->shipping_total ); |
|
| 1113 | - $order->set_discount_total( WC()->cart->get_cart_discount_total() ); |
|
| 1114 | - $order->set_discount_tax( WC()->cart->get_cart_discount_tax_total() ); |
|
| 1115 | - $order->set_cart_tax( WC()->cart->tax_total ); |
|
| 1116 | - $order->set_shipping_tax( WC()->cart->shipping_tax_total ); |
|
| 1117 | - $order->set_total( WC()->cart->total ); |
|
| 1112 | + $order->set_shipping_total(WC()->cart->shipping_total); |
|
| 1113 | + $order->set_discount_total(WC()->cart->get_cart_discount_total()); |
|
| 1114 | + $order->set_discount_tax(WC()->cart->get_cart_discount_tax_total()); |
|
| 1115 | + $order->set_cart_tax(WC()->cart->tax_total); |
|
| 1116 | + $order->set_shipping_tax(WC()->cart->shipping_tax_total); |
|
| 1117 | + $order->set_total(WC()->cart->total); |
|
| 1118 | 1118 | $order->save(); |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | 1121 | // If we got here, the order was created without problems! |
| 1122 | - wc_transaction_query( 'commit' ); |
|
| 1122 | + wc_transaction_query('commit'); |
|
| 1123 | 1123 | |
| 1124 | 1124 | return $order; |
| 1125 | 1125 | } |
@@ -1132,9 +1132,9 @@ discard block |
||
| 1132 | 1132 | * |
| 1133 | 1133 | * @param string $message |
| 1134 | 1134 | */ |
| 1135 | - public function log( $message ) { |
|
| 1136 | - if ( $this->logging ) { |
|
| 1137 | - WC_Stripe::log( 'Apple Pay: ' . $message ); |
|
| 1135 | + public function log($message) { |
|
| 1136 | + if ($this->logging) { |
|
| 1137 | + WC_Stripe::log('Apple Pay: ' . $message); |
|
| 1138 | 1138 | } |
| 1139 | 1139 | } |
| 1140 | 1140 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @version 3.1.0 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 10 | +if ( ! defined('ABSPATH')) { |
|
| 11 | 11 | exit; |
| 12 | 12 | } |
| 13 | 13 | |
@@ -20,12 +20,12 @@ discard block |
||
| 20 | 20 | * Initialize class actions. |
| 21 | 21 | */ |
| 22 | 22 | public function __construct() { |
| 23 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
| 23 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
| 24 | 24 | |
| 25 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
| 26 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
| 27 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
| 28 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
| 25 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
| 26 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
| 27 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
| 28 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | * @return bool |
| 35 | 35 | */ |
| 36 | 36 | protected function is_activated() { |
| 37 | - $options = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 38 | - $enabled = isset( $options['enabled'] ) && 'yes' === $options['enabled']; |
|
| 39 | - $stripe_checkout = isset( $options['stripe_checkout'] ) && 'yes' !== $options['stripe_checkout']; |
|
| 40 | - $request_payment_api = isset( $options['request_payment_api'] ) && 'yes' === $options['request_payment_api']; |
|
| 37 | + $options = get_option('woocommerce_stripe_settings', array()); |
|
| 38 | + $enabled = isset($options['enabled']) && 'yes' === $options['enabled']; |
|
| 39 | + $stripe_checkout = isset($options['stripe_checkout']) && 'yes' !== $options['stripe_checkout']; |
|
| 40 | + $request_payment_api = isset($options['request_payment_api']) && 'yes' === $options['request_payment_api']; |
|
| 41 | 41 | |
| 42 | 42 | return $enabled && $stripe_checkout && $request_payment_api && is_ssl(); |
| 43 | 43 | } |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | * @return string |
| 49 | 49 | */ |
| 50 | 50 | protected function get_publishable_key() { |
| 51 | - $options = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 51 | + $options = get_option('woocommerce_stripe_settings', array()); |
|
| 52 | 52 | |
| 53 | - if ( empty( $options ) ) { |
|
| 53 | + if (empty($options)) { |
|
| 54 | 54 | return ''; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -62,39 +62,39 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function scripts() { |
| 64 | 64 | // Load PaymentRequest only on cart for now. |
| 65 | - if ( ! is_cart() ) { |
|
| 65 | + if ( ! is_cart()) { |
|
| 66 | 66 | return; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ( ! $this->is_activated() ) { |
|
| 69 | + if ( ! $this->is_activated()) { |
|
| 70 | 70 | return; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 73 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 74 | 74 | |
| 75 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 76 | - wp_enqueue_script( 'google-payment-request-shim', 'https://storage.googleapis.com/prshim/v1/payment-shim.js', '', '1.0', false ); |
|
| 77 | - wp_enqueue_script( 'wc-stripe-payment-request', plugins_url( 'assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 75 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 76 | + wp_enqueue_script('google-payment-request-shim', 'https://storage.googleapis.com/prshim/v1/payment-shim.js', '', '1.0', false); |
|
| 77 | + wp_enqueue_script('wc-stripe-payment-request', plugins_url('assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 78 | 78 | |
| 79 | 79 | wp_localize_script( |
| 80 | 80 | 'wc-stripe-payment-request', |
| 81 | 81 | 'wcStripePaymentRequestParams', |
| 82 | 82 | array( |
| 83 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 83 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 84 | 84 | 'stripe' => array( |
| 85 | 85 | 'key' => $this->get_publishable_key(), |
| 86 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
| 86 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
| 87 | 87 | ), |
| 88 | 88 | 'nonce' => array( |
| 89 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
| 90 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
| 91 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
| 92 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
| 89 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
| 90 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
| 91 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
| 92 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
| 93 | 93 | ), |
| 94 | 94 | 'i18n' => array( |
| 95 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
| 95 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
| 96 | 96 | /* translators: Do not translate the [option] placeholder */ |
| 97 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
| 97 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
| 98 | 98 | ), |
| 99 | 99 | ) |
| 100 | 100 | ); |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | * Get cart details. |
| 105 | 105 | */ |
| 106 | 106 | public function ajax_get_cart_details() { |
| 107 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
| 107 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
| 108 | 108 | |
| 109 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 110 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 109 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 110 | + define('WOOCOMMERCE_CART', true); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | WC()->cart->calculate_totals(); |
@@ -119,18 +119,18 @@ discard block |
||
| 119 | 119 | 'shipping_required' => WC()->cart->needs_shipping(), |
| 120 | 120 | 'order_data' => array( |
| 121 | 121 | 'total' => array( |
| 122 | - 'label' => __( 'Total', 'woocommerce-gateway-stripe' ), |
|
| 122 | + 'label' => __('Total', 'woocommerce-gateway-stripe'), |
|
| 123 | 123 | 'amount' => array( |
| 124 | - 'value' => max( 0, apply_filters( 'woocommerce_calculated_total', round( WC()->cart->cart_contents_total + WC()->cart->fee_total + WC()->cart->tax_total, WC()->cart->dp ), WC()->cart ) ), |
|
| 124 | + 'value' => max(0, apply_filters('woocommerce_calculated_total', round(WC()->cart->cart_contents_total + WC()->cart->fee_total + WC()->cart->tax_total, WC()->cart->dp), WC()->cart)), |
|
| 125 | 125 | 'currency' => $currency, |
| 126 | 126 | ), |
| 127 | 127 | ), |
| 128 | 128 | // Include line items such as subtotal, fees and taxes. No shipping option is provided here because it is not chosen yet. |
| 129 | - 'displayItems' => $this->compute_display_items( null ), |
|
| 129 | + 'displayItems' => $this->compute_display_items(null), |
|
| 130 | 130 | ), |
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | - wp_send_json( $data ); |
|
| 133 | + wp_send_json($data); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @version 3.1.0 |
| 141 | 141 | * @param array $address |
| 142 | 142 | */ |
| 143 | - public function calculate_shipping( $address = array() ) { |
|
| 143 | + public function calculate_shipping($address = array()) { |
|
| 144 | 144 | $country = $address['country']; |
| 145 | 145 | $state = $address['state']; |
| 146 | 146 | $postcode = $address['postcode']; |
@@ -150,19 +150,19 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | WC()->shipping->reset_shipping(); |
| 152 | 152 | |
| 153 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 154 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 153 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
| 154 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if ( $country ) { |
|
| 158 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 159 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 157 | + if ($country) { |
|
| 158 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 159 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 160 | 160 | } else { |
| 161 | 161 | WC()->customer->set_to_base(); |
| 162 | 162 | WC()->customer->set_shipping_to_base(); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - version_compare( WC_VERSION, '3.0', '<' ) ? WC()->customer->calculated_shipping( true ) : WC()->customer->set_calculated_shipping( true ); |
|
| 165 | + version_compare(WC_VERSION, '3.0', '<') ? WC()->customer->calculated_shipping(true) : WC()->customer->set_calculated_shipping(true); |
|
| 166 | 166 | |
| 167 | 167 | WC()->customer->save(); |
| 168 | 168 | |
@@ -179,17 +179,17 @@ discard block |
||
| 179 | 179 | $packages[0]['destination']['address'] = $address_1; |
| 180 | 180 | $packages[0]['destination']['address_2'] = $address_2; |
| 181 | 181 | |
| 182 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 183 | - if ( $item['data']->needs_shipping() ) { |
|
| 184 | - if ( isset( $item['line_total'] ) ) { |
|
| 182 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 183 | + if ($item['data']->needs_shipping()) { |
|
| 184 | + if (isset($item['line_total'])) { |
|
| 185 | 185 | $packages[0]['contents_cost'] += $item['line_total']; |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 190 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 191 | 191 | |
| 192 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 192 | + WC()->shipping->calculate_shipping($packages); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,19 +200,19 @@ discard block |
||
| 200 | 200 | * @see WC_Shipping::get_packages(). |
| 201 | 201 | */ |
| 202 | 202 | public function ajax_get_shipping_options() { |
| 203 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
| 203 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
| 204 | 204 | |
| 205 | 205 | // Set the shipping package. |
| 206 | - $posted = filter_input_array( INPUT_POST, array( |
|
| 206 | + $posted = filter_input_array(INPUT_POST, array( |
|
| 207 | 207 | 'country' => FILTER_SANITIZE_STRING, |
| 208 | 208 | 'state' => FILTER_SANITIZE_STRING, |
| 209 | 209 | 'postcode' => FILTER_SANITIZE_STRING, |
| 210 | 210 | 'city' => FILTER_SANITIZE_STRING, |
| 211 | 211 | 'address' => FILTER_SANITIZE_STRING, |
| 212 | 212 | 'address_2' => FILTER_SANITIZE_STRING, |
| 213 | - ) ); |
|
| 213 | + )); |
|
| 214 | 214 | |
| 215 | - $this->calculate_shipping( $posted ); |
|
| 215 | + $this->calculate_shipping($posted); |
|
| 216 | 216 | |
| 217 | 217 | // Set the shipping options. |
| 218 | 218 | $currency = get_woocommerce_currency(); |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | |
| 221 | 221 | $packages = WC()->shipping->get_packages(); |
| 222 | 222 | |
| 223 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 224 | - foreach ( $packages as $package_key => $package ) { |
|
| 225 | - if ( empty( $package['rates'] ) ) { |
|
| 223 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 224 | + foreach ($packages as $package_key => $package) { |
|
| 225 | + if (empty($package['rates'])) { |
|
| 226 | 226 | break; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 229 | + foreach ($package['rates'] as $key => $rate) { |
|
| 230 | 230 | $data[] = array( |
| 231 | 231 | 'id' => $rate->id, |
| 232 | 232 | 'label' => $rate->label, |
@@ -241,60 +241,60 @@ discard block |
||
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Auto select when have only one shipping method available. |
| 244 | - if ( 1 === count( $data ) ) { |
|
| 244 | + if (1 === count($data)) { |
|
| 245 | 245 | $data[0]['selected'] = true; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - wp_send_json( $data ); |
|
| 248 | + wp_send_json($data); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
| 252 | 252 | * Update shipping method. |
| 253 | 253 | */ |
| 254 | 254 | public function ajax_update_shipping_method() { |
| 255 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
| 255 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
| 256 | 256 | |
| 257 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 258 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 257 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 258 | + define('WOOCOMMERCE_CART', true); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 262 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 261 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 262 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 263 | 263 | |
| 264 | - if ( is_array( $shipping_method ) ) { |
|
| 265 | - foreach ( $shipping_method as $i => $value ) { |
|
| 266 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
| 264 | + if (is_array($shipping_method)) { |
|
| 265 | + foreach ($shipping_method as $i => $value) { |
|
| 266 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
| 270 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
| 271 | 271 | |
| 272 | 272 | WC()->cart->calculate_totals(); |
| 273 | 273 | |
| 274 | 274 | // Send back the new cart total and line items to be displayed, such as subtotal, shipping rate(s), fees and taxes. |
| 275 | - $data = array( |
|
| 275 | + $data = array( |
|
| 276 | 276 | 'total' => WC()->cart->total, |
| 277 | - 'items' => $this->compute_display_items( $shipping_method[0] ), |
|
| 277 | + 'items' => $this->compute_display_items($shipping_method[0]), |
|
| 278 | 278 | ); |
| 279 | 279 | |
| 280 | - wp_send_json( $data ); |
|
| 280 | + wp_send_json($data); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * Create order. |
| 285 | 285 | */ |
| 286 | 286 | public function ajax_create_order() { |
| 287 | - if ( WC()->cart->is_empty() ) { |
|
| 288 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
| 287 | + if (WC()->cart->is_empty()) { |
|
| 288 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
| 292 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 291 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
| 292 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | WC()->checkout()->process_checkout(); |
| 296 | 296 | |
| 297 | - die( 0 ); |
|
| 297 | + die(0); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -302,26 +302,26 @@ discard block |
||
| 302 | 302 | * |
| 303 | 303 | * @param string shipping_method_id If shipping method ID is provided, will include display items about shipping. |
| 304 | 304 | */ |
| 305 | - protected function compute_display_items( $shipping_method_id ) { |
|
| 305 | + protected function compute_display_items($shipping_method_id) { |
|
| 306 | 306 | $currency = get_woocommerce_currency(); |
| 307 | 307 | $items = array( |
| 308 | 308 | // Subtotal excluding tax, because taxes is a separate item, below. |
| 309 | 309 | array( |
| 310 | - 'label' => __( 'Subtotal', 'woocommerce-gateway-stripe' ), |
|
| 310 | + 'label' => __('Subtotal', 'woocommerce-gateway-stripe'), |
|
| 311 | 311 | 'amount' => array( |
| 312 | - 'value' => max( 0, round( WC()->cart->subtotal_ex_tax, WC()->cart->dp ) ), |
|
| 312 | + 'value' => max(0, round(WC()->cart->subtotal_ex_tax, WC()->cart->dp)), |
|
| 313 | 313 | 'currency' => $currency, |
| 314 | 314 | ), |
| 315 | 315 | ), |
| 316 | 316 | ); |
| 317 | 317 | // If a chosen shipping option was provided, add line item(s) for it and include the shipping tax. |
| 318 | - $tax_total = max( 0, round( WC()->cart->tax_total, WC()->cart->dp ) ); |
|
| 319 | - if ( $shipping_method_id ) { |
|
| 320 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
| 318 | + $tax_total = max(0, round(WC()->cart->tax_total, WC()->cart->dp)); |
|
| 319 | + if ($shipping_method_id) { |
|
| 320 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
| 321 | 321 | // Look through the package rates for $shipping_method_id, and when found, add a line item. |
| 322 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
| 323 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 324 | - if ( $rate->id == $shipping_method_id ) { |
|
| 322 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
| 323 | + foreach ($package['rates'] as $key => $rate) { |
|
| 324 | + if ($rate->id == $shipping_method_id) { |
|
| 325 | 325 | $items[] = array( |
| 326 | 326 | 'label' => $rate->label, |
| 327 | 327 | 'amount' => array( |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | // Include fees and taxes as display items. |
| 338 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
| 338 | + foreach (WC()->cart->fees as $key => $fee) { |
|
| 339 | 339 | $items[] = array( |
| 340 | 340 | 'label' => $fee->name, |
| 341 | 341 | 'amount' => array( |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | ); |
| 346 | 346 | } |
| 347 | 347 | // The tax total may include the shipping taxes if a shipping option is provided. |
| 348 | - if ( 0 < $tax_total ) { |
|
| 348 | + if (0 < $tax_total) { |
|
| 349 | 349 | $items[] = array( |
| 350 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 350 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 351 | 351 | 'amount' => array( |
| 352 | 352 | 'currency' => $currency, |
| 353 | 353 | 'value' => $tax_total, |