@@ -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,50 +67,50 @@ 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_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) ); |
|
| 95 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
| 96 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
| 97 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 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_generate_apple_pay_single', array($this, 'generate_apple_pay_single')); |
|
| 95 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
| 96 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
| 97 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * Filters the gateway title to reflect Apple Pay. |
| 102 | 102 | * |
| 103 | 103 | */ |
| 104 | - public function filter_gateway_title( $title, $id ) { |
|
| 104 | + public function filter_gateway_title($title, $id) { |
|
| 105 | 105 | global $post; |
| 106 | 106 | |
| 107 | - if ( ! is_object( $post ) ) { |
|
| 107 | + if ( ! is_object($post)) { |
|
| 108 | 108 | return $title; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 111 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 112 | 112 | |
| 113 | - if ( 'stripe' === $id && ! empty( $method_title ) ) { |
|
| 113 | + if ('stripe' === $id && ! empty($method_title)) { |
|
| 114 | 114 | return $method_title; |
| 115 | 115 | } |
| 116 | 116 | |
@@ -124,44 +124,44 @@ discard block |
||
| 124 | 124 | * @version 3.1.0 |
| 125 | 125 | */ |
| 126 | 126 | public function single_scripts() { |
| 127 | - if ( ! is_single() ) { |
|
| 127 | + if ( ! is_single()) { |
|
| 128 | 128 | return; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | global $post; |
| 132 | 132 | |
| 133 | - $product = wc_get_product( $post->ID ); |
|
| 133 | + $product = wc_get_product($post->ID); |
|
| 134 | 134 | |
| 135 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 135 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 139 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 140 | 140 | |
| 141 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 141 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 142 | 142 | |
| 143 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 144 | - 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 ); |
|
| 143 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 144 | + 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); |
|
| 145 | 145 | |
| 146 | 146 | $publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key']; |
| 147 | 147 | |
| 148 | 148 | $stripe_params = array( |
| 149 | 149 | 'key' => $publishable_key, |
| 150 | 150 | 'currency_code' => get_woocommerce_currency(), |
| 151 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 151 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 152 | 152 | 'label' => $this->statement_descriptor, |
| 153 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 154 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 155 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 156 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 157 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 153 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 154 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 155 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 156 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 157 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 158 | 158 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 159 | 159 | 'i18n' => array( |
| 160 | - 'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
| 160 | + 'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
| 161 | 161 | ), |
| 162 | 162 | ); |
| 163 | 163 | |
| 164 | - wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) ); |
|
| 164 | + wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params)); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -171,34 +171,34 @@ discard block |
||
| 171 | 171 | * @version 3.1.0 |
| 172 | 172 | */ |
| 173 | 173 | public function cart_scripts() { |
| 174 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 174 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 175 | 175 | return; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 178 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 179 | 179 | |
| 180 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 180 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 181 | 181 | |
| 182 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 183 | - 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 ); |
|
| 182 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 183 | + 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); |
|
| 184 | 184 | |
| 185 | 185 | $publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key']; |
| 186 | 186 | |
| 187 | 187 | $stripe_params = array( |
| 188 | 188 | 'key' => $publishable_key, |
| 189 | 189 | 'currency_code' => get_woocommerce_currency(), |
| 190 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 190 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 191 | 191 | 'label' => $this->statement_descriptor, |
| 192 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 193 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 194 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 195 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 196 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 192 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 193 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 194 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 195 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 196 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 197 | 197 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 198 | 198 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
| 199 | 199 | ); |
| 200 | 200 | |
| 201 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
| 201 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -227,26 +227,26 @@ discard block |
||
| 227 | 227 | */ |
| 228 | 228 | if ( |
| 229 | 229 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 230 | - || ! isset( $gateways['stripe'] ) |
|
| 230 | + || ! isset($gateways['stripe']) |
|
| 231 | 231 | ) { |
| 232 | 232 | return; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if ( is_single() ) { |
|
| 235 | + if (is_single()) { |
|
| 236 | 236 | global $post; |
| 237 | 237 | |
| 238 | - $product = wc_get_product( $post->ID ); |
|
| 238 | + $product = wc_get_product($post->ID); |
|
| 239 | 239 | |
| 240 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 240 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - $apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 246 | - $button_lang = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en'; |
|
| 245 | + $apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 246 | + $button_lang = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en'; |
|
| 247 | 247 | ?> |
| 248 | 248 | <div class="apple-pay-button-wrapper"> |
| 249 | - <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> |
|
| 249 | + <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> |
|
| 250 | 250 | </div> |
| 251 | 251 | <?php |
| 252 | 252 | } |
@@ -266,22 +266,22 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | if ( |
| 268 | 268 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 269 | - || ! isset( $gateways['stripe'] ) |
|
| 269 | + || ! isset($gateways['stripe']) |
|
| 270 | 270 | ) { |
| 271 | 271 | return; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if ( is_single() ) { |
|
| 274 | + if (is_single()) { |
|
| 275 | 275 | global $post; |
| 276 | 276 | |
| 277 | - $product = wc_get_product( $post->ID ); |
|
| 277 | + $product = wc_get_product($post->ID); |
|
| 278 | 278 | |
| 279 | - if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 279 | + if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | ?> |
| 284 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
| 284 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
| 285 | 285 | <?php |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,51 +292,51 @@ discard block |
||
| 292 | 292 | * @version 3.1.0 |
| 293 | 293 | */ |
| 294 | 294 | public function generate_apple_pay_single() { |
| 295 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 296 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 295 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 296 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 300 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 299 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 300 | + define('WOOCOMMERCE_CART', true); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | WC()->shipping->reset_shipping(); |
| 304 | 304 | |
| 305 | 305 | global $post; |
| 306 | 306 | |
| 307 | - $product = wc_get_product( $post->ID ); |
|
| 308 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 307 | + $product = wc_get_product($post->ID); |
|
| 308 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | 311 | * If this page is single product page, we need to simulate |
| 312 | 312 | * adding the product to the cart taken account if it is a |
| 313 | 313 | * simple or variable product. |
| 314 | 314 | */ |
| 315 | - if ( is_single() ) { |
|
| 315 | + if (is_single()) { |
|
| 316 | 316 | // First empty the cart to prevent wrong calculation. |
| 317 | 317 | WC()->cart->empty_cart(); |
| 318 | 318 | |
| 319 | - if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 320 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 319 | + if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 320 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 321 | 321 | |
| 322 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
| 323 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 322 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
| 323 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 324 | 324 | } else { |
| 325 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 326 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 325 | + $data_store = WC_Data_Store::load('product'); |
|
| 326 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 329 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) { |
|
| 333 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 332 | + if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) { |
|
| 333 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | WC()->cart->calculate_totals(); |
| 338 | 338 | |
| 339 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 339 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -346,11 +346,11 @@ discard block |
||
| 346 | 346 | * @version 3.1.0 |
| 347 | 347 | */ |
| 348 | 348 | public function generate_apple_pay_cart() { |
| 349 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 350 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 349 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 350 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 353 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -360,29 +360,29 @@ discard block |
||
| 360 | 360 | * @version 3.1.0 |
| 361 | 361 | * @param array $address |
| 362 | 362 | */ |
| 363 | - public function calculate_shipping( $address = array() ) { |
|
| 364 | - $country = strtoupper( $address['countryCode'] ); |
|
| 365 | - $state = strtoupper( $address['administrativeArea'] ); |
|
| 363 | + public function calculate_shipping($address = array()) { |
|
| 364 | + $country = strtoupper($address['countryCode']); |
|
| 365 | + $state = strtoupper($address['administrativeArea']); |
|
| 366 | 366 | $postcode = $address['postalCode']; |
| 367 | 367 | $city = $address['locality']; |
| 368 | 368 | |
| 369 | 369 | WC()->shipping->reset_shipping(); |
| 370 | 370 | |
| 371 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 372 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 373 | - } elseif ( $postcode ) { |
|
| 374 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 371 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 372 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
| 373 | + } elseif ($postcode) { |
|
| 374 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if ( $country ) { |
|
| 378 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 379 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 377 | + if ($country) { |
|
| 378 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 379 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 380 | 380 | } else { |
| 381 | 381 | WC()->customer->set_to_base(); |
| 382 | 382 | WC()->customer->set_shipping_to_base(); |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - WC()->customer->calculated_shipping( true ); |
|
| 385 | + WC()->customer->calculated_shipping(true); |
|
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | 388 | * Set the shipping package. |
@@ -404,17 +404,17 @@ discard block |
||
| 404 | 404 | $packages[0]['destination']['postcode'] = $postcode; |
| 405 | 405 | $packages[0]['destination']['city'] = $city; |
| 406 | 406 | |
| 407 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 408 | - if ( $item['data']->needs_shipping() ) { |
|
| 409 | - if ( isset( $item['line_total'] ) ) { |
|
| 407 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 408 | + if ($item['data']->needs_shipping()) { |
|
| 409 | + if (isset($item['line_total'])) { |
|
| 410 | 410 | $packages[0]['contents_cost'] += $item['line_total']; |
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 415 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 416 | 416 | |
| 417 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 417 | + WC()->shipping->calculate_shipping($packages); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -424,18 +424,18 @@ discard block |
||
| 424 | 424 | * @version 3.1.0 |
| 425 | 425 | */ |
| 426 | 426 | public function get_shipping_methods() { |
| 427 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
| 428 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 427 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
| 428 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 432 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 431 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 432 | + define('WOOCOMMERCE_CART', true); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | try { |
| 436 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
| 436 | + $address = array_map('wc_clean', $_POST['address']); |
|
| 437 | 437 | |
| 438 | - $this->calculate_shipping( $address ); |
|
| 438 | + $this->calculate_shipping($address); |
|
| 439 | 439 | |
| 440 | 440 | // Set the shipping options. |
| 441 | 441 | $currency = get_woocommerce_currency(); |
@@ -443,13 +443,13 @@ discard block |
||
| 443 | 443 | |
| 444 | 444 | $packages = WC()->shipping->get_packages(); |
| 445 | 445 | |
| 446 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 447 | - foreach ( $packages as $package_key => $package ) { |
|
| 448 | - if ( empty( $package['rates'] ) ) { |
|
| 449 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 446 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 447 | + foreach ($packages as $package_key => $package) { |
|
| 448 | + if (empty($package['rates'])) { |
|
| 449 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 452 | + foreach ($package['rates'] as $key => $rate) { |
|
| 453 | 453 | $data[] = array( |
| 454 | 454 | 'id' => $rate->id, |
| 455 | 455 | 'label' => $rate->label, |
@@ -463,16 +463,16 @@ discard block |
||
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | // Auto select the first shipping method. |
| 466 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 466 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 467 | 467 | |
| 468 | 468 | WC()->cart->calculate_totals(); |
| 469 | 469 | |
| 470 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 470 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 471 | 471 | } else { |
| 472 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 472 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 473 | 473 | } |
| 474 | - } catch ( Exception $e ) { |
|
| 475 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 474 | + } catch (Exception $e) { |
|
| 475 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | |
@@ -483,29 +483,29 @@ discard block |
||
| 483 | 483 | * @version 3.1.0 |
| 484 | 484 | */ |
| 485 | 485 | public function update_shipping_method() { |
| 486 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 487 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 486 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 487 | + define('WOOCOMMERCE_CART', true); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
| 491 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 490 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
| 491 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
| 494 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
| 495 | 495 | |
| 496 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
| 496 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
| 497 | 497 | |
| 498 | 498 | WC()->cart->calculate_totals(); |
| 499 | 499 | |
| 500 | 500 | // Send back the new cart total. |
| 501 | 501 | $currency = get_woocommerce_currency(); |
| 502 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
| 502 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
| 503 | 503 | $data = array( |
| 504 | 504 | 'total' => WC()->cart->total, |
| 505 | 505 | ); |
| 506 | 506 | |
| 507 | 507 | // Include fees and taxes as displayItems. |
| 508 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
| 508 | + foreach (WC()->cart->fees as $key => $fee) { |
|
| 509 | 509 | $data['items'][] = array( |
| 510 | 510 | 'label' => $fee->name, |
| 511 | 511 | 'amount' => array( |
@@ -514,9 +514,9 @@ discard block |
||
| 514 | 514 | ), |
| 515 | 515 | ); |
| 516 | 516 | } |
| 517 | - if ( 0 < $tax_total ) { |
|
| 517 | + if (0 < $tax_total) { |
|
| 518 | 518 | $data['items'][] = array( |
| 519 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 519 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 520 | 520 | 'amount' => array( |
| 521 | 521 | 'currency' => $currency, |
| 522 | 522 | 'value' => $tax_total, |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | ); |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 527 | + wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -535,37 +535,37 @@ discard block |
||
| 535 | 535 | * @version 3.1.0 |
| 536 | 536 | */ |
| 537 | 537 | public function process_apple_pay() { |
| 538 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
| 539 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 538 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
| 539 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | try { |
| 543 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
| 543 | + $result = array_map('wc_clean', $_POST['result']); |
|
| 544 | 544 | |
| 545 | - $order = $this->create_order( $result ); |
|
| 545 | + $order = $this->create_order($result); |
|
| 546 | 546 | |
| 547 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 547 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 548 | 548 | |
| 549 | 549 | // Handle payment. |
| 550 | - if ( $order->get_total() > 0 ) { |
|
| 550 | + if ($order->get_total() > 0) { |
|
| 551 | 551 | |
| 552 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 553 | - 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 ) ) ); |
|
| 552 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 553 | + 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))); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - WC_Stripe::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
| 556 | + WC_Stripe::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
| 557 | 557 | |
| 558 | 558 | // Make the request. |
| 559 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
| 559 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
| 560 | 560 | |
| 561 | - if ( is_wp_error( $response ) ) { |
|
| 561 | + if (is_wp_error($response)) { |
|
| 562 | 562 | $localized_messages = $this->get_localized_messages(); |
| 563 | 563 | |
| 564 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
| 564 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | // Process valid response. |
| 568 | - $this->process_response( $response, $order ); |
|
| 568 | + $this->process_response($response, $order); |
|
| 569 | 569 | } else { |
| 570 | 570 | $order->payment_complete(); |
| 571 | 571 | } |
@@ -573,24 +573,24 @@ discard block |
||
| 573 | 573 | // Remove cart. |
| 574 | 574 | WC()->cart->empty_cart(); |
| 575 | 575 | |
| 576 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
| 577 | - update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) ); |
|
| 576 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
| 577 | + update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe')); |
|
| 578 | 578 | |
| 579 | 579 | // Return thank you page redirect. |
| 580 | - wp_send_json( array( |
|
| 580 | + wp_send_json(array( |
|
| 581 | 581 | 'success' => 'true', |
| 582 | - 'redirect' => $this->get_return_url( $order ), |
|
| 583 | - ) ); |
|
| 582 | + 'redirect' => $this->get_return_url($order), |
|
| 583 | + )); |
|
| 584 | 584 | |
| 585 | - } catch ( Exception $e ) { |
|
| 586 | - WC()->session->set( 'refresh_totals', true ); |
|
| 587 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 585 | + } catch (Exception $e) { |
|
| 586 | + WC()->session->set('refresh_totals', true); |
|
| 587 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 588 | 588 | |
| 589 | - if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 590 | - $this->send_failed_order_email( $order_id ); |
|
| 589 | + if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) { |
|
| 590 | + $this->send_failed_order_email($order_id); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
| 593 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | |
@@ -600,16 +600,16 @@ discard block |
||
| 600 | 600 | * @param string $source token |
| 601 | 601 | * @return array() |
| 602 | 602 | */ |
| 603 | - protected function generate_payment_request( $order, $source ) { |
|
| 603 | + protected function generate_payment_request($order, $source) { |
|
| 604 | 604 | $post_data = array(); |
| 605 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
| 606 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 607 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 605 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
| 606 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 607 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 608 | 608 | $post_data['capture'] = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false'; |
| 609 | 609 | |
| 610 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
| 610 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
| 611 | 611 | |
| 612 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 612 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 613 | 613 | $post_data['receipt_email'] = $billing_email; |
| 614 | 614 | } |
| 615 | 615 | |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | * @param WC_Order $order |
| 625 | 625 | * @param object $source |
| 626 | 626 | */ |
| 627 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
| 627 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | /** |
@@ -633,14 +633,14 @@ discard block |
||
| 633 | 633 | * @since 3.1.0 |
| 634 | 634 | * @version 3.1.0 |
| 635 | 635 | */ |
| 636 | - public function build_shipping_methods( $shipping_methods ) { |
|
| 637 | - if ( empty( $shipping_methods ) ) { |
|
| 636 | + public function build_shipping_methods($shipping_methods) { |
|
| 637 | + if (empty($shipping_methods)) { |
|
| 638 | 638 | return array(); |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | $shipping = array(); |
| 642 | 642 | |
| 643 | - foreach ( $shipping_methods as $method ) { |
|
| 643 | + foreach ($shipping_methods as $method) { |
|
| 644 | 644 | $shipping[] = array( |
| 645 | 645 | 'label' => $method['label'], |
| 646 | 646 | 'detail' => '', |
@@ -659,65 +659,65 @@ discard block |
||
| 659 | 659 | * @version 3.1.0 |
| 660 | 660 | */ |
| 661 | 661 | public function build_line_items() { |
| 662 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 663 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 662 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 663 | + define('WOOCOMMERCE_CART', true); |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - $decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 ); |
|
| 666 | + $decimals = apply_filters('wc_stripe_apple_pay_decimals', 2); |
|
| 667 | 667 | |
| 668 | 668 | $items = array(); |
| 669 | 669 | $subtotal = 0; |
| 670 | 670 | |
| 671 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 672 | - $amount = wc_format_decimal( $values['line_subtotal'], $decimals ); |
|
| 673 | - $subtotal += $values['line_subtotal']; |
|
| 671 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 672 | + $amount = wc_format_decimal($values['line_subtotal'], $decimals); |
|
| 673 | + $subtotal += $values['line_subtotal']; |
|
| 674 | 674 | $quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : ''; |
| 675 | 675 | |
| 676 | 676 | $item = array( |
| 677 | 677 | 'type' => 'final', |
| 678 | 678 | 'label' => $values['data']->post->post_title . $quantity_label, |
| 679 | - 'amount' => wc_format_decimal( $amount, $decimals ), |
|
| 679 | + 'amount' => wc_format_decimal($amount, $decimals), |
|
| 680 | 680 | ); |
| 681 | 681 | |
| 682 | 682 | $items[] = $item; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | // Default show only subtotal instead of itemization. |
| 686 | - if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) { |
|
| 686 | + if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) { |
|
| 687 | 687 | $items = array(); |
| 688 | 688 | $items[] = array( |
| 689 | 689 | 'type' => 'final', |
| 690 | - 'label' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
| 691 | - 'amount' => wc_format_decimal( $subtotal, $decimals ), |
|
| 690 | + 'label' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
| 691 | + 'amount' => wc_format_decimal($subtotal, $decimals), |
|
| 692 | 692 | ); |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals ); |
|
| 696 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); |
|
| 697 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $decimals ); |
|
| 698 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts; |
|
| 699 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
| 695 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals); |
|
| 696 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals); |
|
| 697 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $decimals); |
|
| 698 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts; |
|
| 699 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
| 700 | 700 | |
| 701 | - if ( wc_tax_enabled() ) { |
|
| 701 | + if (wc_tax_enabled()) { |
|
| 702 | 702 | $items[] = array( |
| 703 | 703 | 'type' => 'final', |
| 704 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 704 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 705 | 705 | 'amount' => $tax, |
| 706 | 706 | ); |
| 707 | 707 | } |
| 708 | 708 | |
| 709 | - if ( WC()->cart->needs_shipping() ) { |
|
| 709 | + if (WC()->cart->needs_shipping()) { |
|
| 710 | 710 | $items[] = array( |
| 711 | 711 | 'type' => 'final', |
| 712 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 712 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 713 | 713 | 'amount' => $shipping, |
| 714 | 714 | ); |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - if ( WC()->cart->has_discount() ) { |
|
| 717 | + if (WC()->cart->has_discount()) { |
|
| 718 | 718 | $items[] = array( |
| 719 | 719 | 'type' => 'final', |
| 720 | - 'label' => __( 'Discount', 'woocommerce-gateway-stripe' ), |
|
| 720 | + 'label' => __('Discount', 'woocommerce-gateway-stripe'), |
|
| 721 | 721 | 'amount' => '-' . $discounts, |
| 722 | 722 | ); |
| 723 | 723 | } |
@@ -733,24 +733,24 @@ discard block |
||
| 733 | 733 | * @param array $data |
| 734 | 734 | * @return object $order |
| 735 | 735 | */ |
| 736 | - public function create_order( $data = array() ) { |
|
| 737 | - if ( empty( $data ) ) { |
|
| 738 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 736 | + public function create_order($data = array()) { |
|
| 737 | + if (empty($data)) { |
|
| 738 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | $order = wc_create_order(); |
| 742 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 742 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 743 | 743 | |
| 744 | - if ( is_wp_error( $order ) ) { |
|
| 745 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 746 | - } elseif ( false === $order ) { |
|
| 747 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
| 744 | + if (is_wp_error($order)) { |
|
| 745 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 746 | + } elseif (false === $order) { |
|
| 747 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
| 748 | 748 | } else { |
| 749 | - do_action( 'woocommerce_new_order', $order_id ); |
|
| 749 | + do_action('woocommerce_new_order', $order_id); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | // Store the line items to the new/resumed order |
| 753 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 753 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 754 | 754 | $item_id = $order->add_product( |
| 755 | 755 | $values['data'], |
| 756 | 756 | $values['quantity'], |
@@ -766,25 +766,25 @@ discard block |
||
| 766 | 766 | ) |
| 767 | 767 | ); |
| 768 | 768 | |
| 769 | - if ( ! $item_id ) { |
|
| 770 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
| 769 | + if ( ! $item_id) { |
|
| 770 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | // Allow plugins to add order item meta |
| 774 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 775 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
| 774 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 775 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
| 776 | 776 | } else { |
| 777 | - do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() ); |
|
| 777 | + do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id()); |
|
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | // Store fees |
| 782 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
| 783 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 784 | - $item_id = $order->add_fee( $fee ); |
|
| 782 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
| 783 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 784 | + $item_id = $order->add_fee($fee); |
|
| 785 | 785 | } else { |
| 786 | 786 | $item = new WC_Order_Item_Fee(); |
| 787 | - $item->set_props( array( |
|
| 787 | + $item->set_props(array( |
|
| 788 | 788 | 'name' => $fee->name, |
| 789 | 789 | 'tax_class' => $fee->taxable ? $fee->tax_class : 0, |
| 790 | 790 | 'total' => $fee->amount, |
@@ -793,79 +793,79 @@ discard block |
||
| 793 | 793 | 'total' => $fee->tax_data, |
| 794 | 794 | ), |
| 795 | 795 | 'order_id' => $order->get_id(), |
| 796 | - ) ); |
|
| 796 | + )); |
|
| 797 | 797 | $item_id = $item->save(); |
| 798 | - $order->add_item( $item ); |
|
| 798 | + $order->add_item($item); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | - if ( ! $item_id ) { |
|
| 802 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
| 801 | + if ( ! $item_id) { |
|
| 802 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | // Allow plugins to add order item meta to fees |
| 806 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 807 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
| 806 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 807 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
| 808 | 808 | } else { |
| 809 | - do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() ); |
|
| 809 | + do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id()); |
|
| 810 | 810 | } |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | // Store tax rows |
| 814 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
| 815 | - $tax_amount = WC()->cart->get_tax_amount( $tax_rate_id ); |
|
| 816 | - $shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id ); |
|
| 814 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
| 815 | + $tax_amount = WC()->cart->get_tax_amount($tax_rate_id); |
|
| 816 | + $shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id); |
|
| 817 | 817 | |
| 818 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 819 | - $item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount ); |
|
| 818 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 819 | + $item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount); |
|
| 820 | 820 | } else { |
| 821 | 821 | $item = new WC_Order_Item_Tax(); |
| 822 | - $item->set_props( array( |
|
| 822 | + $item->set_props(array( |
|
| 823 | 823 | 'rate_id' => $tax_rate_id, |
| 824 | 824 | 'tax_total' => $tax_amount, |
| 825 | 825 | 'shipping_tax_total' => $shipping_tax_amount, |
| 826 | - ) ); |
|
| 827 | - $item->set_rate( $tax_rate_id ); |
|
| 828 | - $item->set_order_id( $order->get_id() ); |
|
| 826 | + )); |
|
| 827 | + $item->set_rate($tax_rate_id); |
|
| 828 | + $item->set_order_id($order->get_id()); |
|
| 829 | 829 | $item_id = $item->save(); |
| 830 | - $order->add_item( $item ); |
|
| 830 | + $order->add_item($item); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | - if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
| 834 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
| 833 | + if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
| 834 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
| 835 | 835 | } |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | // Store coupons |
| 839 | - $discount = WC()->cart->get_coupon_discount_amount( $code ); |
|
| 840 | - $discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code ); |
|
| 839 | + $discount = WC()->cart->get_coupon_discount_amount($code); |
|
| 840 | + $discount_tax = WC()->cart->get_coupon_discount_tax_amount($code); |
|
| 841 | 841 | |
| 842 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
| 843 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 844 | - $coupon_id = $order->add_coupon( $code, $discount, $discount_tax ); |
|
| 842 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
| 843 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 844 | + $coupon_id = $order->add_coupon($code, $discount, $discount_tax); |
|
| 845 | 845 | } else { |
| 846 | 846 | $item = new WC_Order_Item_Coupon(); |
| 847 | - $item->set_props( array( |
|
| 847 | + $item->set_props(array( |
|
| 848 | 848 | 'code' => $code, |
| 849 | 849 | 'discount' => $discount, |
| 850 | 850 | 'discount_tax' => $discount_tax, |
| 851 | 851 | 'order_id' => $order->get_id(), |
| 852 | - ) ); |
|
| 852 | + )); |
|
| 853 | 853 | $coupon_id = $item->save(); |
| 854 | - $order->add_item( $item ); |
|
| 854 | + $order->add_item($item); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | - if ( ! $coupon_id ) { |
|
| 858 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
| 857 | + if ( ! $coupon_id) { |
|
| 858 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
| 859 | 859 | } |
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | // Billing address |
| 863 | 863 | $billing_address = array(); |
| 864 | - if ( ! empty( $data['token']['card'] ) ) { |
|
| 864 | + if ( ! empty($data['token']['card'])) { |
|
| 865 | 865 | // Name from Stripe is a full name string. |
| 866 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
| 867 | - $lastname = array_pop( $name ); |
|
| 868 | - $firstname = implode( ' ', $name ); |
|
| 866 | + $name = explode(' ', $data['token']['card']['name']); |
|
| 867 | + $lastname = array_pop($name); |
|
| 868 | + $firstname = implode(' ', $name); |
|
| 869 | 869 | $billing_address['first_name'] = $firstname; |
| 870 | 870 | $billing_address['last_name'] = $lastname; |
| 871 | 871 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -880,7 +880,7 @@ discard block |
||
| 880 | 880 | |
| 881 | 881 | // Shipping address. |
| 882 | 882 | $shipping_address = array(); |
| 883 | - if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) { |
|
| 883 | + if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) { |
|
| 884 | 884 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
| 885 | 885 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
| 886 | 886 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | $shipping_address['city'] = $data['shippingContact']['locality']; |
| 892 | 892 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
| 893 | 893 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
| 894 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
| 894 | + } elseif ( ! empty($data['shippingContact'])) { |
|
| 895 | 895 | $shipping_address['first_name'] = $firstname; |
| 896 | 896 | $shipping_address['last_name'] = $lastname; |
| 897 | 897 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -904,33 +904,33 @@ discard block |
||
| 904 | 904 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | - $order->set_address( $billing_address, 'billing' ); |
|
| 908 | - $order->set_address( $shipping_address, 'shipping' ); |
|
| 907 | + $order->set_address($billing_address, 'billing'); |
|
| 908 | + $order->set_address($shipping_address, 'shipping'); |
|
| 909 | 909 | |
| 910 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
| 910 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
| 911 | 911 | |
| 912 | 912 | // Get the rate object selected by user. |
| 913 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
| 914 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 913 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
| 914 | + foreach ($package['rates'] as $key => $rate) { |
|
| 915 | 915 | // Loop through user chosen shipping methods. |
| 916 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
| 917 | - if ( $method === $key ) { |
|
| 918 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
| 919 | - $order->add_shipping( $rate ); |
|
| 916 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
| 917 | + if ($method === $key) { |
|
| 918 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
| 919 | + $order->add_shipping($rate); |
|
| 920 | 920 | } else { |
| 921 | 921 | $item = new WC_Order_Item_Shipping(); |
| 922 | - $item->set_props( array( |
|
| 922 | + $item->set_props(array( |
|
| 923 | 923 | 'method_title' => $rate->label, |
| 924 | 924 | 'method_id' => $rate->id, |
| 925 | - 'total' => wc_format_decimal( $rate->cost ), |
|
| 925 | + 'total' => wc_format_decimal($rate->cost), |
|
| 926 | 926 | 'taxes' => $rate->taxes, |
| 927 | 927 | 'order_id' => $order->get_id(), |
| 928 | - ) ); |
|
| 929 | - foreach ( $rate->get_meta_data() as $key => $value ) { |
|
| 930 | - $item->add_meta_data( $key, $value, true ); |
|
| 928 | + )); |
|
| 929 | + foreach ($rate->get_meta_data() as $key => $value) { |
|
| 930 | + $item->add_meta_data($key, $value, true); |
|
| 931 | 931 | } |
| 932 | 932 | $item->save(); |
| 933 | - $order->add_item( $item ); |
|
| 933 | + $order->add_item($item); |
|
| 934 | 934 | } |
| 935 | 935 | } |
| 936 | 936 | } |
@@ -938,16 +938,16 @@ discard block |
||
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 941 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
| 942 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
| 943 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
| 944 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
| 945 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
| 946 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
| 947 | - $order->set_total( WC()->cart->total ); |
|
| 941 | + $order->set_payment_method($available_gateways['stripe']); |
|
| 942 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
| 943 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
| 944 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
| 945 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
| 946 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
| 947 | + $order->set_total(WC()->cart->total); |
|
| 948 | 948 | |
| 949 | 949 | // If we got here, the order was created without problems! |
| 950 | - wc_transaction_query( 'commit' ); |
|
| 950 | + wc_transaction_query('commit'); |
|
| 951 | 951 | |
| 952 | 952 | return $order; |
| 953 | 953 | } |