@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | public function __construct() { |
| 48 | 48 | self::$_this = $this; |
| 49 | 49 | |
| 50 | - $this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
| 50 | + $this->_gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
| 51 | 51 | |
| 52 | - $this->statement_descriptor = ! empty( $this->_gateway_settings['statement_descriptor'] ) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
| 52 | + $this->statement_descriptor = ! empty($this->_gateway_settings['statement_descriptor']) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 53 | 53 | |
| 54 | 54 | $this->init(); |
| 55 | 55 | } |
@@ -67,52 +67,52 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function init() { |
| 69 | 69 | // If Apple Pay is not enabled no need to proceed further. |
| 70 | - if ( 'yes' !== $this->_gateway_settings['apple_pay'] ) { |
|
| 70 | + if ('yes' !== $this->_gateway_settings['apple_pay']) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) ); |
|
| 75 | - add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) ); |
|
| 74 | + add_action('wp_enqueue_scripts', array($this, 'cart_scripts')); |
|
| 75 | + add_action('wp_enqueue_scripts', array($this, 'single_scripts')); |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * In order to display the Apple Pay button in the correct position, |
| 79 | 79 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
| 80 | 80 | * CSS is used to position the button. |
| 81 | 81 | */ |
| 82 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
| 83 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 82 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
| 83 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1); |
|
| 84 | 84 | } else { |
| 85 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 89 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
| 90 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 91 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
| 92 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
| 93 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
| 94 | - add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) ); |
|
| 95 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) ); |
|
| 96 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
| 97 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
| 98 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 99 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
| 85 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1); |
|
| 89 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2); |
|
| 90 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1); |
|
| 91 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2); |
|
| 92 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
| 93 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
| 94 | + add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart')); |
|
| 95 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single')); |
|
| 96 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
| 97 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
| 98 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 99 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * Filters the gateway title to reflect Apple Pay. |
| 104 | 104 | * |
| 105 | 105 | */ |
| 106 | - public function filter_gateway_title( $title, $id ) { |
|
| 106 | + public function filter_gateway_title($title, $id) { |
|
| 107 | 107 | global $post; |
| 108 | 108 | |
| 109 | - if ( ! is_object( $post ) ) { |
|
| 109 | + if ( ! is_object($post)) { |
|
| 110 | 110 | return $title; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 113 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 114 | 114 | |
| 115 | - if ( 'stripe' === $id && ! empty( $method_title ) ) { |
|
| 115 | + if ('stripe' === $id && ! empty($method_title)) { |
|
| 116 | 116 | return $method_title; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | * @since 3.1.4 |
| 126 | 126 | * @version 3.1.4 |
| 127 | 127 | */ |
| 128 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 128 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 129 | 129 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 130 | 130 | |
| 131 | 131 | if ( |
| 132 | 132 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 133 | - || ! isset( $gateways['stripe'] ) |
|
| 133 | + || ! isset($gateways['stripe']) |
|
| 134 | 134 | ) { |
| 135 | 135 | return $valid; |
| 136 | 136 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * when passing it back from the shippingcontactselected object. This causes WC to invalidate |
| 141 | 141 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 142 | 142 | */ |
| 143 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 143 | + if ('GB' === $country || 'CA' === $country) { |
|
| 144 | 144 | return true; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -154,44 +154,44 @@ discard block |
||
| 154 | 154 | * @version 3.1.4 |
| 155 | 155 | */ |
| 156 | 156 | public function single_scripts() { |
| 157 | - if ( ! is_single() ) { |
|
| 157 | + if ( ! is_single()) { |
|
| 158 | 158 | return; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | global $post; |
| 162 | 162 | |
| 163 | - $product = wc_get_product( $post->ID ); |
|
| 163 | + $product = wc_get_product($post->ID); |
|
| 164 | 164 | |
| 165 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 165 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 169 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 170 | 170 | |
| 171 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 171 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 172 | 172 | |
| 173 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 174 | - 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 ); |
|
| 173 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 174 | + 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); |
|
| 175 | 175 | |
| 176 | 176 | $publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key']; |
| 177 | 177 | |
| 178 | 178 | $stripe_params = array( |
| 179 | 179 | 'key' => $publishable_key, |
| 180 | 180 | 'currency_code' => get_woocommerce_currency(), |
| 181 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 181 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 182 | 182 | 'label' => $this->statement_descriptor, |
| 183 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 184 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 185 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 186 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 187 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 183 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 184 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 185 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 186 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 187 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 188 | 188 | 'needs_shipping' => $product->needs_shipping() ? 'yes' : 'no', |
| 189 | 189 | 'i18n' => array( |
| 190 | - 'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
| 190 | + 'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
| 191 | 191 | ), |
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | - wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) ); |
|
| 194 | + wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params)); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -201,34 +201,34 @@ discard block |
||
| 201 | 201 | * @version 3.1.0 |
| 202 | 202 | */ |
| 203 | 203 | public function cart_scripts() { |
| 204 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 204 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 208 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 209 | 209 | |
| 210 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 210 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 211 | 211 | |
| 212 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 213 | - 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 ); |
|
| 212 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 213 | + 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); |
|
| 214 | 214 | |
| 215 | 215 | $publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key']; |
| 216 | 216 | |
| 217 | 217 | $stripe_params = array( |
| 218 | 218 | 'key' => $publishable_key, |
| 219 | 219 | 'currency_code' => get_woocommerce_currency(), |
| 220 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 220 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 221 | 221 | 'label' => $this->statement_descriptor, |
| 222 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 223 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 224 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 225 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 226 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 222 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 223 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 224 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 225 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 226 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 227 | 227 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 228 | 228 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
| 229 | 229 | ); |
| 230 | 230 | |
| 231 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
| 231 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -257,26 +257,26 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | if ( |
| 259 | 259 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 260 | - || ! isset( $gateways['stripe'] ) |
|
| 260 | + || ! isset($gateways['stripe']) |
|
| 261 | 261 | ) { |
| 262 | 262 | return; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( is_single() ) { |
|
| 265 | + if (is_single()) { |
|
| 266 | 266 | global $post; |
| 267 | 267 | |
| 268 | - $product = wc_get_product( $post->ID ); |
|
| 268 | + $product = wc_get_product($post->ID); |
|
| 269 | 269 | |
| 270 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 270 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 271 | 271 | return; |
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 276 | - $button_lang = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en'; |
|
| 275 | + $apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 276 | + $button_lang = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en'; |
|
| 277 | 277 | ?> |
| 278 | 278 | <div class="apple-pay-button-wrapper"> |
| 279 | - <button class="apple-pay-button" lang="<?php echo esc_attr( $button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $apple_pay_button ); ?>;"></button> |
|
| 279 | + <button class="apple-pay-button" lang="<?php echo esc_attr($button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($apple_pay_button); ?>;"></button> |
|
| 280 | 280 | </div> |
| 281 | 281 | <?php |
| 282 | 282 | } |
@@ -296,22 +296,22 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | if ( |
| 298 | 298 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 299 | - || ! isset( $gateways['stripe'] ) |
|
| 299 | + || ! isset($gateways['stripe']) |
|
| 300 | 300 | ) { |
| 301 | 301 | return; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if ( is_single() ) { |
|
| 304 | + if (is_single()) { |
|
| 305 | 305 | global $post; |
| 306 | 306 | |
| 307 | - $product = wc_get_product( $post->ID ); |
|
| 307 | + $product = wc_get_product($post->ID); |
|
| 308 | 308 | |
| 309 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 309 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 310 | 310 | return; |
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | ?> |
| 314 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
| 314 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
| 315 | 315 | <?php |
| 316 | 316 | } |
| 317 | 317 | |
@@ -322,51 +322,51 @@ discard block |
||
| 322 | 322 | * @version 3.1.0 |
| 323 | 323 | */ |
| 324 | 324 | public function generate_apple_pay_single() { |
| 325 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 326 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 325 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 326 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 330 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 329 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 330 | + define('WOOCOMMERCE_CART', true); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | WC()->shipping->reset_shipping(); |
| 334 | 334 | |
| 335 | 335 | global $post; |
| 336 | 336 | |
| 337 | - $product = wc_get_product( $post->ID ); |
|
| 338 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 337 | + $product = wc_get_product($post->ID); |
|
| 338 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 339 | 339 | |
| 340 | 340 | /** |
| 341 | 341 | * If this page is single product page, we need to simulate |
| 342 | 342 | * adding the product to the cart taken account if it is a |
| 343 | 343 | * simple or variable product. |
| 344 | 344 | */ |
| 345 | - if ( is_single() ) { |
|
| 345 | + if (is_single()) { |
|
| 346 | 346 | // First empty the cart to prevent wrong calculation. |
| 347 | 347 | WC()->cart->empty_cart(); |
| 348 | 348 | |
| 349 | - if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 350 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 349 | + if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 350 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 351 | 351 | |
| 352 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
| 353 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 352 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
| 353 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 354 | 354 | } else { |
| 355 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 356 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 355 | + $data_store = WC_Data_Store::load('product'); |
|
| 356 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 359 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) { |
|
| 363 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 362 | + if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) { |
|
| 363 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | WC()->cart->calculate_totals(); |
| 368 | 368 | |
| 369 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 369 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * @version 3.1.0 |
| 377 | 377 | */ |
| 378 | 378 | public function generate_apple_pay_cart() { |
| 379 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 380 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 379 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 380 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 383 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -401,29 +401,29 @@ discard block |
||
| 401 | 401 | * @version 3.1.0 |
| 402 | 402 | * @param array $address |
| 403 | 403 | */ |
| 404 | - public function calculate_shipping( $address = array() ) { |
|
| 405 | - $country = strtoupper( $address['countryCode'] ); |
|
| 406 | - $state = strtoupper( $address['administrativeArea'] ); |
|
| 404 | + public function calculate_shipping($address = array()) { |
|
| 405 | + $country = strtoupper($address['countryCode']); |
|
| 406 | + $state = strtoupper($address['administrativeArea']); |
|
| 407 | 407 | $postcode = $address['postalCode']; |
| 408 | 408 | $city = $address['locality']; |
| 409 | 409 | |
| 410 | 410 | WC()->shipping->reset_shipping(); |
| 411 | 411 | |
| 412 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 413 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 414 | - } elseif ( $postcode ) { |
|
| 415 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 412 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 413 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
| 414 | + } elseif ($postcode) { |
|
| 415 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - if ( $country ) { |
|
| 419 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 420 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 418 | + if ($country) { |
|
| 419 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 420 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 421 | 421 | } else { |
| 422 | 422 | WC()->customer->set_to_base(); |
| 423 | 423 | WC()->customer->set_shipping_to_base(); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - WC()->customer->calculated_shipping( true ); |
|
| 426 | + WC()->customer->calculated_shipping(true); |
|
| 427 | 427 | |
| 428 | 428 | /** |
| 429 | 429 | * Set the shipping package. |
@@ -445,17 +445,17 @@ discard block |
||
| 445 | 445 | $packages[0]['destination']['postcode'] = $postcode; |
| 446 | 446 | $packages[0]['destination']['city'] = $city; |
| 447 | 447 | |
| 448 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 449 | - if ( $item['data']->needs_shipping() ) { |
|
| 450 | - if ( isset( $item['line_total'] ) ) { |
|
| 448 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 449 | + if ($item['data']->needs_shipping()) { |
|
| 450 | + if (isset($item['line_total'])) { |
|
| 451 | 451 | $packages[0]['contents_cost'] += $item['line_total']; |
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 456 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 457 | 457 | |
| 458 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 458 | + WC()->shipping->calculate_shipping($packages); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -465,18 +465,18 @@ discard block |
||
| 465 | 465 | * @version 3.1.0 |
| 466 | 466 | */ |
| 467 | 467 | public function get_shipping_methods() { |
| 468 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
| 469 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 468 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
| 469 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 473 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 472 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 473 | + define('WOOCOMMERCE_CART', true); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | try { |
| 477 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
| 477 | + $address = array_map('wc_clean', $_POST['address']); |
|
| 478 | 478 | |
| 479 | - $this->calculate_shipping( $address ); |
|
| 479 | + $this->calculate_shipping($address); |
|
| 480 | 480 | |
| 481 | 481 | // Set the shipping options. |
| 482 | 482 | $currency = get_woocommerce_currency(); |
@@ -484,13 +484,13 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | $packages = WC()->shipping->get_packages(); |
| 486 | 486 | |
| 487 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 488 | - foreach ( $packages as $package_key => $package ) { |
|
| 489 | - if ( empty( $package['rates'] ) ) { |
|
| 490 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 487 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 488 | + foreach ($packages as $package_key => $package) { |
|
| 489 | + if (empty($package['rates'])) { |
|
| 490 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 493 | + foreach ($package['rates'] as $key => $rate) { |
|
| 494 | 494 | $data[] = array( |
| 495 | 495 | 'id' => $rate->id, |
| 496 | 496 | 'label' => $rate->label, |
@@ -504,16 +504,16 @@ discard block |
||
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | // Auto select the first shipping method. |
| 507 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 507 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 508 | 508 | |
| 509 | 509 | WC()->cart->calculate_totals(); |
| 510 | 510 | |
| 511 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 511 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 512 | 512 | } else { |
| 513 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 513 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 514 | 514 | } |
| 515 | - } catch ( Exception $e ) { |
|
| 516 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 515 | + } catch (Exception $e) { |
|
| 516 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | |
@@ -524,29 +524,29 @@ discard block |
||
| 524 | 524 | * @version 3.1.0 |
| 525 | 525 | */ |
| 526 | 526 | public function update_shipping_method() { |
| 527 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 528 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 527 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 528 | + define('WOOCOMMERCE_CART', true); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
| 532 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 531 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
| 532 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
| 535 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
| 536 | 536 | |
| 537 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
| 537 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
| 538 | 538 | |
| 539 | 539 | WC()->cart->calculate_totals(); |
| 540 | 540 | |
| 541 | 541 | // Send back the new cart total. |
| 542 | 542 | $currency = get_woocommerce_currency(); |
| 543 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
| 543 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
| 544 | 544 | $data = array( |
| 545 | 545 | 'total' => WC()->cart->total, |
| 546 | 546 | ); |
| 547 | 547 | |
| 548 | 548 | // Include fees and taxes as displayItems. |
| 549 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
| 549 | + foreach (WC()->cart->fees as $key => $fee) { |
|
| 550 | 550 | $data['items'][] = array( |
| 551 | 551 | 'label' => $fee->name, |
| 552 | 552 | 'amount' => array( |
@@ -555,9 +555,9 @@ discard block |
||
| 555 | 555 | ), |
| 556 | 556 | ); |
| 557 | 557 | } |
| 558 | - if ( 0 < $tax_total ) { |
|
| 558 | + if (0 < $tax_total) { |
|
| 559 | 559 | $data['items'][] = array( |
| 560 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 560 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 561 | 561 | 'amount' => array( |
| 562 | 562 | 'currency' => $currency, |
| 563 | 563 | 'value' => $tax_total, |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | ); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 568 | + wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | /** |
@@ -576,37 +576,37 @@ discard block |
||
| 576 | 576 | * @version 3.1.0 |
| 577 | 577 | */ |
| 578 | 578 | public function process_apple_pay() { |
| 579 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
| 580 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 579 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
| 580 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | try { |
| 584 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
| 584 | + $result = array_map('wc_clean', $_POST['result']); |
|
| 585 | 585 | |
| 586 | - $order = $this->create_order( $result ); |
|
| 586 | + $order = $this->create_order($result); |
|
| 587 | 587 | |
| 588 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 588 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 589 | 589 | |
| 590 | 590 | // Handle payment. |
| 591 | - if ( $order->get_total() > 0 ) { |
|
| 591 | + if ($order->get_total() > 0) { |
|
| 592 | 592 | |
| 593 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 594 | - 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 ) ) ); |
|
| 593 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 594 | + 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))); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | - WC_Stripe::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
| 597 | + WC_Stripe::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
| 598 | 598 | |
| 599 | 599 | // Make the request. |
| 600 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
| 600 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
| 601 | 601 | |
| 602 | - if ( is_wp_error( $response ) ) { |
|
| 602 | + if (is_wp_error($response)) { |
|
| 603 | 603 | $localized_messages = $this->get_localized_messages(); |
| 604 | 604 | |
| 605 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
| 605 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | // Process valid response. |
| 609 | - $this->process_response( $response, $order ); |
|
| 609 | + $this->process_response($response, $order); |
|
| 610 | 610 | } else { |
| 611 | 611 | $order->payment_complete(); |
| 612 | 612 | } |
@@ -614,24 +614,24 @@ discard block |
||
| 614 | 614 | // Remove cart. |
| 615 | 615 | WC()->cart->empty_cart(); |
| 616 | 616 | |
| 617 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
| 618 | - update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) ); |
|
| 617 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
| 618 | + update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe')); |
|
| 619 | 619 | |
| 620 | 620 | // Return thank you page redirect. |
| 621 | - wp_send_json( array( |
|
| 621 | + wp_send_json(array( |
|
| 622 | 622 | 'success' => 'true', |
| 623 | - 'redirect' => $this->get_return_url( $order ), |
|
| 624 | - ) ); |
|
| 623 | + 'redirect' => $this->get_return_url($order), |
|
| 624 | + )); |
|
| 625 | 625 | |
| 626 | - } catch ( Exception $e ) { |
|
| 627 | - WC()->session->set( 'refresh_totals', true ); |
|
| 628 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 626 | + } catch (Exception $e) { |
|
| 627 | + WC()->session->set('refresh_totals', true); |
|
| 628 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 629 | 629 | |
| 630 | - if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 631 | - $this->send_failed_order_email( $order_id ); |
|
| 630 | + if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) { |
|
| 631 | + $this->send_failed_order_email($order_id); |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
| 634 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
| 635 | 635 | } |
| 636 | 636 | } |
| 637 | 637 | |
@@ -641,16 +641,16 @@ discard block |
||
| 641 | 641 | * @param string $source token |
| 642 | 642 | * @return array() |
| 643 | 643 | */ |
| 644 | - protected function generate_payment_request( $order, $source ) { |
|
| 644 | + protected function generate_payment_request($order, $source) { |
|
| 645 | 645 | $post_data = array(); |
| 646 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
| 647 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 648 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 646 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
| 647 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 648 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 649 | 649 | $post_data['capture'] = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false'; |
| 650 | 650 | |
| 651 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
| 651 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
| 652 | 652 | |
| 653 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 653 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 654 | 654 | $post_data['receipt_email'] = $billing_email; |
| 655 | 655 | } |
| 656 | 656 | |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | * @param WC_Order $order |
| 666 | 666 | * @param object $source |
| 667 | 667 | */ |
| 668 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
| 668 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -674,14 +674,14 @@ discard block |
||
| 674 | 674 | * @since 3.1.0 |
| 675 | 675 | * @version 3.1.0 |
| 676 | 676 | */ |
| 677 | - public function build_shipping_methods( $shipping_methods ) { |
|
| 678 | - if ( empty( $shipping_methods ) ) { |
|
| 677 | + public function build_shipping_methods($shipping_methods) { |
|
| 678 | + if (empty($shipping_methods)) { |
|
| 679 | 679 | return array(); |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | $shipping = array(); |
| 683 | 683 | |
| 684 | - foreach ( $shipping_methods as $method ) { |
|
| 684 | + foreach ($shipping_methods as $method) { |
|
| 685 | 685 | $shipping[] = array( |
| 686 | 686 | 'label' => $method['label'], |
| 687 | 687 | 'detail' => '', |
@@ -700,65 +700,65 @@ discard block |
||
| 700 | 700 | * @version 3.1.0 |
| 701 | 701 | */ |
| 702 | 702 | public function build_line_items() { |
| 703 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 704 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 703 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 704 | + define('WOOCOMMERCE_CART', true); |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | - $decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 ); |
|
| 707 | + $decimals = apply_filters('wc_stripe_apple_pay_decimals', 2); |
|
| 708 | 708 | |
| 709 | 709 | $items = array(); |
| 710 | 710 | $subtotal = 0; |
| 711 | 711 | |
| 712 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 713 | - $amount = wc_format_decimal( $values['line_subtotal'], $decimals ); |
|
| 714 | - $subtotal += $values['line_subtotal']; |
|
| 712 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 713 | + $amount = wc_format_decimal($values['line_subtotal'], $decimals); |
|
| 714 | + $subtotal += $values['line_subtotal']; |
|
| 715 | 715 | $quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : ''; |
| 716 | 716 | |
| 717 | 717 | $item = array( |
| 718 | 718 | 'type' => 'final', |
| 719 | 719 | 'label' => $values['data']->post->post_title . $quantity_label, |
| 720 | - 'amount' => wc_format_decimal( $amount, $decimals ), |
|
| 720 | + 'amount' => wc_format_decimal($amount, $decimals), |
|
| 721 | 721 | ); |
| 722 | 722 | |
| 723 | 723 | $items[] = $item; |
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | // Default show only subtotal instead of itemization. |
| 727 | - if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) { |
|
| 727 | + if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) { |
|
| 728 | 728 | $items = array(); |
| 729 | 729 | $items[] = array( |
| 730 | 730 | 'type' => 'final', |
| 731 | - 'label' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
| 732 | - 'amount' => wc_format_decimal( $subtotal, $decimals ), |
|
| 731 | + 'label' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
| 732 | + 'amount' => wc_format_decimal($subtotal, $decimals), |
|
| 733 | 733 | ); |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals ); |
|
| 737 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); |
|
| 738 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $decimals ); |
|
| 739 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts; |
|
| 740 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
| 736 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals); |
|
| 737 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals); |
|
| 738 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $decimals); |
|
| 739 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts; |
|
| 740 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
| 741 | 741 | |
| 742 | - if ( wc_tax_enabled() ) { |
|
| 742 | + if (wc_tax_enabled()) { |
|
| 743 | 743 | $items[] = array( |
| 744 | 744 | 'type' => 'final', |
| 745 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 745 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 746 | 746 | 'amount' => $tax, |
| 747 | 747 | ); |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - if ( WC()->cart->needs_shipping() ) { |
|
| 750 | + if (WC()->cart->needs_shipping()) { |
|
| 751 | 751 | $items[] = array( |
| 752 | 752 | 'type' => 'final', |
| 753 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 753 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 754 | 754 | 'amount' => $shipping, |
| 755 | 755 | ); |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - if ( WC()->cart->has_discount() ) { |
|
| 758 | + if (WC()->cart->has_discount()) { |
|
| 759 | 759 | $items[] = array( |
| 760 | 760 | 'type' => 'final', |
| 761 | - 'label' => __( 'Discount', 'woocommerce-gateway-stripe' ), |
|
| 761 | + 'label' => __('Discount', 'woocommerce-gateway-stripe'), |
|
| 762 | 762 | 'amount' => '-' . $discounts, |
| 763 | 763 | ); |
| 764 | 764 | } |
@@ -774,24 +774,24 @@ discard block |
||
| 774 | 774 | * @param array $data |
| 775 | 775 | * @return object $order |
| 776 | 776 | */ |
| 777 | - public function create_order( $data = array() ) { |
|
| 778 | - if ( empty( $data ) ) { |
|
| 779 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 777 | + public function create_order($data = array()) { |
|
| 778 | + if (empty($data)) { |
|
| 779 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | $order = wc_create_order(); |
| 783 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 783 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 784 | 784 | |
| 785 | - if ( is_wp_error( $order ) ) { |
|
| 786 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 787 | - } elseif ( false === $order ) { |
|
| 788 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
| 785 | + if (is_wp_error($order)) { |
|
| 786 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 787 | + } elseif (false === $order) { |
|
| 788 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
| 789 | 789 | } else { |
| 790 | - do_action( 'woocommerce_new_order', $order_id ); |
|
| 790 | + do_action('woocommerce_new_order', $order_id); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // Store the line items to the new/resumed order |
| 794 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 794 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 795 | 795 | $item_id = $order->add_product( |
| 796 | 796 | $values['data'], |
| 797 | 797 | $values['quantity'], |
@@ -807,25 +807,25 @@ discard block |
||
| 807 | 807 | ) |
| 808 | 808 | ); |
| 809 | 809 | |
| 810 | - if ( ! $item_id ) { |
|
| 811 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
| 810 | + if ( ! $item_id) { |
|
| 811 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | // Allow plugins to add order item meta |
| 815 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 816 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
| 815 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 816 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
| 817 | 817 | } else { |
| 818 | - do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() ); |
|
| 818 | + do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id()); |
|
| 819 | 819 | } |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | // Store fees |
| 823 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
| 824 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 825 | - $item_id = $order->add_fee( $fee ); |
|
| 823 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
| 824 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 825 | + $item_id = $order->add_fee($fee); |
|
| 826 | 826 | } else { |
| 827 | 827 | $item = new WC_Order_Item_Fee(); |
| 828 | - $item->set_props( array( |
|
| 828 | + $item->set_props(array( |
|
| 829 | 829 | 'name' => $fee->name, |
| 830 | 830 | 'tax_class' => $fee->taxable ? $fee->tax_class : 0, |
| 831 | 831 | 'total' => $fee->amount, |
@@ -834,79 +834,79 @@ discard block |
||
| 834 | 834 | 'total' => $fee->tax_data, |
| 835 | 835 | ), |
| 836 | 836 | 'order_id' => $order->get_id(), |
| 837 | - ) ); |
|
| 837 | + )); |
|
| 838 | 838 | $item_id = $item->save(); |
| 839 | - $order->add_item( $item ); |
|
| 839 | + $order->add_item($item); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | - if ( ! $item_id ) { |
|
| 843 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
| 842 | + if ( ! $item_id) { |
|
| 843 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | // Allow plugins to add order item meta to fees |
| 847 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 848 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
| 847 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 848 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
| 849 | 849 | } else { |
| 850 | - do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() ); |
|
| 850 | + do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id()); |
|
| 851 | 851 | } |
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | // Store tax rows |
| 855 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
| 856 | - $tax_amount = WC()->cart->get_tax_amount( $tax_rate_id ); |
|
| 857 | - $shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id ); |
|
| 855 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
| 856 | + $tax_amount = WC()->cart->get_tax_amount($tax_rate_id); |
|
| 857 | + $shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id); |
|
| 858 | 858 | |
| 859 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 860 | - $item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount ); |
|
| 859 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 860 | + $item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount); |
|
| 861 | 861 | } else { |
| 862 | 862 | $item = new WC_Order_Item_Tax(); |
| 863 | - $item->set_props( array( |
|
| 863 | + $item->set_props(array( |
|
| 864 | 864 | 'rate_id' => $tax_rate_id, |
| 865 | 865 | 'tax_total' => $tax_amount, |
| 866 | 866 | 'shipping_tax_total' => $shipping_tax_amount, |
| 867 | - ) ); |
|
| 868 | - $item->set_rate( $tax_rate_id ); |
|
| 869 | - $item->set_order_id( $order->get_id() ); |
|
| 867 | + )); |
|
| 868 | + $item->set_rate($tax_rate_id); |
|
| 869 | + $item->set_order_id($order->get_id()); |
|
| 870 | 870 | $item_id = $item->save(); |
| 871 | - $order->add_item( $item ); |
|
| 871 | + $order->add_item($item); |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | - if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
| 875 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
| 874 | + if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
| 875 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
| 876 | 876 | } |
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | // Store coupons |
| 880 | - $discount = WC()->cart->get_coupon_discount_amount( $code ); |
|
| 881 | - $discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code ); |
|
| 880 | + $discount = WC()->cart->get_coupon_discount_amount($code); |
|
| 881 | + $discount_tax = WC()->cart->get_coupon_discount_tax_amount($code); |
|
| 882 | 882 | |
| 883 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
| 884 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 885 | - $coupon_id = $order->add_coupon( $code, $discount, $discount_tax ); |
|
| 883 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
| 884 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 885 | + $coupon_id = $order->add_coupon($code, $discount, $discount_tax); |
|
| 886 | 886 | } else { |
| 887 | 887 | $item = new WC_Order_Item_Coupon(); |
| 888 | - $item->set_props( array( |
|
| 888 | + $item->set_props(array( |
|
| 889 | 889 | 'code' => $code, |
| 890 | 890 | 'discount' => $discount, |
| 891 | 891 | 'discount_tax' => $discount_tax, |
| 892 | 892 | 'order_id' => $order->get_id(), |
| 893 | - ) ); |
|
| 893 | + )); |
|
| 894 | 894 | $coupon_id = $item->save(); |
| 895 | - $order->add_item( $item ); |
|
| 895 | + $order->add_item($item); |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - if ( ! $coupon_id ) { |
|
| 899 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
| 898 | + if ( ! $coupon_id) { |
|
| 899 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
| 900 | 900 | } |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | // Billing address |
| 904 | 904 | $billing_address = array(); |
| 905 | - if ( ! empty( $data['token']['card'] ) ) { |
|
| 905 | + if ( ! empty($data['token']['card'])) { |
|
| 906 | 906 | // Name from Stripe is a full name string. |
| 907 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
| 908 | - $lastname = array_pop( $name ); |
|
| 909 | - $firstname = implode( ' ', $name ); |
|
| 907 | + $name = explode(' ', $data['token']['card']['name']); |
|
| 908 | + $lastname = array_pop($name); |
|
| 909 | + $firstname = implode(' ', $name); |
|
| 910 | 910 | $billing_address['first_name'] = $firstname; |
| 911 | 911 | $billing_address['last_name'] = $lastname; |
| 912 | 912 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | |
| 922 | 922 | // Shipping address. |
| 923 | 923 | $shipping_address = array(); |
| 924 | - if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) { |
|
| 924 | + if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) { |
|
| 925 | 925 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
| 926 | 926 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
| 927 | 927 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -932,7 +932,7 @@ discard block |
||
| 932 | 932 | $shipping_address['city'] = $data['shippingContact']['locality']; |
| 933 | 933 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
| 934 | 934 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
| 935 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
| 935 | + } elseif ( ! empty($data['shippingContact'])) { |
|
| 936 | 936 | $shipping_address['first_name'] = $firstname; |
| 937 | 937 | $shipping_address['last_name'] = $lastname; |
| 938 | 938 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -945,33 +945,33 @@ discard block |
||
| 945 | 945 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
| 946 | 946 | } |
| 947 | 947 | |
| 948 | - $order->set_address( $billing_address, 'billing' ); |
|
| 949 | - $order->set_address( $shipping_address, 'shipping' ); |
|
| 948 | + $order->set_address($billing_address, 'billing'); |
|
| 949 | + $order->set_address($shipping_address, 'shipping'); |
|
| 950 | 950 | |
| 951 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
| 951 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
| 952 | 952 | |
| 953 | 953 | // Get the rate object selected by user. |
| 954 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
| 955 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 954 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
| 955 | + foreach ($package['rates'] as $key => $rate) { |
|
| 956 | 956 | // Loop through user chosen shipping methods. |
| 957 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
| 958 | - if ( $method === $key ) { |
|
| 959 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 960 | - $order->add_shipping( $rate ); |
|
| 957 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
| 958 | + if ($method === $key) { |
|
| 959 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 960 | + $order->add_shipping($rate); |
|
| 961 | 961 | } else { |
| 962 | 962 | $item = new WC_Order_Item_Shipping(); |
| 963 | - $item->set_props( array( |
|
| 963 | + $item->set_props(array( |
|
| 964 | 964 | 'method_title' => $rate->label, |
| 965 | 965 | 'method_id' => $rate->id, |
| 966 | - 'total' => wc_format_decimal( $rate->cost ), |
|
| 966 | + 'total' => wc_format_decimal($rate->cost), |
|
| 967 | 967 | 'taxes' => $rate->taxes, |
| 968 | 968 | 'order_id' => $order->get_id(), |
| 969 | - ) ); |
|
| 970 | - foreach ( $rate->get_meta_data() as $key => $value ) { |
|
| 971 | - $item->add_meta_data( $key, $value, true ); |
|
| 969 | + )); |
|
| 970 | + foreach ($rate->get_meta_data() as $key => $value) { |
|
| 971 | + $item->add_meta_data($key, $value, true); |
|
| 972 | 972 | } |
| 973 | 973 | $item->save(); |
| 974 | - $order->add_item( $item ); |
|
| 974 | + $order->add_item($item); |
|
| 975 | 975 | } |
| 976 | 976 | } |
| 977 | 977 | } |
@@ -979,16 +979,16 @@ discard block |
||
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 982 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
| 983 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
| 984 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
| 985 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
| 986 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
| 987 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
| 988 | - $order->set_total( WC()->cart->total ); |
|
| 982 | + $order->set_payment_method($available_gateways['stripe']); |
|
| 983 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
| 984 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
| 985 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
| 986 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
| 987 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
| 988 | + $order->set_total(WC()->cart->total); |
|
| 989 | 989 | |
| 990 | 990 | // If we got here, the order was created without problems! |
| 991 | - wc_transaction_query( 'commit' ); |
|
| 991 | + wc_transaction_query('commit'); |
|
| 992 | 992 | |
| 993 | 993 | return $order; |
| 994 | 994 | } |