@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 4.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -71,36 +71,36 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct() { |
73 | 73 | self::$_this = $this; |
74 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
75 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
76 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
74 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
75 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
76 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
80 | 80 | |
81 | - if ( $this->testmode ) { |
|
82 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
81 | + if ($this->testmode) { |
|
82 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
84 | 84 | } |
85 | 85 | |
86 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
86 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
87 | 87 | |
88 | 88 | // Checks if Stripe Gateway is enabled. |
89 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
89 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // Checks if Payment Request is enabled. |
94 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
94 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Don't load for change payment method page. |
99 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
99 | + if (isset($_GET['change_payment_method'])) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
103 | + add_action('template_redirect', array($this, 'set_session')); |
|
104 | 104 | $this->init(); |
105 | 105 | } |
106 | 106 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function are_keys_set() { |
114 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
114 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -135,19 +135,19 @@ discard block |
||
135 | 135 | * @since 4.0.0 |
136 | 136 | */ |
137 | 137 | public function set_session() { |
138 | - if ( ! is_product() ) { |
|
138 | + if ( ! is_product()) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - if ( ! is_user_logged_in() ) { |
|
142 | + if ( ! is_user_logged_in()) { |
|
143 | 143 | $wc_session = new WC_Session_Handler(); |
144 | 144 | |
145 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
145 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
146 | 146 | $wc_session->init(); |
147 | 147 | } |
148 | 148 | |
149 | - if ( ! $wc_session->has_session() ) { |
|
150 | - $wc_session->set_customer_session_cookie( true ); |
|
149 | + if ( ! $wc_session->has_session()) { |
|
150 | + $wc_session->set_customer_session_cookie(true); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -159,40 +159,40 @@ discard block |
||
159 | 159 | * @version 4.0.0 |
160 | 160 | */ |
161 | 161 | public function init() { |
162 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
162 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
163 | 163 | |
164 | 164 | /* |
165 | 165 | * In order to display the Payment Request button in the correct position, |
166 | 166 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
167 | 167 | * CSS is used to position the button. |
168 | 168 | */ |
169 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
170 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
171 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
169 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
170 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
171 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
172 | 172 | } else { |
173 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
174 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
173 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
174 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
175 | 175 | } |
176 | 176 | |
177 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
178 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
177 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
178 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
179 | 179 | |
180 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
181 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
180 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
181 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
182 | 182 | |
183 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
184 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
185 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
186 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
187 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
188 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
189 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
190 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
183 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
184 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
185 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
186 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
187 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
188 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
189 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
190 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
191 | 191 | |
192 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
193 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
192 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
193 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
194 | 194 | |
195 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
195 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function get_button_type() { |
206 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
206 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @return string |
215 | 215 | */ |
216 | 216 | public function get_button_theme() { |
217 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
217 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @return string |
226 | 226 | */ |
227 | 227 | public function get_button_height() { |
228 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
228 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -235,40 +235,40 @@ discard block |
||
235 | 235 | * @version 4.0.0 |
236 | 236 | */ |
237 | 237 | public function get_product_data() { |
238 | - if ( ! is_product() ) { |
|
238 | + if ( ! is_product()) { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | |
242 | 242 | global $post; |
243 | 243 | |
244 | - $product = wc_get_product( $post->ID ); |
|
244 | + $product = wc_get_product($post->ID); |
|
245 | 245 | |
246 | 246 | $data = array(); |
247 | 247 | $items = array(); |
248 | 248 | |
249 | 249 | $items[] = array( |
250 | 250 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
251 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
251 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
252 | 252 | ); |
253 | 253 | |
254 | - if ( wc_tax_enabled() ) { |
|
254 | + if (wc_tax_enabled()) { |
|
255 | 255 | $items[] = array( |
256 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
256 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
257 | 257 | 'amount' => 0, |
258 | 258 | 'pending' => true, |
259 | 259 | ); |
260 | 260 | } |
261 | 261 | |
262 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
262 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
263 | 263 | $items[] = array( |
264 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
264 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
265 | 265 | 'amount' => 0, |
266 | 266 | 'pending' => true, |
267 | 267 | ); |
268 | 268 | |
269 | - $data['shippingOptions'] = array( |
|
269 | + $data['shippingOptions'] = array( |
|
270 | 270 | 'id' => 'pending', |
271 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
271 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
272 | 272 | 'detail' => '', |
273 | 273 | 'amount' => 0, |
274 | 274 | ); |
@@ -276,41 +276,41 @@ discard block |
||
276 | 276 | |
277 | 277 | $data['displayItems'] = $items; |
278 | 278 | $data['total'] = array( |
279 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
280 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
279 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
280 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
281 | 281 | 'pending' => true, |
282 | 282 | ); |
283 | 283 | |
284 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
285 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
286 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
284 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
285 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
286 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
287 | 287 | |
288 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
288 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
292 | 292 | * Filters the gateway title to reflect Payment Request type |
293 | 293 | * |
294 | 294 | */ |
295 | - public function filter_gateway_title( $title, $id ) { |
|
295 | + public function filter_gateway_title($title, $id) { |
|
296 | 296 | global $post; |
297 | 297 | |
298 | - if ( ! is_object( $post ) ) { |
|
298 | + if ( ! is_object($post)) { |
|
299 | 299 | return $title; |
300 | 300 | } |
301 | 301 | |
302 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
303 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
302 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
303 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
304 | 304 | } else { |
305 | - $order = wc_get_order( $post->ID ); |
|
306 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
305 | + $order = wc_get_order($post->ID); |
|
306 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
309 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
310 | 310 | return $method_title; |
311 | 311 | } |
312 | 312 | |
313 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
313 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
314 | 314 | return $method_title; |
315 | 315 | } |
316 | 316 | |
@@ -323,16 +323,16 @@ discard block |
||
323 | 323 | * @since 3.1.4 |
324 | 324 | * @version 4.0.0 |
325 | 325 | */ |
326 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
326 | + public function postal_code_validation($valid, $postcode, $country) { |
|
327 | 327 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
328 | 328 | |
329 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
329 | + if ( ! isset($gateways['stripe'])) { |
|
330 | 330 | return $valid; |
331 | 331 | } |
332 | 332 | |
333 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
333 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
334 | 334 | |
335 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
335 | + if ('apple_pay' !== $payment_request_type) { |
|
336 | 336 | return $valid; |
337 | 337 | } |
338 | 338 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * the order and not let it go through. The remedy for now is just to remove this validation. |
343 | 343 | * Note that this only works with shipping providers that don't validate full postal codes. |
344 | 344 | */ |
345 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
345 | + if ('GB' === $country || 'CA' === $country) { |
|
346 | 346 | return true; |
347 | 347 | } |
348 | 348 | |
@@ -357,29 +357,29 @@ discard block |
||
357 | 357 | * @param int $order_id |
358 | 358 | * @param array $posted_data The posted data from checkout form. |
359 | 359 | */ |
360 | - public function add_order_meta( $order_id, $posted_data ) { |
|
361 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
360 | + public function add_order_meta($order_id, $posted_data) { |
|
361 | + if (empty($_POST['payment_request_type'])) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | - $order = wc_get_order( $order_id ); |
|
365 | + $order = wc_get_order($order_id); |
|
366 | 366 | |
367 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
367 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
368 | 368 | |
369 | - if ( 'apple_pay' === $payment_request_type ) { |
|
370 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
371 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
369 | + if ('apple_pay' === $payment_request_type) { |
|
370 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
371 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
372 | 372 | } else { |
373 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
373 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
374 | 374 | $order->save(); |
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
379 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
380 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
378 | + if ('payment_request_api' === $payment_request_type) { |
|
379 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
380 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
381 | 381 | } else { |
382 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
382 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
383 | 383 | $order->save(); |
384 | 384 | } |
385 | 385 | } |
@@ -393,11 +393,11 @@ discard block |
||
393 | 393 | * @return array |
394 | 394 | */ |
395 | 395 | public function supported_product_types() { |
396 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
396 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
397 | 397 | 'simple', |
398 | 398 | 'variable', |
399 | 399 | 'variation', |
400 | - ) ); |
|
400 | + )); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -408,15 +408,15 @@ discard block |
||
408 | 408 | * @return bool |
409 | 409 | */ |
410 | 410 | public function allowed_items_in_cart() { |
411 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
412 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
411 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
412 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
413 | 413 | |
414 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
414 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
415 | 415 | return false; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Pre Orders compatbility where we don't support charge upon release. |
419 | - 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() ) ) { |
|
419 | + 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())) { |
|
420 | 420 | return false; |
421 | 421 | } |
422 | 422 | } |
@@ -432,82 +432,82 @@ discard block |
||
432 | 432 | */ |
433 | 433 | public function scripts() { |
434 | 434 | // If keys are not set bail. |
435 | - if ( ! $this->are_keys_set() ) { |
|
436 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
435 | + if ( ! $this->are_keys_set()) { |
|
436 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
440 | 440 | // If no SSL bail. |
441 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
442 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
441 | + if ( ! $this->testmode && ! is_ssl()) { |
|
442 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
446 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
447 | 447 | return; |
448 | 448 | } |
449 | 449 | |
450 | - if ( is_product() ) { |
|
450 | + if (is_product()) { |
|
451 | 451 | global $post; |
452 | 452 | |
453 | - $product = wc_get_product( $post->ID ); |
|
453 | + $product = wc_get_product($post->ID); |
|
454 | 454 | |
455 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
455 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
456 | 456 | return; |
457 | 457 | } |
458 | 458 | |
459 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
459 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
460 | 460 | return; |
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
464 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
464 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
465 | 465 | |
466 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
467 | - 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 ); |
|
466 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
467 | + 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); |
|
468 | 468 | |
469 | 469 | wp_localize_script( |
470 | 470 | 'wc_stripe_payment_request', |
471 | 471 | 'wc_stripe_payment_request_params', |
472 | 472 | array( |
473 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
473 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
474 | 474 | 'stripe' => array( |
475 | 475 | 'key' => $this->publishable_key, |
476 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
476 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
477 | 477 | ), |
478 | 478 | 'nonce' => array( |
479 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
480 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
481 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
482 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
483 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
484 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
485 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
486 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
479 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
480 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
481 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
482 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
483 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
484 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
485 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
486 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
487 | 487 | ), |
488 | 488 | 'i18n' => array( |
489 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
489 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
490 | 490 | /* translators: Do not translate the [option] placeholder */ |
491 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
491 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
492 | 492 | ), |
493 | 493 | 'checkout' => array( |
494 | 494 | 'url' => wc_get_checkout_url(), |
495 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
496 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
495 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
496 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
497 | 497 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
498 | 498 | ), |
499 | 499 | 'button' => array( |
500 | 500 | 'type' => $this->get_button_type(), |
501 | 501 | 'theme' => $this->get_button_theme(), |
502 | 502 | 'height' => $this->get_button_height(), |
503 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
503 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
504 | 504 | ), |
505 | 505 | 'is_product_page' => is_product(), |
506 | 506 | 'product' => $this->get_product_data(), |
507 | 507 | ) |
508 | 508 | ); |
509 | 509 | |
510 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
510 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -519,39 +519,39 @@ discard block |
||
519 | 519 | public function display_payment_request_button_html() { |
520 | 520 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
521 | 521 | |
522 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
522 | + if ( ! isset($gateways['stripe'])) { |
|
523 | 523 | return; |
524 | 524 | } |
525 | 525 | |
526 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
526 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
527 | 527 | return; |
528 | 528 | } |
529 | 529 | |
530 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
530 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
531 | 531 | return; |
532 | 532 | } |
533 | 533 | |
534 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
534 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
535 | 535 | return; |
536 | 536 | } |
537 | 537 | |
538 | - if ( is_product() ) { |
|
538 | + if (is_product()) { |
|
539 | 539 | global $post; |
540 | 540 | |
541 | - $product = wc_get_product( $post->ID ); |
|
541 | + $product = wc_get_product($post->ID); |
|
542 | 542 | |
543 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
543 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
544 | 544 | return; |
545 | 545 | } |
546 | 546 | |
547 | 547 | // Pre Orders charge upon release not supported. |
548 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
549 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
548 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
549 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
550 | 550 | return; |
551 | 551 | } |
552 | 552 | } else { |
553 | - if ( ! $this->allowed_items_in_cart() ) { |
|
554 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
553 | + if ( ! $this->allowed_items_in_cart()) { |
|
554 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
555 | 555 | return; |
556 | 556 | } |
557 | 557 | } |
@@ -573,44 +573,44 @@ discard block |
||
573 | 573 | public function display_payment_request_button_separator_html() { |
574 | 574 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
575 | 575 | |
576 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
576 | + if ( ! isset($gateways['stripe'])) { |
|
577 | 577 | return; |
578 | 578 | } |
579 | 579 | |
580 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
580 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
581 | 581 | return; |
582 | 582 | } |
583 | 583 | |
584 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
584 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
585 | 585 | return; |
586 | 586 | } |
587 | 587 | |
588 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
588 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
589 | 589 | return; |
590 | 590 | } |
591 | 591 | |
592 | - if ( is_product() ) { |
|
592 | + if (is_product()) { |
|
593 | 593 | global $post; |
594 | 594 | |
595 | - $product = wc_get_product( $post->ID ); |
|
595 | + $product = wc_get_product($post->ID); |
|
596 | 596 | |
597 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
597 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
598 | 598 | return; |
599 | 599 | } |
600 | 600 | |
601 | 601 | // Pre Orders charge upon release not supported. |
602 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
603 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
602 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
603 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
604 | 604 | return; |
605 | 605 | } |
606 | 606 | } else { |
607 | - if ( ! $this->allowed_items_in_cart() ) { |
|
608 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
607 | + if ( ! $this->allowed_items_in_cart()) { |
|
608 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
609 | 609 | return; |
610 | 610 | } |
611 | 611 | } |
612 | 612 | ?> |
613 | - <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> |
|
613 | + <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> |
|
614 | 614 | <?php |
615 | 615 | } |
616 | 616 | |
@@ -621,11 +621,11 @@ discard block |
||
621 | 621 | * @version 4.0.0 |
622 | 622 | */ |
623 | 623 | public function ajax_log_errors() { |
624 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
624 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
625 | 625 | |
626 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
626 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
627 | 627 | |
628 | - WC_Stripe_Logger::log( $errors ); |
|
628 | + WC_Stripe_Logger::log($errors); |
|
629 | 629 | |
630 | 630 | exit; |
631 | 631 | } |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | * @version 4.0.0 |
638 | 638 | */ |
639 | 639 | public function ajax_clear_cart() { |
640 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
640 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
641 | 641 | |
642 | 642 | WC()->cart->empty_cart(); |
643 | 643 | exit; |
@@ -647,10 +647,10 @@ discard block |
||
647 | 647 | * Get cart details. |
648 | 648 | */ |
649 | 649 | public function ajax_get_cart_details() { |
650 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
650 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
651 | 651 | |
652 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
653 | - define( 'WOOCOMMERCE_CART', true ); |
|
652 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
653 | + define('WOOCOMMERCE_CART', true); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | WC()->cart->calculate_totals(); |
@@ -661,14 +661,14 @@ discard block |
||
661 | 661 | $data = array( |
662 | 662 | 'shipping_required' => WC()->cart->needs_shipping(), |
663 | 663 | 'order_data' => array( |
664 | - 'currency' => strtolower( $currency ), |
|
665 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
664 | + 'currency' => strtolower($currency), |
|
665 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
666 | 666 | ), |
667 | 667 | ); |
668 | 668 | |
669 | 669 | $data['order_data'] += $this->build_display_items(); |
670 | 670 | |
671 | - wp_send_json( $data ); |
|
671 | + wp_send_json($data); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
@@ -679,47 +679,47 @@ discard block |
||
679 | 679 | * @see WC_Shipping::get_packages(). |
680 | 680 | */ |
681 | 681 | public function ajax_get_shipping_options() { |
682 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
682 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
683 | 683 | |
684 | 684 | try { |
685 | 685 | // Set the shipping package. |
686 | - $posted = filter_input_array( INPUT_POST, array( |
|
686 | + $posted = filter_input_array(INPUT_POST, array( |
|
687 | 687 | 'country' => FILTER_SANITIZE_STRING, |
688 | 688 | 'state' => FILTER_SANITIZE_STRING, |
689 | 689 | 'postcode' => FILTER_SANITIZE_STRING, |
690 | 690 | 'city' => FILTER_SANITIZE_STRING, |
691 | 691 | 'address' => FILTER_SANITIZE_STRING, |
692 | 692 | 'address_2' => FILTER_SANITIZE_STRING, |
693 | - ) ); |
|
693 | + )); |
|
694 | 694 | |
695 | - $this->calculate_shipping( $posted ); |
|
695 | + $this->calculate_shipping($posted); |
|
696 | 696 | |
697 | 697 | // Set the shipping options. |
698 | 698 | $data = array(); |
699 | 699 | $packages = WC()->shipping->get_packages(); |
700 | 700 | |
701 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
702 | - foreach ( $packages as $package_key => $package ) { |
|
703 | - if ( empty( $package['rates'] ) ) { |
|
704 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
701 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
702 | + foreach ($packages as $package_key => $package) { |
|
703 | + if (empty($package['rates'])) { |
|
704 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
705 | 705 | } |
706 | 706 | |
707 | - foreach ( $package['rates'] as $key => $rate ) { |
|
707 | + foreach ($package['rates'] as $key => $rate) { |
|
708 | 708 | $data['shipping_options'][] = array( |
709 | 709 | 'id' => $rate->id, |
710 | 710 | 'label' => $rate->label, |
711 | 711 | 'detail' => '', |
712 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
712 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
713 | 713 | ); |
714 | 714 | } |
715 | 715 | } |
716 | 716 | } else { |
717 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
717 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
718 | 718 | } |
719 | 719 | |
720 | - if ( isset( $data[0] ) ) { |
|
720 | + if (isset($data[0])) { |
|
721 | 721 | // Auto select the first shipping method. |
722 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
722 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | WC()->cart->calculate_totals(); |
@@ -727,12 +727,12 @@ discard block |
||
727 | 727 | $data += $this->build_display_items(); |
728 | 728 | $data['result'] = 'success'; |
729 | 729 | |
730 | - wp_send_json( $data ); |
|
731 | - } catch ( Exception $e ) { |
|
730 | + wp_send_json($data); |
|
731 | + } catch (Exception $e) { |
|
732 | 732 | $data += $this->build_display_items(); |
733 | 733 | $data['result'] = 'invalid_shipping_address'; |
734 | 734 | |
735 | - wp_send_json( $data ); |
|
735 | + wp_send_json($data); |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | |
@@ -740,22 +740,22 @@ discard block |
||
740 | 740 | * Update shipping method. |
741 | 741 | */ |
742 | 742 | public function ajax_update_shipping_method() { |
743 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
743 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
744 | 744 | |
745 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
746 | - define( 'WOOCOMMERCE_CART', true ); |
|
745 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
746 | + define('WOOCOMMERCE_CART', true); |
|
747 | 747 | } |
748 | 748 | |
749 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
750 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
749 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
750 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
751 | 751 | |
752 | - if ( is_array( $shipping_method ) ) { |
|
753 | - foreach ( $shipping_method as $i => $value ) { |
|
754 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
752 | + if (is_array($shipping_method)) { |
|
753 | + foreach ($shipping_method as $i => $value) { |
|
754 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
755 | 755 | } |
756 | 756 | } |
757 | 757 | |
758 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
758 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
759 | 759 | |
760 | 760 | WC()->cart->calculate_totals(); |
761 | 761 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | $data += $this->build_display_items(); |
764 | 764 | $data['result'] = 'success'; |
765 | 765 | |
766 | - wp_send_json( $data ); |
|
766 | + wp_send_json($data); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
@@ -774,31 +774,31 @@ discard block |
||
774 | 774 | * @return array $data |
775 | 775 | */ |
776 | 776 | public function ajax_get_selected_product_data() { |
777 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
777 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
778 | 778 | |
779 | - $product_id = absint( $_POST['product_id'] ); |
|
780 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
779 | + $product_id = absint($_POST['product_id']); |
|
780 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
781 | 781 | |
782 | - $product = wc_get_product( $product_id ); |
|
782 | + $product = wc_get_product($product_id); |
|
783 | 783 | |
784 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
785 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
784 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
785 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
786 | 786 | |
787 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
788 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
787 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
788 | + $variation_id = $product->get_matching_variation($attributes); |
|
789 | 789 | } else { |
790 | - $data_store = WC_Data_Store::load( 'product' ); |
|
791 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
790 | + $data_store = WC_Data_Store::load('product'); |
|
791 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
792 | 792 | } |
793 | 793 | |
794 | - if ( ! empty( $variation_id ) ) { |
|
795 | - $product = wc_get_product( $variation_id ); |
|
794 | + if ( ! empty($variation_id)) { |
|
795 | + $product = wc_get_product($variation_id); |
|
796 | 796 | } |
797 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
798 | - $product = wc_get_product( $product_id ); |
|
797 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
798 | + $product = wc_get_product($product_id); |
|
799 | 799 | } |
800 | 800 | |
801 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
801 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
802 | 802 | |
803 | 803 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
804 | 804 | |
@@ -806,28 +806,28 @@ discard block |
||
806 | 806 | $items = array(); |
807 | 807 | |
808 | 808 | $items[] = array( |
809 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
810 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
809 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
810 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
811 | 811 | ); |
812 | 812 | |
813 | - if ( wc_tax_enabled() ) { |
|
813 | + if (wc_tax_enabled()) { |
|
814 | 814 | $items[] = array( |
815 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
815 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
816 | 816 | 'amount' => 0, |
817 | 817 | 'pending' => true, |
818 | 818 | ); |
819 | 819 | } |
820 | 820 | |
821 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
821 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
822 | 822 | $items[] = array( |
823 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
823 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
824 | 824 | 'amount' => 0, |
825 | 825 | 'pending' => true, |
826 | 826 | ); |
827 | 827 | |
828 | - $data['shippingOptions'] = array( |
|
828 | + $data['shippingOptions'] = array( |
|
829 | 829 | 'id' => 'pending', |
830 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
830 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
831 | 831 | 'detail' => '', |
832 | 832 | 'amount' => 0, |
833 | 833 | ); |
@@ -836,15 +836,15 @@ discard block |
||
836 | 836 | $data['displayItems'] = $items; |
837 | 837 | $data['total'] = array( |
838 | 838 | 'label' => $this->total_label, |
839 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
839 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
840 | 840 | 'pending' => true, |
841 | 841 | ); |
842 | 842 | |
843 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
844 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
845 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
843 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
844 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
845 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
846 | 846 | |
847 | - wp_send_json( $data ); |
|
847 | + wp_send_json($data); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
@@ -855,37 +855,37 @@ discard block |
||
855 | 855 | * @return array $data |
856 | 856 | */ |
857 | 857 | public function ajax_add_to_cart() { |
858 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
858 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
859 | 859 | |
860 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
861 | - define( 'WOOCOMMERCE_CART', true ); |
|
860 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
861 | + define('WOOCOMMERCE_CART', true); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | WC()->shipping->reset_shipping(); |
865 | 865 | |
866 | - $product_id = absint( $_POST['product_id'] ); |
|
867 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
866 | + $product_id = absint($_POST['product_id']); |
|
867 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
868 | 868 | |
869 | - $product = wc_get_product( $product_id ); |
|
869 | + $product = wc_get_product($product_id); |
|
870 | 870 | |
871 | 871 | // First empty the cart to prevent wrong calculation. |
872 | 872 | WC()->cart->empty_cart(); |
873 | 873 | |
874 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
875 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
874 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
875 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
876 | 876 | |
877 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
878 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
877 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
878 | + $variation_id = $product->get_matching_variation($attributes); |
|
879 | 879 | } else { |
880 | - $data_store = WC_Data_Store::load( 'product' ); |
|
881 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
880 | + $data_store = WC_Data_Store::load('product'); |
|
881 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
882 | 882 | } |
883 | 883 | |
884 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
884 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
885 | 885 | } |
886 | 886 | |
887 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
888 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
887 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
888 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | WC()->cart->calculate_totals(); |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | $data += $this->build_display_items(); |
895 | 895 | $data['result'] = 'success'; |
896 | 896 | |
897 | - wp_send_json( $data ); |
|
897 | + wp_send_json($data); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -907,31 +907,31 @@ discard block |
||
907 | 907 | * @version 4.0.0 |
908 | 908 | */ |
909 | 909 | public function normalize_state() { |
910 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
911 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
912 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
913 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
910 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
911 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
912 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
913 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
914 | 914 | |
915 | - if ( $billing_state && $billing_country ) { |
|
916 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
915 | + if ($billing_state && $billing_country) { |
|
916 | + $valid_states = WC()->countries->get_states($billing_country); |
|
917 | 917 | |
918 | 918 | // Valid states found for country. |
919 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
920 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
921 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
919 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
920 | + foreach ($valid_states as $state_abbr => $state) { |
|
921 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
922 | 922 | $_POST['billing_state'] = $state_abbr; |
923 | 923 | } |
924 | 924 | } |
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
928 | - if ( $shipping_state && $shipping_country ) { |
|
929 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
928 | + if ($shipping_state && $shipping_country) { |
|
929 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
930 | 930 | |
931 | 931 | // Valid states found for country. |
932 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
933 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
934 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
932 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
933 | + foreach ($valid_states as $state_abbr => $state) { |
|
934 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
935 | 935 | $_POST['shipping_state'] = $state_abbr; |
936 | 936 | } |
937 | 937 | } |
@@ -946,19 +946,19 @@ discard block |
||
946 | 946 | * @version 4.0.0 |
947 | 947 | */ |
948 | 948 | public function ajax_create_order() { |
949 | - if ( WC()->cart->is_empty() ) { |
|
950 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
949 | + if (WC()->cart->is_empty()) { |
|
950 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
951 | 951 | } |
952 | 952 | |
953 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
954 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
953 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
954 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | $this->normalize_state(); |
958 | 958 | |
959 | 959 | WC()->checkout()->process_checkout(); |
960 | 960 | |
961 | - die( 0 ); |
|
961 | + die(0); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | * @version 4.0.0 |
969 | 969 | * @param array $address |
970 | 970 | */ |
971 | - protected function calculate_shipping( $address = array() ) { |
|
971 | + protected function calculate_shipping($address = array()) { |
|
972 | 972 | global $states; |
973 | 973 | |
974 | 974 | $country = $address['country']; |
@@ -985,28 +985,28 @@ discard block |
||
985 | 985 | * In some versions of Chrome, state can be a full name. So we need |
986 | 986 | * to convert that to abbreviation as WC is expecting that. |
987 | 987 | */ |
988 | - if ( 2 < strlen( $state ) ) { |
|
989 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
988 | + if (2 < strlen($state)) { |
|
989 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | WC()->shipping->reset_shipping(); |
993 | 993 | |
994 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
995 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
994 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
995 | + $postcode = wc_format_postcode($postcode, $country); |
|
996 | 996 | } |
997 | 997 | |
998 | - if ( $country ) { |
|
999 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1000 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
998 | + if ($country) { |
|
999 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
1000 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1001 | 1001 | } else { |
1002 | 1002 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
1003 | 1003 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
1004 | 1004 | } |
1005 | 1005 | |
1006 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
1007 | - WC()->customer->calculated_shipping( true ); |
|
1006 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
1007 | + WC()->customer->calculated_shipping(true); |
|
1008 | 1008 | } else { |
1009 | - WC()->customer->set_calculated_shipping( true ); |
|
1009 | + WC()->customer->set_calculated_shipping(true); |
|
1010 | 1010 | WC()->customer->save(); |
1011 | 1011 | } |
1012 | 1012 | |
@@ -1023,17 +1023,17 @@ discard block |
||
1023 | 1023 | $packages[0]['destination']['address'] = $address_1; |
1024 | 1024 | $packages[0]['destination']['address_2'] = $address_2; |
1025 | 1025 | |
1026 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1027 | - if ( $item['data']->needs_shipping() ) { |
|
1028 | - if ( isset( $item['line_total'] ) ) { |
|
1026 | + foreach (WC()->cart->get_cart() as $item) { |
|
1027 | + if ($item['data']->needs_shipping()) { |
|
1028 | + if (isset($item['line_total'])) { |
|
1029 | 1029 | $packages[0]['contents_cost'] += $item['line_total']; |
1030 | 1030 | } |
1031 | 1031 | } |
1032 | 1032 | } |
1033 | 1033 | |
1034 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1034 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1035 | 1035 | |
1036 | - WC()->shipping->calculate_shipping( $packages ); |
|
1036 | + WC()->shipping->calculate_shipping($packages); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | /** |
@@ -1042,19 +1042,19 @@ discard block |
||
1042 | 1042 | * @since 3.1.0 |
1043 | 1043 | * @version 4.0.0 |
1044 | 1044 | */ |
1045 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1046 | - if ( empty( $shipping_methods ) ) { |
|
1045 | + protected function build_shipping_methods($shipping_methods) { |
|
1046 | + if (empty($shipping_methods)) { |
|
1047 | 1047 | return array(); |
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | $shipping = array(); |
1051 | 1051 | |
1052 | - foreach ( $shipping_methods as $method ) { |
|
1052 | + foreach ($shipping_methods as $method) { |
|
1053 | 1053 | $shipping[] = array( |
1054 | 1054 | 'id' => $method['id'], |
1055 | 1055 | 'label' => $method['label'], |
1056 | 1056 | 'detail' => '', |
1057 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1057 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1058 | 1058 | ); |
1059 | 1059 | } |
1060 | 1060 | |
@@ -1068,69 +1068,69 @@ discard block |
||
1068 | 1068 | * @version 4.0.0 |
1069 | 1069 | */ |
1070 | 1070 | protected function build_display_items() { |
1071 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1072 | - define( 'WOOCOMMERCE_CART', true ); |
|
1071 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1072 | + define('WOOCOMMERCE_CART', true); |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | $items = array(); |
1076 | 1076 | $subtotal = 0; |
1077 | 1077 | |
1078 | 1078 | // Default show only subtotal instead of itemization. |
1079 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1080 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1079 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1080 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1081 | 1081 | $amount = $cart_item['line_subtotal']; |
1082 | - $subtotal += $cart_item['line_subtotal']; |
|
1082 | + $subtotal += $cart_item['line_subtotal']; |
|
1083 | 1083 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1084 | 1084 | |
1085 | 1085 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1086 | 1086 | |
1087 | 1087 | $item = array( |
1088 | 1088 | 'label' => $product_name . $quantity_label, |
1089 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1089 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1090 | 1090 | ); |
1091 | 1091 | |
1092 | 1092 | $items[] = $item; |
1093 | 1093 | } |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1097 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1098 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1099 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1100 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1096 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1097 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1098 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1099 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1100 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1101 | 1101 | |
1102 | - if ( wc_tax_enabled() ) { |
|
1102 | + if (wc_tax_enabled()) { |
|
1103 | 1103 | $items[] = array( |
1104 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1105 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1104 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1105 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1106 | 1106 | ); |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - if ( WC()->cart->needs_shipping() ) { |
|
1109 | + if (WC()->cart->needs_shipping()) { |
|
1110 | 1110 | $items[] = array( |
1111 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1112 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1111 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1112 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1113 | 1113 | ); |
1114 | 1114 | } |
1115 | 1115 | |
1116 | - if ( WC()->cart->has_discount() ) { |
|
1116 | + if (WC()->cart->has_discount()) { |
|
1117 | 1117 | $items[] = array( |
1118 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1119 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1118 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1119 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1120 | 1120 | ); |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1123 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1124 | 1124 | $cart_fees = WC()->cart->fees; |
1125 | 1125 | } else { |
1126 | 1126 | $cart_fees = WC()->cart->get_fees(); |
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | // Include fees and taxes as display items. |
1130 | - foreach ( $cart_fees as $key => $fee ) { |
|
1130 | + foreach ($cart_fees as $key => $fee) { |
|
1131 | 1131 | $items[] = array( |
1132 | 1132 | 'label' => $fee->name, |
1133 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1133 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1134 | 1134 | ); |
1135 | 1135 | } |
1136 | 1136 | |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | 'displayItems' => $items, |
1139 | 1139 | 'total' => array( |
1140 | 1140 | 'label' => $this->total_label, |
1141 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1141 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1142 | 1142 | 'pending' => false, |
1143 | 1143 | ), |
1144 | 1144 | ); |