@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 3.1.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -56,39 +56,39 @@ discard block |
||
| 56 | 56 | * @version 4.0.0 |
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 60 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
| 61 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
| 62 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
| 63 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
| 64 | - |
|
| 65 | - if ( $this->testmode ) { |
|
| 66 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
| 59 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 60 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
| 61 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
| 62 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
| 63 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
| 64 | + |
|
| 65 | + if ($this->testmode) { |
|
| 66 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // If both site title and statement descriptor is not set. Fallback. |
| 70 | - if ( empty( $this->total_label ) ) { |
|
| 70 | + if (empty($this->total_label)) { |
|
| 71 | 71 | $this->total_label = $_SERVER['SERVER_NAME']; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
| 74 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
| 75 | 75 | |
| 76 | 76 | // Checks if Stripe Gateway is enabled. |
| 77 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
| 77 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
| 78 | 78 | return; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // Checks if Payment Request is enabled. |
| 82 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
| 82 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Don't load for change payment method page. |
| 87 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
| 87 | + if (isset($_GET['change_payment_method'])) { |
|
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - add_action( 'woocommerce_init', array( $this, 'set_session' ) ); |
|
| 91 | + add_action('woocommerce_init', array($this, 'set_session')); |
|
| 92 | 92 | $this->init(); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -99,15 +99,15 @@ discard block |
||
| 99 | 99 | * @since 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function set_session() { |
| 102 | - if ( ! is_user_logged_in() ) { |
|
| 102 | + if ( ! is_user_logged_in()) { |
|
| 103 | 103 | $wc_session = new WC_Session_Handler(); |
| 104 | 104 | |
| 105 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
| 105 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
| 106 | 106 | $wc_session->init(); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if ( ! $wc_session->has_session() ) { |
|
| 110 | - $wc_session->set_customer_session_cookie( true ); |
|
| 109 | + if ( ! $wc_session->has_session()) { |
|
| 110 | + $wc_session->set_customer_session_cookie(true); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -119,40 +119,40 @@ discard block |
||
| 119 | 119 | * @version 4.0.0 |
| 120 | 120 | */ |
| 121 | 121 | public function init() { |
| 122 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
| 122 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
| 123 | 123 | |
| 124 | 124 | /* |
| 125 | 125 | * In order to display the Payment Request button in the correct position, |
| 126 | 126 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
| 127 | 127 | * CSS is used to position the button. |
| 128 | 128 | */ |
| 129 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 130 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 131 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 129 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 130 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
| 131 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 132 | 132 | } else { |
| 133 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 134 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 133 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
| 134 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 138 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 137 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
| 138 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 139 | 139 | |
| 140 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 141 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 140 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
| 141 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 142 | 142 | |
| 143 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
| 144 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
| 145 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
| 146 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
| 147 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
| 148 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
| 149 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
| 150 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
| 143 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
| 144 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
| 145 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
| 146 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
| 147 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
| 148 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
| 149 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
| 150 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
| 151 | 151 | |
| 152 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 153 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
| 152 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 153 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
| 154 | 154 | |
| 155 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
| 155 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @return string |
| 164 | 164 | */ |
| 165 | 165 | public function get_button_type() { |
| 166 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 166 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | 176 | public function get_button_theme() { |
| 177 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 177 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * @return string |
| 186 | 186 | */ |
| 187 | 187 | public function get_button_height() { |
| 188 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
| 188 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -195,40 +195,40 @@ discard block |
||
| 195 | 195 | * @version 4.0.0 |
| 196 | 196 | */ |
| 197 | 197 | public function get_product_data() { |
| 198 | - if ( ! is_product() ) { |
|
| 198 | + if ( ! is_product()) { |
|
| 199 | 199 | return false; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | global $post; |
| 203 | 203 | |
| 204 | - $product = wc_get_product( $post->ID ); |
|
| 204 | + $product = wc_get_product($post->ID); |
|
| 205 | 205 | |
| 206 | 206 | $data = array(); |
| 207 | 207 | $items = array(); |
| 208 | 208 | |
| 209 | 209 | $items[] = array( |
| 210 | 210 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
| 211 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
| 211 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
| 212 | 212 | ); |
| 213 | 213 | |
| 214 | - if ( wc_tax_enabled() ) { |
|
| 214 | + if (wc_tax_enabled()) { |
|
| 215 | 215 | $items[] = array( |
| 216 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 216 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 217 | 217 | 'amount' => 0, |
| 218 | 218 | 'pending' => true, |
| 219 | 219 | ); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 222 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 223 | 223 | $items[] = array( |
| 224 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 224 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 225 | 225 | 'amount' => 0, |
| 226 | 226 | 'pending' => true, |
| 227 | 227 | ); |
| 228 | 228 | |
| 229 | - $data['shippingOptions'] = array( |
|
| 229 | + $data['shippingOptions'] = array( |
|
| 230 | 230 | 'id' => 'pending', |
| 231 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 231 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 232 | 232 | 'detail' => '', |
| 233 | 233 | 'amount' => 0, |
| 234 | 234 | ); |
@@ -236,41 +236,41 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | $data['displayItems'] = $items; |
| 238 | 238 | $data['total'] = array( |
| 239 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
| 240 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
| 239 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
| 240 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
| 241 | 241 | 'pending' => true, |
| 242 | 242 | ); |
| 243 | 243 | |
| 244 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 245 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 246 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 244 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 245 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 246 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 247 | 247 | |
| 248 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
| 248 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
| 252 | 252 | * Filters the gateway title to reflect Payment Request type |
| 253 | 253 | * |
| 254 | 254 | */ |
| 255 | - public function filter_gateway_title( $title, $id ) { |
|
| 255 | + public function filter_gateway_title($title, $id) { |
|
| 256 | 256 | global $post; |
| 257 | 257 | |
| 258 | - if ( ! is_object( $post ) ) { |
|
| 258 | + if ( ! is_object($post)) { |
|
| 259 | 259 | return $title; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 263 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 262 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 263 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 264 | 264 | } else { |
| 265 | - $order = wc_get_order( $post->ID ); |
|
| 266 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
| 265 | + $order = wc_get_order($post->ID); |
|
| 266 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
| 269 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
| 270 | 270 | return $method_title; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
| 273 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
| 274 | 274 | return $method_title; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -283,16 +283,16 @@ discard block |
||
| 283 | 283 | * @since 3.1.4 |
| 284 | 284 | * @version 4.0.0 |
| 285 | 285 | */ |
| 286 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 286 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 287 | 287 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 288 | 288 | |
| 289 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 289 | + if ( ! isset($gateways['stripe'])) { |
|
| 290 | 290 | return $valid; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
| 293 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
| 294 | 294 | |
| 295 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
| 295 | + if ('apple_pay' !== $payment_request_type) { |
|
| 296 | 296 | return $valid; |
| 297 | 297 | } |
| 298 | 298 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 303 | 303 | * Note that this only works with shipping providers that don't validate full postal codes. |
| 304 | 304 | */ |
| 305 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 305 | + if ('GB' === $country || 'CA' === $country) { |
|
| 306 | 306 | return true; |
| 307 | 307 | } |
| 308 | 308 | |
@@ -317,29 +317,29 @@ discard block |
||
| 317 | 317 | * @param int $order_id |
| 318 | 318 | * @param array $posted_data The posted data from checkout form. |
| 319 | 319 | */ |
| 320 | - public function add_order_meta( $order_id, $posted_data ) { |
|
| 321 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
| 320 | + public function add_order_meta($order_id, $posted_data) { |
|
| 321 | + if (empty($_POST['payment_request_type'])) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - $order = wc_get_order( $order_id ); |
|
| 325 | + $order = wc_get_order($order_id); |
|
| 326 | 326 | |
| 327 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
| 327 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
| 328 | 328 | |
| 329 | - if ( 'apple_pay' === $payment_request_type ) { |
|
| 330 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 331 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
| 329 | + if ('apple_pay' === $payment_request_type) { |
|
| 330 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 331 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
| 332 | 332 | } else { |
| 333 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
| 333 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
| 334 | 334 | $order->save(); |
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
| 339 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 340 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
| 338 | + if ('payment_request_api' === $payment_request_type) { |
|
| 339 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 340 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
| 341 | 341 | } else { |
| 342 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
| 342 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
| 343 | 343 | $order->save(); |
| 344 | 344 | } |
| 345 | 345 | } |
@@ -353,11 +353,11 @@ discard block |
||
| 353 | 353 | * @return array |
| 354 | 354 | */ |
| 355 | 355 | public function supported_product_types() { |
| 356 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
| 356 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
| 357 | 357 | 'simple', |
| 358 | 358 | 'variable', |
| 359 | 359 | 'variation', |
| 360 | - ) ); |
|
| 360 | + )); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -368,15 +368,15 @@ discard block |
||
| 368 | 368 | * @return bool |
| 369 | 369 | */ |
| 370 | 370 | public function allowed_items_in_cart() { |
| 371 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 372 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
| 371 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 372 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
| 373 | 373 | |
| 374 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
| 374 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
| 375 | 375 | return false; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | // Pre Orders compatbility where we don't support charge upon release. |
| 379 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
| 379 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
| 380 | 380 | return false; |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -391,71 +391,71 @@ discard block |
||
| 391 | 391 | * @version 4.0.0 |
| 392 | 392 | */ |
| 393 | 393 | public function scripts() { |
| 394 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 394 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 395 | 395 | return; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if ( is_product() ) { |
|
| 398 | + if (is_product()) { |
|
| 399 | 399 | global $post; |
| 400 | 400 | |
| 401 | - $product = wc_get_product( $post->ID ); |
|
| 401 | + $product = wc_get_product($post->ID); |
|
| 402 | 402 | |
| 403 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 403 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 404 | 404 | return; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 407 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 408 | 408 | return; |
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 412 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 413 | 413 | |
| 414 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 415 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 414 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 415 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 416 | 416 | |
| 417 | 417 | wp_localize_script( |
| 418 | 418 | 'wc_stripe_payment_request', |
| 419 | 419 | 'wc_stripe_payment_request_params', |
| 420 | 420 | array( |
| 421 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 421 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 422 | 422 | 'stripe' => array( |
| 423 | 423 | 'key' => $this->publishable_key, |
| 424 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
| 424 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
| 425 | 425 | ), |
| 426 | 426 | 'nonce' => array( |
| 427 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
| 428 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
| 429 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
| 430 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
| 431 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
| 432 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
| 433 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
| 434 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
| 427 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
| 428 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
| 429 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
| 430 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
| 431 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
| 432 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
| 433 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
| 434 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
| 435 | 435 | ), |
| 436 | 436 | 'i18n' => array( |
| 437 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
| 437 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
| 438 | 438 | /* translators: Do not translate the [option] placeholder */ |
| 439 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
| 439 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
| 440 | 440 | ), |
| 441 | 441 | 'checkout' => array( |
| 442 | 442 | 'url' => wc_get_checkout_url(), |
| 443 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
| 444 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 443 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
| 444 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 445 | 445 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 446 | 446 | ), |
| 447 | 447 | 'button' => array( |
| 448 | 448 | 'type' => $this->get_button_type(), |
| 449 | 449 | 'theme' => $this->get_button_theme(), |
| 450 | 450 | 'height' => $this->get_button_height(), |
| 451 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
| 451 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
| 452 | 452 | ), |
| 453 | 453 | 'is_product_page' => is_product(), |
| 454 | 454 | 'product' => $this->get_product_data(), |
| 455 | 455 | ) |
| 456 | 456 | ); |
| 457 | 457 | |
| 458 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
| 458 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -467,39 +467,39 @@ discard block |
||
| 467 | 467 | public function display_payment_request_button_html() { |
| 468 | 468 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 469 | 469 | |
| 470 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 470 | + if ( ! isset($gateways['stripe'])) { |
|
| 471 | 471 | return; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 474 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 475 | 475 | return; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 478 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 479 | 479 | return; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
| 482 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
| 483 | 483 | return; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - if ( is_product() ) { |
|
| 486 | + if (is_product()) { |
|
| 487 | 487 | global $post; |
| 488 | 488 | |
| 489 | - $product = wc_get_product( $post->ID ); |
|
| 489 | + $product = wc_get_product($post->ID); |
|
| 490 | 490 | |
| 491 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 491 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 492 | 492 | return; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // Pre Orders charge upon release not supported. |
| 496 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 497 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 496 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 497 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 498 | 498 | return; |
| 499 | 499 | } |
| 500 | 500 | } else { |
| 501 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 502 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 501 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 502 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 503 | 503 | return; |
| 504 | 504 | } |
| 505 | 505 | } |
@@ -521,44 +521,44 @@ discard block |
||
| 521 | 521 | public function display_payment_request_button_separator_html() { |
| 522 | 522 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 523 | 523 | |
| 524 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 524 | + if ( ! isset($gateways['stripe'])) { |
|
| 525 | 525 | return; |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 528 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 529 | 529 | return; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 532 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 533 | 533 | return; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
| 536 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
| 537 | 537 | return; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - if ( is_product() ) { |
|
| 540 | + if (is_product()) { |
|
| 541 | 541 | global $post; |
| 542 | 542 | |
| 543 | - $product = wc_get_product( $post->ID ); |
|
| 543 | + $product = wc_get_product($post->ID); |
|
| 544 | 544 | |
| 545 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 545 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 546 | 546 | return; |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | // Pre Orders charge upon release not supported. |
| 550 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 551 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 550 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 551 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 552 | 552 | return; |
| 553 | 553 | } |
| 554 | 554 | } else { |
| 555 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 556 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 555 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 556 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 557 | 557 | return; |
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | ?> |
| 561 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
| 561 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p> |
|
| 562 | 562 | <?php |
| 563 | 563 | } |
| 564 | 564 | |
@@ -569,11 +569,11 @@ discard block |
||
| 569 | 569 | * @version 4.0.0 |
| 570 | 570 | */ |
| 571 | 571 | public function ajax_log_errors() { |
| 572 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
| 572 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
| 573 | 573 | |
| 574 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
| 574 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
| 575 | 575 | |
| 576 | - WC_Stripe_Logger::log( $errors ); |
|
| 576 | + WC_Stripe_Logger::log($errors); |
|
| 577 | 577 | |
| 578 | 578 | exit; |
| 579 | 579 | } |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | * @version 4.0.0 |
| 586 | 586 | */ |
| 587 | 587 | public function ajax_clear_cart() { |
| 588 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
| 588 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
| 589 | 589 | |
| 590 | 590 | WC()->cart->empty_cart(); |
| 591 | 591 | exit; |
@@ -595,10 +595,10 @@ discard block |
||
| 595 | 595 | * Get cart details. |
| 596 | 596 | */ |
| 597 | 597 | public function ajax_get_cart_details() { |
| 598 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
| 598 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
| 599 | 599 | |
| 600 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 601 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 600 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 601 | + define('WOOCOMMERCE_CART', true); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | WC()->cart->calculate_totals(); |
@@ -609,14 +609,14 @@ discard block |
||
| 609 | 609 | $data = array( |
| 610 | 610 | 'shipping_required' => WC()->cart->needs_shipping(), |
| 611 | 611 | 'order_data' => array( |
| 612 | - 'currency' => strtolower( $currency ), |
|
| 613 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 612 | + 'currency' => strtolower($currency), |
|
| 613 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 614 | 614 | ), |
| 615 | 615 | ); |
| 616 | 616 | |
| 617 | 617 | $data['order_data'] += $this->build_display_items(); |
| 618 | 618 | |
| 619 | - wp_send_json( $data ); |
|
| 619 | + wp_send_json($data); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -627,47 +627,47 @@ discard block |
||
| 627 | 627 | * @see WC_Shipping::get_packages(). |
| 628 | 628 | */ |
| 629 | 629 | public function ajax_get_shipping_options() { |
| 630 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
| 630 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
| 631 | 631 | |
| 632 | 632 | try { |
| 633 | 633 | // Set the shipping package. |
| 634 | - $posted = filter_input_array( INPUT_POST, array( |
|
| 634 | + $posted = filter_input_array(INPUT_POST, array( |
|
| 635 | 635 | 'country' => FILTER_SANITIZE_STRING, |
| 636 | 636 | 'state' => FILTER_SANITIZE_STRING, |
| 637 | 637 | 'postcode' => FILTER_SANITIZE_STRING, |
| 638 | 638 | 'city' => FILTER_SANITIZE_STRING, |
| 639 | 639 | 'address' => FILTER_SANITIZE_STRING, |
| 640 | 640 | 'address_2' => FILTER_SANITIZE_STRING, |
| 641 | - ) ); |
|
| 641 | + )); |
|
| 642 | 642 | |
| 643 | - $this->calculate_shipping( $posted ); |
|
| 643 | + $this->calculate_shipping($posted); |
|
| 644 | 644 | |
| 645 | 645 | // Set the shipping options. |
| 646 | 646 | $data = array(); |
| 647 | 647 | $packages = WC()->shipping->get_packages(); |
| 648 | 648 | |
| 649 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 650 | - foreach ( $packages as $package_key => $package ) { |
|
| 651 | - if ( empty( $package['rates'] ) ) { |
|
| 652 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 649 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 650 | + foreach ($packages as $package_key => $package) { |
|
| 651 | + if (empty($package['rates'])) { |
|
| 652 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 655 | + foreach ($package['rates'] as $key => $rate) { |
|
| 656 | 656 | $data['shipping_options'][] = array( |
| 657 | 657 | 'id' => $rate->id, |
| 658 | 658 | 'label' => $rate->label, |
| 659 | 659 | 'detail' => '', |
| 660 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
| 660 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
| 661 | 661 | ); |
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | 664 | } else { |
| 665 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 665 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - if ( isset( $data[0] ) ) { |
|
| 668 | + if (isset($data[0])) { |
|
| 669 | 669 | // Auto select the first shipping method. |
| 670 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 670 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | WC()->cart->calculate_totals(); |
@@ -675,12 +675,12 @@ discard block |
||
| 675 | 675 | $data += $this->build_display_items(); |
| 676 | 676 | $data['result'] = 'success'; |
| 677 | 677 | |
| 678 | - wp_send_json( $data ); |
|
| 679 | - } catch ( Exception $e ) { |
|
| 678 | + wp_send_json($data); |
|
| 679 | + } catch (Exception $e) { |
|
| 680 | 680 | $data += $this->build_display_items(); |
| 681 | 681 | $data['result'] = 'invalid_shipping_address'; |
| 682 | 682 | |
| 683 | - wp_send_json( $data ); |
|
| 683 | + wp_send_json($data); |
|
| 684 | 684 | } |
| 685 | 685 | } |
| 686 | 686 | |
@@ -688,22 +688,22 @@ discard block |
||
| 688 | 688 | * Update shipping method. |
| 689 | 689 | */ |
| 690 | 690 | public function ajax_update_shipping_method() { |
| 691 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
| 691 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
| 692 | 692 | |
| 693 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 694 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 693 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 694 | + define('WOOCOMMERCE_CART', true); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 698 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 697 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 698 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 699 | 699 | |
| 700 | - if ( is_array( $shipping_method ) ) { |
|
| 701 | - foreach ( $shipping_method as $i => $value ) { |
|
| 702 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
| 700 | + if (is_array($shipping_method)) { |
|
| 701 | + foreach ($shipping_method as $i => $value) { |
|
| 702 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
| 703 | 703 | } |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
| 706 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
| 707 | 707 | |
| 708 | 708 | WC()->cart->calculate_totals(); |
| 709 | 709 | |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | $data += $this->build_display_items(); |
| 712 | 712 | $data['result'] = 'success'; |
| 713 | 713 | |
| 714 | - wp_send_json( $data ); |
|
| 714 | + wp_send_json($data); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | /** |
@@ -722,31 +722,31 @@ discard block |
||
| 722 | 722 | * @return array $data |
| 723 | 723 | */ |
| 724 | 724 | public function ajax_get_selected_product_data() { |
| 725 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
| 725 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
| 726 | 726 | |
| 727 | - $product_id = absint( $_POST['product_id'] ); |
|
| 728 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 727 | + $product_id = absint($_POST['product_id']); |
|
| 728 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 729 | 729 | |
| 730 | - $product = wc_get_product( $product_id ); |
|
| 730 | + $product = wc_get_product($product_id); |
|
| 731 | 731 | |
| 732 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 733 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 732 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 733 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 734 | 734 | |
| 735 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 736 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 735 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 736 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 737 | 737 | } else { |
| 738 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 739 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 738 | + $data_store = WC_Data_Store::load('product'); |
|
| 739 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | - if ( ! empty( $variation_id ) ) { |
|
| 743 | - $product = wc_get_product( $variation_id ); |
|
| 742 | + if ( ! empty($variation_id)) { |
|
| 743 | + $product = wc_get_product($variation_id); |
|
| 744 | 744 | } |
| 745 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
| 746 | - $product = wc_get_product( $product_id ); |
|
| 745 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
| 746 | + $product = wc_get_product($product_id); |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
| 749 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
| 750 | 750 | |
| 751 | 751 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
| 752 | 752 | |
@@ -754,28 +754,28 @@ discard block |
||
| 754 | 754 | $items = array(); |
| 755 | 755 | |
| 756 | 756 | $items[] = array( |
| 757 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
| 758 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 757 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
| 758 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 759 | 759 | ); |
| 760 | 760 | |
| 761 | - if ( wc_tax_enabled() ) { |
|
| 761 | + if (wc_tax_enabled()) { |
|
| 762 | 762 | $items[] = array( |
| 763 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 763 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 764 | 764 | 'amount' => 0, |
| 765 | 765 | 'pending' => true, |
| 766 | 766 | ); |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 769 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 770 | 770 | $items[] = array( |
| 771 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 771 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 772 | 772 | 'amount' => 0, |
| 773 | 773 | 'pending' => true, |
| 774 | 774 | ); |
| 775 | 775 | |
| 776 | - $data['shippingOptions'] = array( |
|
| 776 | + $data['shippingOptions'] = array( |
|
| 777 | 777 | 'id' => 'pending', |
| 778 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 778 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 779 | 779 | 'detail' => '', |
| 780 | 780 | 'amount' => 0, |
| 781 | 781 | ); |
@@ -784,15 +784,15 @@ discard block |
||
| 784 | 784 | $data['displayItems'] = $items; |
| 785 | 785 | $data['total'] = array( |
| 786 | 786 | 'label' => $this->total_label, |
| 787 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 787 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 788 | 788 | 'pending' => true, |
| 789 | 789 | ); |
| 790 | 790 | |
| 791 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 792 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 793 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 791 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 792 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 793 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 794 | 794 | |
| 795 | - wp_send_json( $data ); |
|
| 795 | + wp_send_json($data); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -803,37 +803,37 @@ discard block |
||
| 803 | 803 | * @return array $data |
| 804 | 804 | */ |
| 805 | 805 | public function ajax_add_to_cart() { |
| 806 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
| 806 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
| 807 | 807 | |
| 808 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 809 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 808 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 809 | + define('WOOCOMMERCE_CART', true); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | WC()->shipping->reset_shipping(); |
| 813 | 813 | |
| 814 | - $product_id = absint( $_POST['product_id'] ); |
|
| 815 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 814 | + $product_id = absint($_POST['product_id']); |
|
| 815 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 816 | 816 | |
| 817 | - $product = wc_get_product( $product_id ); |
|
| 817 | + $product = wc_get_product($product_id); |
|
| 818 | 818 | |
| 819 | 819 | // First empty the cart to prevent wrong calculation. |
| 820 | 820 | WC()->cart->empty_cart(); |
| 821 | 821 | |
| 822 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 823 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 822 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 823 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 824 | 824 | |
| 825 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 826 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 825 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 826 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 827 | 827 | } else { |
| 828 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 829 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 828 | + $data_store = WC_Data_Store::load('product'); |
|
| 829 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 832 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
| 836 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 835 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
| 836 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | WC()->cart->calculate_totals(); |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | $data += $this->build_display_items(); |
| 843 | 843 | $data['result'] = 'success'; |
| 844 | 844 | |
| 845 | - wp_send_json( $data ); |
|
| 845 | + wp_send_json($data); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | /** |
@@ -855,31 +855,31 @@ discard block |
||
| 855 | 855 | * @version 4.0.0 |
| 856 | 856 | */ |
| 857 | 857 | public function normalize_state() { |
| 858 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
| 859 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
| 860 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
| 861 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
| 858 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
| 859 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
| 860 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
| 861 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
| 862 | 862 | |
| 863 | - if ( $billing_state && $billing_country ) { |
|
| 864 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
| 863 | + if ($billing_state && $billing_country) { |
|
| 864 | + $valid_states = WC()->countries->get_states($billing_country); |
|
| 865 | 865 | |
| 866 | 866 | // Valid states found for country. |
| 867 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 868 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 869 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
| 867 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 868 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 869 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
| 870 | 870 | $_POST['billing_state'] = $state_abbr; |
| 871 | 871 | } |
| 872 | 872 | } |
| 873 | 873 | } |
| 874 | 874 | } |
| 875 | 875 | |
| 876 | - if ( $shipping_state && $shipping_country ) { |
|
| 877 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
| 876 | + if ($shipping_state && $shipping_country) { |
|
| 877 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
| 878 | 878 | |
| 879 | 879 | // Valid states found for country. |
| 880 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 881 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 882 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
| 880 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 881 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 882 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
| 883 | 883 | $_POST['shipping_state'] = $state_abbr; |
| 884 | 884 | } |
| 885 | 885 | } |
@@ -894,19 +894,19 @@ discard block |
||
| 894 | 894 | * @version 4.0.0 |
| 895 | 895 | */ |
| 896 | 896 | public function ajax_create_order() { |
| 897 | - if ( WC()->cart->is_empty() ) { |
|
| 898 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
| 897 | + if (WC()->cart->is_empty()) { |
|
| 898 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
| 902 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 901 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
| 902 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | $this->normalize_state(); |
| 906 | 906 | |
| 907 | 907 | WC()->checkout()->process_checkout(); |
| 908 | 908 | |
| 909 | - die( 0 ); |
|
| 909 | + die(0); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | /** |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | * @version 4.0.0 |
| 917 | 917 | * @param array $address |
| 918 | 918 | */ |
| 919 | - protected function calculate_shipping( $address = array() ) { |
|
| 919 | + protected function calculate_shipping($address = array()) { |
|
| 920 | 920 | global $states; |
| 921 | 921 | |
| 922 | 922 | $country = $address['country']; |
@@ -933,28 +933,28 @@ discard block |
||
| 933 | 933 | * In some versions of Chrome, state can be a full name. So we need |
| 934 | 934 | * to convert that to abbreviation as WC is expecting that. |
| 935 | 935 | */ |
| 936 | - if ( 2 < strlen( $state ) ) { |
|
| 937 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
| 936 | + if (2 < strlen($state)) { |
|
| 937 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | WC()->shipping->reset_shipping(); |
| 941 | 941 | |
| 942 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 943 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 942 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
| 943 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | - if ( $country ) { |
|
| 947 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 948 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 946 | + if ($country) { |
|
| 947 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 948 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 949 | 949 | } else { |
| 950 | 950 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
| 951 | 951 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
| 952 | 952 | } |
| 953 | 953 | |
| 954 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 955 | - WC()->customer->calculated_shipping( true ); |
|
| 954 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 955 | + WC()->customer->calculated_shipping(true); |
|
| 956 | 956 | } else { |
| 957 | - WC()->customer->set_calculated_shipping( true ); |
|
| 957 | + WC()->customer->set_calculated_shipping(true); |
|
| 958 | 958 | WC()->customer->save(); |
| 959 | 959 | } |
| 960 | 960 | |
@@ -971,17 +971,17 @@ discard block |
||
| 971 | 971 | $packages[0]['destination']['address'] = $address_1; |
| 972 | 972 | $packages[0]['destination']['address_2'] = $address_2; |
| 973 | 973 | |
| 974 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 975 | - if ( $item['data']->needs_shipping() ) { |
|
| 976 | - if ( isset( $item['line_total'] ) ) { |
|
| 974 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 975 | + if ($item['data']->needs_shipping()) { |
|
| 976 | + if (isset($item['line_total'])) { |
|
| 977 | 977 | $packages[0]['contents_cost'] += $item['line_total']; |
| 978 | 978 | } |
| 979 | 979 | } |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 982 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 983 | 983 | |
| 984 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 984 | + WC()->shipping->calculate_shipping($packages); |
|
| 985 | 985 | } |
| 986 | 986 | |
| 987 | 987 | /** |
@@ -990,19 +990,19 @@ discard block |
||
| 990 | 990 | * @since 3.1.0 |
| 991 | 991 | * @version 4.0.0 |
| 992 | 992 | */ |
| 993 | - protected function build_shipping_methods( $shipping_methods ) { |
|
| 994 | - if ( empty( $shipping_methods ) ) { |
|
| 993 | + protected function build_shipping_methods($shipping_methods) { |
|
| 994 | + if (empty($shipping_methods)) { |
|
| 995 | 995 | return array(); |
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | $shipping = array(); |
| 999 | 999 | |
| 1000 | - foreach ( $shipping_methods as $method ) { |
|
| 1000 | + foreach ($shipping_methods as $method) { |
|
| 1001 | 1001 | $shipping[] = array( |
| 1002 | 1002 | 'id' => $method['id'], |
| 1003 | 1003 | 'label' => $method['label'], |
| 1004 | 1004 | 'detail' => '', |
| 1005 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
| 1005 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
| 1006 | 1006 | ); |
| 1007 | 1007 | } |
| 1008 | 1008 | |
@@ -1016,69 +1016,69 @@ discard block |
||
| 1016 | 1016 | * @version 4.0.0 |
| 1017 | 1017 | */ |
| 1018 | 1018 | protected function build_display_items() { |
| 1019 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 1020 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 1019 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 1020 | + define('WOOCOMMERCE_CART', true); |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | $items = array(); |
| 1024 | 1024 | $subtotal = 0; |
| 1025 | 1025 | |
| 1026 | 1026 | // Default show only subtotal instead of itemization. |
| 1027 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
| 1028 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 1027 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
| 1028 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 1029 | 1029 | $amount = $cart_item['line_subtotal']; |
| 1030 | - $subtotal += $cart_item['line_subtotal']; |
|
| 1030 | + $subtotal += $cart_item['line_subtotal']; |
|
| 1031 | 1031 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
| 1032 | 1032 | |
| 1033 | 1033 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
| 1034 | 1034 | |
| 1035 | 1035 | $item = array( |
| 1036 | 1036 | 'label' => $product_name . $quantity_label, |
| 1037 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
| 1037 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
| 1038 | 1038 | ); |
| 1039 | 1039 | |
| 1040 | 1040 | $items[] = $item; |
| 1041 | 1041 | } |
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
| 1045 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
| 1046 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
| 1047 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
| 1048 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
| 1044 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
| 1045 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
| 1046 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
| 1047 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
| 1048 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
| 1049 | 1049 | |
| 1050 | - if ( wc_tax_enabled() ) { |
|
| 1050 | + if (wc_tax_enabled()) { |
|
| 1051 | 1051 | $items[] = array( |
| 1052 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
| 1053 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
| 1052 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
| 1053 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
| 1054 | 1054 | ); |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | - if ( WC()->cart->needs_shipping() ) { |
|
| 1057 | + if (WC()->cart->needs_shipping()) { |
|
| 1058 | 1058 | $items[] = array( |
| 1059 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
| 1060 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
| 1059 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
| 1060 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
| 1061 | 1061 | ); |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | - if ( WC()->cart->has_discount() ) { |
|
| 1064 | + if (WC()->cart->has_discount()) { |
|
| 1065 | 1065 | $items[] = array( |
| 1066 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
| 1067 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
| 1066 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
| 1067 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
| 1068 | 1068 | ); |
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1071 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1072 | 1072 | $cart_fees = WC()->cart->fees; |
| 1073 | 1073 | } else { |
| 1074 | 1074 | $cart_fees = WC()->cart->get_fees(); |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | // Include fees and taxes as display items. |
| 1078 | - foreach ( $cart_fees as $key => $fee ) { |
|
| 1078 | + foreach ($cart_fees as $key => $fee) { |
|
| 1079 | 1079 | $items[] = array( |
| 1080 | 1080 | 'label' => $fee->name, |
| 1081 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
| 1081 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
| 1082 | 1082 | ); |
| 1083 | 1083 | } |
| 1084 | 1084 | |
@@ -1086,7 +1086,7 @@ discard block |
||
| 1086 | 1086 | 'displayItems' => $items, |
| 1087 | 1087 | 'total' => array( |
| 1088 | 1088 | 'label' => $this->total_label, |
| 1089 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
| 1089 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
| 1090 | 1090 | 'pending' => false, |
| 1091 | 1091 | ), |
| 1092 | 1092 | ); |