Completed
Pull Request — master (#1239)
by
unknown
01:44
created
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
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
 
@@ -64,41 +64,41 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		self::$_this            = $this;
67
-		$this->stripe_settings  = get_option( 'woocommerce_stripe_settings', array() );
68
-		$this->testmode         = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
69
-		$this->publishable_key  = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
70
-		$this->secret_key       = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : '';
71
-		$this->total_label      = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
67
+		$this->stripe_settings  = get_option('woocommerce_stripe_settings', array());
68
+		$this->testmode         = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
69
+		$this->publishable_key  = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
70
+		$this->secret_key       = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : '';
71
+		$this->total_label      = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
72 72
 
73
-		if ( $this->testmode ) {
74
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
75
-			$this->secret_key      = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : '';
73
+		if ($this->testmode) {
74
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
75
+			$this->secret_key      = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : '';
76 76
 		}
77 77
 
78
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
78
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
79 79
 
80 80
 		// Checks if Stripe Gateway is enabled.
81
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
81
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
82 82
 			return;
83 83
 		}
84 84
 
85 85
 		// Checks if Payment Request is enabled.
86
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
86
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
87 87
 			return;
88 88
 		}
89 89
 
90 90
 		// Don't load for change payment method page.
91
-		if ( isset( $_GET['change_payment_method'] ) ) {
91
+		if (isset($_GET['change_payment_method'])) {
92 92
 			return;
93 93
 		}
94 94
 
95
-		$wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
95
+		$wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2);
96 96
 
97
-		if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) {
97
+		if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) {
98 98
 			return;
99 99
 		}
100 100
 
101
-		add_action( 'template_redirect', array( $this, 'set_session' ) );
101
+		add_action('template_redirect', array($this, 'set_session'));
102 102
 		$this->init();
103 103
 	}
104 104
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @return array The list of countries.
110 110
 	 */
111 111
 	public function get_stripe_supported_countries() {
112
-		return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) );
112
+		return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US'));
113 113
 	}
114 114
 
115 115
 	/**
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 	public function are_keys_set() {
122 122
 		// NOTE: updates to this function should be added to are_keys_set()
123 123
 		// in includes/abstracts/abstract-wc-stripe-payment-gateway.php
124
-		if ( $this->testmode ) {
125
-			return preg_match( '/^pk_test_/', $this->publishable_key )
126
-			       && preg_match( '/^[rs]k_test_/', $this->secret_key );
124
+		if ($this->testmode) {
125
+			return preg_match('/^pk_test_/', $this->publishable_key)
126
+			       && preg_match('/^[rs]k_test_/', $this->secret_key);
127 127
 		} else {
128
-			return preg_match( '/^pk_live_/', $this->publishable_key )
129
-			       && preg_match( '/^[rs]k_live_/', $this->secret_key );
128
+			return preg_match('/^pk_live_/', $this->publishable_key)
129
+			       && preg_match('/^[rs]k_live_/', $this->secret_key);
130 130
 		}
131 131
 	}
132 132
 
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 	 * @since 4.0.0
148 148
 	 */
149 149
 	public function set_session() {
150
-		if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
150
+		if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) {
151 151
 			return;
152 152
 		}
153 153
 
154
-		WC()->session->set_customer_session_cookie( true );
154
+		WC()->session->set_customer_session_cookie(true);
155 155
 	}
156 156
 
157 157
 	/**
@@ -161,30 +161,30 @@  discard block
 block discarded – undo
161 161
 	 * @version 4.0.0
162 162
 	 */
163 163
 	public function init() {
164
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
164
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
165 165
 
166
-		add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
167
-		add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
166
+		add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
167
+		add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
168 168
 
169
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
170
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
169
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
170
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
171 171
 
172
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
173
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
172
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
173
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
174 174
 
175
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
176
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
177
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
178
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
179
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
180
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
181
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
182
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
175
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
176
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
177
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
178
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
179
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
180
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
181
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
182
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
183 183
 
184
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
185
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
184
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
185
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
186 186
 
187
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
187
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
188 188
 	}
189 189
 
190 190
 	/**
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @return string
196 196
 	 */
197 197
 	public function get_button_type() {
198
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
198
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
199 199
 	}
200 200
 
201 201
 	/**
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	 * @return string
207 207
 	 */
208 208
 	public function get_button_theme() {
209
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
209
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
210 210
 	}
211 211
 
212 212
 	/**
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @return string
218 218
 	 */
219 219
 	public function get_button_height() {
220
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
220
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
221 221
 	}
222 222
 
223 223
 	/**
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	 * @return string
240 240
 	 */
241 241
 	public function get_button_branded_type() {
242
-		return isset( $this->stripe_settings['payment_request_button_branded_type'] ) ? $this->stripe_settings['payment_request_button_branded_type'] : 'default';
242
+		return isset($this->stripe_settings['payment_request_button_branded_type']) ? $this->stripe_settings['payment_request_button_branded_type'] : 'default';
243 243
 	}
244 244
 
245 245
 	/**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @return string
273 273
 	 */
274 274
 	public function get_button_label() {
275
-		return isset( $this->stripe_settings['payment_request_button_label'] ) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now';
275
+		return isset($this->stripe_settings['payment_request_button_label']) ? $this->stripe_settings['payment_request_button_label'] : 'Buy now';
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,22 +282,22 @@  discard block
 block discarded – undo
282 282
 	 * @version 4.0.0
283 283
 	 */
284 284
 	public function get_product_data() {
285
-		if ( ! is_product() ) {
285
+		if ( ! is_product()) {
286 286
 			return false;
287 287
 		}
288 288
 
289 289
 		global $post;
290 290
 
291
-		$product = wc_get_product( $post->ID );
291
+		$product = wc_get_product($post->ID);
292 292
 
293
-		if ( 'variable' === $product->get_type() ) {
294
-			$attributes = wc_clean( wp_unslash( $_GET ) );
293
+		if ('variable' === $product->get_type()) {
294
+			$attributes = wc_clean(wp_unslash($_GET));
295 295
 
296
-			$data_store   = WC_Data_Store::load( 'product' );
297
-			$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
296
+			$data_store   = WC_Data_Store::load('product');
297
+			$variation_id = $data_store->find_matching_product_variation($product, $attributes);
298 298
 
299
-			if ( ! empty( $variation_id ) ) {
300
-				$product = wc_get_product( $variation_id );
299
+			if ( ! empty($variation_id)) {
300
+				$product = wc_get_product($variation_id);
301 301
 			}
302 302
 		}
303 303
 
@@ -306,27 +306,27 @@  discard block
 block discarded – undo
306 306
 
307 307
 		$items[] = array(
308 308
 			'label'  => $product->get_name(),
309
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ),
309
+			'amount' => WC_Stripe_Helper::get_stripe_amount($product->get_price()),
310 310
 		);
311 311
 
312
-		if ( wc_tax_enabled() ) {
312
+		if (wc_tax_enabled()) {
313 313
 			$items[] = array(
314
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
314
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
315 315
 				'amount'  => 0,
316 316
 				'pending' => true,
317 317
 			);
318 318
 		}
319 319
 
320
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
320
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
321 321
 			$items[] = array(
322
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
322
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
323 323
 				'amount'  => 0,
324 324
 				'pending' => true,
325 325
 			);
326 326
 
327 327
 			$data['shippingOptions'] = array(
328 328
 				'id'     => 'pending',
329
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
329
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
330 330
 				'detail' => '',
331 331
 				'amount' => 0,
332 332
 			);
@@ -334,37 +334,37 @@  discard block
 block discarded – undo
334 334
 
335 335
 		$data['displayItems'] = $items;
336 336
 		$data['total']        = array(
337
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
338
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $product->get_price() ),
337
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
338
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($product->get_price()),
339 339
 			'pending' => true,
340 340
 		);
341 341
 
342
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
343
-		$data['currency']        = strtolower( get_woocommerce_currency() );
344
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
342
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
343
+		$data['currency']        = strtolower(get_woocommerce_currency());
344
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
345 345
 
346
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
346
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
347 347
 	}
348 348
 
349 349
 	/**
350 350
 	 * Filters the gateway title to reflect Payment Request type
351 351
 	 *
352 352
 	 */
353
-	public function filter_gateway_title( $title, $id ) {
353
+	public function filter_gateway_title($title, $id) {
354 354
 		global $post;
355 355
 
356
-		if ( ! is_object( $post ) ) {
356
+		if ( ! is_object($post)) {
357 357
 			return $title;
358 358
 		}
359 359
 
360
-		$order        = wc_get_order( $post->ID );
361
-		$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
360
+		$order        = wc_get_order($post->ID);
361
+		$method_title = is_object($order) ? $order->get_payment_method_title() : '';
362 362
 
363
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
363
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
364 364
 			return $method_title;
365 365
 		}
366 366
 
367
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
367
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
368 368
 			return $method_title;
369 369
 		}
370 370
 
@@ -377,16 +377,16 @@  discard block
 block discarded – undo
377 377
 	 * @since 3.1.4
378 378
 	 * @version 4.0.0
379 379
 	 */
380
-	public function postal_code_validation( $valid, $postcode, $country ) {
380
+	public function postal_code_validation($valid, $postcode, $country) {
381 381
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
382 382
 
383
-		if ( ! isset( $gateways['stripe'] ) ) {
383
+		if ( ! isset($gateways['stripe'])) {
384 384
 			return $valid;
385 385
 		}
386 386
 
387
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
387
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
388 388
 
389
-		if ( 'apple_pay' !== $payment_request_type ) {
389
+		if ('apple_pay' !== $payment_request_type) {
390 390
 			return $valid;
391 391
 		}
392 392
 
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
397 397
 		 * Note that this only works with shipping providers that don't validate full postal codes.
398 398
 		 */
399
-		if ( 'GB' === $country || 'CA' === $country ) {
399
+		if ('GB' === $country || 'CA' === $country) {
400 400
 			return true;
401 401
 		}
402 402
 
@@ -411,22 +411,22 @@  discard block
 block discarded – undo
411 411
 	 * @param int $order_id
412 412
 	 * @param array $posted_data The posted data from checkout form.
413 413
 	 */
414
-	public function add_order_meta( $order_id, $posted_data ) {
415
-		if ( empty( $_POST['payment_request_type'] ) ) {
414
+	public function add_order_meta($order_id, $posted_data) {
415
+		if (empty($_POST['payment_request_type'])) {
416 416
 			return;
417 417
 		}
418 418
 
419
-		$order = wc_get_order( $order_id );
419
+		$order = wc_get_order($order_id);
420 420
 
421
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
421
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
422 422
 
423
-		if ( 'apple_pay' === $payment_request_type ) {
424
-			$order->set_payment_method_title( 'Apple Pay (Stripe)' );
423
+		if ('apple_pay' === $payment_request_type) {
424
+			$order->set_payment_method_title('Apple Pay (Stripe)');
425 425
 			$order->save();
426 426
 		}
427 427
 
428
-		if ( 'payment_request_api' === $payment_request_type ) {
429
-			$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
428
+		if ('payment_request_api' === $payment_request_type) {
429
+			$order->set_payment_method_title('Chrome Payment Request (Stripe)');
430 430
 			$order->save();
431 431
 		}
432 432
 	}
@@ -464,20 +464,20 @@  discard block
 block discarded – undo
464 464
 	 * @return bool
465 465
 	 */
466 466
 	public function allowed_items_in_cart() {
467
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
468
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
467
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
468
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
469 469
 
470
-			if ( ! in_array( $_product->get_type(), $this->supported_product_types() ) ) {
470
+			if ( ! in_array($_product->get_type(), $this->supported_product_types())) {
471 471
 				return false;
472 472
 			}
473 473
 
474 474
 			// Trial subscriptions with shipping are not supported
475
-			if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) {
475
+			if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) {
476 476
 				return false;
477 477
 			}
478 478
 
479 479
 			// Pre Orders compatbility where we don't support charge upon release.
480
-			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() ) ) {
480
+			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())) {
481 481
 				return false;
482 482
 			}
483 483
 		}
@@ -493,59 +493,59 @@  discard block
 block discarded – undo
493 493
 	 */
494 494
 	public function scripts() {
495 495
 		// If keys are not set bail.
496
-		if ( ! $this->are_keys_set() ) {
497
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
496
+		if ( ! $this->are_keys_set()) {
497
+			WC_Stripe_Logger::log('Keys are not set correctly.');
498 498
 			return;
499 499
 		}
500 500
 
501 501
 		// If no SSL bail.
502
-		if ( ! $this->testmode && ! is_ssl() ) {
503
-			WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' );
502
+		if ( ! $this->testmode && ! is_ssl()) {
503
+			WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.');
504 504
 			return;
505 505
 		}
506 506
 
507
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
507
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
508 508
 			return;
509 509
 		}
510 510
 
511
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
511
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
512 512
 			return;
513 513
 		}
514 514
 
515
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
515
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
516 516
 
517 517
 		$stripe_params = array(
518
-			'ajax_url'        => WC_AJAX::get_endpoint( '%%endpoint%%' ),
518
+			'ajax_url'        => WC_AJAX::get_endpoint('%%endpoint%%'),
519 519
 			'stripe'          => array(
520 520
 				'key'                => $this->publishable_key,
521
-				'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
521
+				'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
522 522
 			),
523 523
 			'nonce'           => array(
524
-				'payment'                   => wp_create_nonce( 'wc-stripe-payment-request' ),
525
-				'shipping'                  => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
526
-				'update_shipping'           => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
527
-				'checkout'                  => wp_create_nonce( 'woocommerce-process_checkout' ),
528
-				'add_to_cart'               => wp_create_nonce( 'wc-stripe-add-to-cart' ),
529
-				'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
530
-				'log_errors'                => wp_create_nonce( 'wc-stripe-log-errors' ),
531
-				'clear_cart'                => wp_create_nonce( 'wc-stripe-clear-cart' ),
524
+				'payment'                   => wp_create_nonce('wc-stripe-payment-request'),
525
+				'shipping'                  => wp_create_nonce('wc-stripe-payment-request-shipping'),
526
+				'update_shipping'           => wp_create_nonce('wc-stripe-update-shipping-method'),
527
+				'checkout'                  => wp_create_nonce('woocommerce-process_checkout'),
528
+				'add_to_cart'               => wp_create_nonce('wc-stripe-add-to-cart'),
529
+				'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'),
530
+				'log_errors'                => wp_create_nonce('wc-stripe-log-errors'),
531
+				'clear_cart'                => wp_create_nonce('wc-stripe-clear-cart'),
532 532
 			),
533 533
 			'i18n'            => array(
534
-				'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
534
+				'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
535 535
 				/* translators: Do not translate the [option] placeholder */
536
-				'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
536
+				'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
537 537
 			),
538 538
 			'checkout'        => array(
539 539
 				'url'            => wc_get_checkout_url(),
540
-				'currency_code'  => strtolower( get_woocommerce_currency() ),
541
-				'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
540
+				'currency_code'  => strtolower(get_woocommerce_currency()),
541
+				'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
542 542
 				'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
543 543
 			),
544 544
 			'button'          => array(
545 545
 				'type'         => $this->get_button_type(),
546 546
 				'theme'        => $this->get_button_theme(),
547 547
 				'height'       => $this->get_button_height(),
548
-				'locale'       => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US.
548
+				'locale'       => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US.
549 549
 				'is_custom'    => $this->is_custom_button(),
550 550
 				'is_branded'   => $this->is_branded_button(),
551 551
 				'css_selector' => $this->custom_button_selector(),
@@ -555,15 +555,15 @@  discard block
 block discarded – undo
555 555
 			'product'         => $this->get_product_data(),
556 556
 		);
557 557
 
558
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
559
-		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 );
558
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
559
+		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);
560 560
 
561
-		wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) );
561
+		wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params));
562 562
 
563
-		wp_enqueue_script( 'wc_stripe_payment_request' );
563
+		wp_enqueue_script('wc_stripe_payment_request');
564 564
 
565 565
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
566
-		if ( isset( $gateways['stripe'] ) ) {
566
+		if (isset($gateways['stripe'])) {
567 567
 			$gateways['stripe']->payment_scripts();
568 568
 		}
569 569
 	}
@@ -579,31 +579,31 @@  discard block
 block discarded – undo
579 579
 
580 580
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
581 581
 
582
-		if ( ! isset( $gateways['stripe'] ) ) {
582
+		if ( ! isset($gateways['stripe'])) {
583 583
 			return;
584 584
 		}
585 585
 
586
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
586
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
587 587
 			return;
588 588
 		}
589 589
 
590
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
590
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
591 591
 			return;
592 592
 		}
593 593
 
594
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
594
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
595 595
 			return;
596
-		} else if ( ! $this->should_show_payment_button_on_cart() ) {
596
+		} else if ( ! $this->should_show_payment_button_on_cart()) {
597 597
 			return;
598 598
 		}
599 599
 		?>
600 600
 		<div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;display:none;">
601 601
 			<div id="wc-stripe-payment-request-button">
602 602
 				<?php
603
-					if ( $this->is_custom_button() ) {
604
-						$label = esc_html( $this->get_button_label() );
605
-						$class_name = esc_attr( 'button ' .  $this->get_button_theme() );
606
-						$style = esc_attr( 'height:' . $this->get_button_height() . 'px;' );
603
+					if ($this->is_custom_button()) {
604
+						$label = esc_html($this->get_button_label());
605
+						$class_name = esc_attr('button ' . $this->get_button_theme());
606
+						$style = esc_attr('height:' . $this->get_button_height() . 'px;');
607 607
 						echo "<button id=\"wc-stripe-custom-button\" class=\"$class_name\" style=\"$style\"> $label </button>";
608 608
 					}
609 609
 				?>
@@ -624,25 +624,25 @@  discard block
 block discarded – undo
624 624
 
625 625
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
626 626
 
627
-		if ( ! isset( $gateways['stripe'] ) ) {
627
+		if ( ! isset($gateways['stripe'])) {
628 628
 			return;
629 629
 		}
630 630
 
631
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
631
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
632 632
 			return;
633 633
 		}
634 634
 
635
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
635
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
636 636
 			return;
637 637
 		}
638 638
 
639
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
639
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
640 640
 			return;
641
-		} else if ( ! $this->should_show_payment_button_on_cart() ) {
641
+		} else if ( ! $this->should_show_payment_button_on_cart()) {
642 642
 			return;
643 643
 		}
644 644
 		?>
645
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> &mdash;</p>
645
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> &mdash;</p>
646 646
 		<?php
647 647
 	}
648 648
 
@@ -654,11 +654,11 @@  discard block
 block discarded – undo
654 654
 	 * @return bool
655 655
 	 */
656 656
 	private function should_show_payment_button_on_cart() {
657
-		if ( ! apply_filters( 'wc_stripe_show_payment_request_on_cart', true ) ) {
657
+		if ( ! apply_filters('wc_stripe_show_payment_request_on_cart', true)) {
658 658
 			return false;
659 659
 		}
660
-		if ( ! $this->allowed_items_in_cart() ) {
661
-			WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
660
+		if ( ! $this->allowed_items_in_cart()) {
661
+			WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
662 662
 			return false;
663 663
 		}
664 664
 		return true;
@@ -674,32 +674,32 @@  discard block
 block discarded – undo
674 674
 	private function should_show_payment_button_on_product_page() {
675 675
 		global $post;
676 676
 
677
-		$product = wc_get_product( $post->ID );
677
+		$product = wc_get_product($post->ID);
678 678
 
679
-		if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
679
+		if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
680 680
 			return false;
681 681
 		}
682 682
 
683
-		if ( ! is_object( $product ) || ! in_array( $product->get_type(), $this->supported_product_types() ) ) {
683
+		if ( ! is_object($product) || ! in_array($product->get_type(), $this->supported_product_types())) {
684 684
 			return false;
685 685
 		}
686 686
 
687 687
 		// Trial subscriptions with shipping are not supported
688
-		if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) {
688
+		if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) {
689 689
 			return false;
690 690
 		}
691 691
 
692 692
 		// Pre Orders charge upon release not supported.
693
-		if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
694
-			WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
693
+		if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
694
+			WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
695 695
 			return false;
696 696
 		}
697 697
 
698 698
 		// File upload addon not supported
699
-		if ( class_exists( 'WC_Product_Addons_Helper' ) ) {
700
-			$product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() );
701
-			foreach ( $product_addons as $addon ) {
702
-				if ( 'file_upload' === $addon['type'] ) {
699
+		if (class_exists('WC_Product_Addons_Helper')) {
700
+			$product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id());
701
+			foreach ($product_addons as $addon) {
702
+				if ('file_upload' === $addon['type']) {
703 703
 					return false;
704 704
 				}
705 705
 			}
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
 	 * @version 4.0.0
716 716
 	 */
717 717
 	public function ajax_log_errors() {
718
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
718
+		check_ajax_referer('wc-stripe-log-errors', 'security');
719 719
 
720
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
720
+		$errors = wc_clean(stripslashes($_POST['errors']));
721 721
 
722
-		WC_Stripe_Logger::log( $errors );
722
+		WC_Stripe_Logger::log($errors);
723 723
 
724 724
 		exit;
725 725
 	}
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 	 * @version 4.0.0
732 732
 	 */
733 733
 	public function ajax_clear_cart() {
734
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
734
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
735 735
 
736 736
 		WC()->cart->empty_cart();
737 737
 		exit;
@@ -741,10 +741,10 @@  discard block
 block discarded – undo
741 741
 	 * Get cart details.
742 742
 	 */
743 743
 	public function ajax_get_cart_details() {
744
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
744
+		check_ajax_referer('wc-stripe-payment-request', 'security');
745 745
 
746
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
747
-			define( 'WOOCOMMERCE_CART', true );
746
+		if ( ! defined('WOOCOMMERCE_CART')) {
747
+			define('WOOCOMMERCE_CART', true);
748 748
 		}
749 749
 
750 750
 		WC()->cart->calculate_totals();
@@ -755,14 +755,14 @@  discard block
 block discarded – undo
755 755
 		$data = array(
756 756
 			'shipping_required' => WC()->cart->needs_shipping(),
757 757
 			'order_data'        => array(
758
-				'currency'     => strtolower( $currency ),
759
-				'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
758
+				'currency'     => strtolower($currency),
759
+				'country_code' => substr(get_option('woocommerce_default_country'), 0, 2),
760 760
 			),
761 761
 		);
762 762
 
763 763
 		$data['order_data'] += $this->build_display_items();
764 764
 
765
-		wp_send_json( $data );
765
+		wp_send_json($data);
766 766
 	}
767 767
 
768 768
 	/**
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 	 * @see WC_Shipping::get_packages().
774 774
 	 */
775 775
 	public function ajax_get_shipping_options() {
776
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
776
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
777 777
 
778 778
 		$shipping_address = filter_input_array(
779 779
 			INPUT_POST,
@@ -788,15 +788,15 @@  discard block
 block discarded – undo
788 788
 		);
789 789
 
790 790
 		$should_show_itemized_view = function() {
791
-			$array = filter_input_array( INPUT_POST, [ 'is_product_page' => FILTER_SANITIZE_STRING ] );
792
-			if ( isset( $array['is_product_page'] ) ) {
793
-				return filter_var( $array['is_product_page'], FILTER_VALIDATE_BOOLEAN );
791
+			$array = filter_input_array(INPUT_POST, ['is_product_page' => FILTER_SANITIZE_STRING]);
792
+			if (isset($array['is_product_page'])) {
793
+				return filter_var($array['is_product_page'], FILTER_VALIDATE_BOOLEAN);
794 794
 			}
795 795
 			return false;
796 796
 		};
797 797
 
798
-		$data = $this->get_shipping_options( $shipping_address, $should_show_itemized_view() );
799
-		wp_send_json( $data );
798
+		$data = $this->get_shipping_options($shipping_address, $should_show_itemized_view());
799
+		wp_send_json($data);
800 800
 	}
801 801
 
802 802
 	/**
@@ -808,66 +808,66 @@  discard block
 block discarded – undo
808 808
 	 * @return array Shipping options data.
809 809
 	 * phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag
810 810
 	 */
811
-	public function get_shipping_options( $shipping_address, $itemized_display_items = false ) {
811
+	public function get_shipping_options($shipping_address, $itemized_display_items = false) {
812 812
 		try {
813 813
 			// Set the shipping options.
814 814
 			$data = array();
815 815
 
816 816
 			// Remember current shipping method before resetting.
817
-			$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
818
-			$this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $shipping_address ) );
817
+			$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
818
+			$this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $shipping_address));
819 819
 
820 820
 			$packages = WC()->shipping->get_packages();
821 821
 
822
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
823
-				foreach ( $packages as $package_key => $package ) {
824
-					if ( empty( $package['rates'] ) ) {
825
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
822
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
823
+				foreach ($packages as $package_key => $package) {
824
+					if (empty($package['rates'])) {
825
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
826 826
 					}
827 827
 
828
-					foreach ( $package['rates'] as $key => $rate ) {
828
+					foreach ($package['rates'] as $key => $rate) {
829 829
 						$data['shipping_options'][] = array(
830 830
 							'id'     => $rate->id,
831 831
 							'label'  => $rate->label,
832 832
 							'detail' => '',
833
-							'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
833
+							'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost),
834 834
 						);
835 835
 					}
836 836
 				}
837 837
 			} else {
838
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
838
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
839 839
 			}
840 840
 
841 841
 			// The first shipping option is automatically applied on the client.
842 842
 			// Keep chosen shipping method by sorting shipping options if the method still available for new address.
843 843
 			// Fallback to the first available shipping method.
844
-			if ( isset( $data['shipping_options'][0] ) ) {
845
-				if ( isset( $chosen_shipping_methods[0] ) ) {
844
+			if (isset($data['shipping_options'][0])) {
845
+				if (isset($chosen_shipping_methods[0])) {
846 846
 					$chosen_method_id         = $chosen_shipping_methods[0];
847
-					$compare_shipping_options = function ( $a, $b ) use ( $chosen_method_id ) {
848
-						if ( $a['id'] === $chosen_method_id ) {
847
+					$compare_shipping_options = function($a, $b) use ($chosen_method_id) {
848
+						if ($a['id'] === $chosen_method_id) {
849 849
 							return -1;
850 850
 						}
851 851
 
852
-						if ( $b['id'] === $chosen_method_id ) {
852
+						if ($b['id'] === $chosen_method_id) {
853 853
 							return 1;
854 854
 						}
855 855
 
856 856
 						return 0;
857 857
 					};
858
-					usort( $data['shipping_options'], $compare_shipping_options );
858
+					usort($data['shipping_options'], $compare_shipping_options);
859 859
 				}
860 860
 
861 861
 				$first_shipping_method_id = $data['shipping_options'][0]['id'];
862
-				$this->update_shipping_method( [ $first_shipping_method_id ] );
862
+				$this->update_shipping_method([$first_shipping_method_id]);
863 863
 			}
864 864
 
865 865
 			WC()->cart->calculate_totals();
866 866
 
867
-			$data          += $this->build_display_items( $itemized_display_items );
867
+			$data          += $this->build_display_items($itemized_display_items);
868 868
 			$data['result'] = 'success';
869
-		} catch ( Exception $e ) {
870
-			$data          += $this->build_display_items( $itemized_display_items );
869
+		} catch (Exception $e) {
870
+			$data          += $this->build_display_items($itemized_display_items);
871 871
 			$data['result'] = 'invalid_shipping_address';
872 872
 		}
873 873
 
@@ -878,30 +878,30 @@  discard block
 block discarded – undo
878 878
 	 * Update shipping method.
879 879
 	 */
880 880
 	public function ajax_update_shipping_method() {
881
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
881
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
882 882
 
883
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
884
-			define( 'WOOCOMMERCE_CART', true );
883
+		if ( ! defined('WOOCOMMERCE_CART')) {
884
+			define('WOOCOMMERCE_CART', true);
885 885
 		}
886 886
 
887
-		$shipping_methods = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
888
-		$this->update_shipping_method( $shipping_methods );
887
+		$shipping_methods = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
888
+		$this->update_shipping_method($shipping_methods);
889 889
 
890 890
 		WC()->cart->calculate_totals();
891 891
 
892 892
 		$should_show_itemized_view = function() {
893
-			$array = filter_input_array( INPUT_POST, [ 'is_product_page' => FILTER_SANITIZE_STRING ] );
894
-			if ( isset( $array['is_product_page'] ) ) {
895
-				return filter_var( $array['is_product_page'], FILTER_VALIDATE_BOOLEAN );
893
+			$array = filter_input_array(INPUT_POST, ['is_product_page' => FILTER_SANITIZE_STRING]);
894
+			if (isset($array['is_product_page'])) {
895
+				return filter_var($array['is_product_page'], FILTER_VALIDATE_BOOLEAN);
896 896
 			}
897 897
 			return false;
898 898
 		};
899 899
 
900 900
 		$data           = array();
901
-		$data          += $this->build_display_items( $should_show_itemized_view() );
901
+		$data          += $this->build_display_items($should_show_itemized_view());
902 902
 		$data['result'] = 'success';
903 903
 
904
-		wp_send_json( $data );
904
+		wp_send_json($data);
905 905
 	}
906 906
 
907 907
 	/**
@@ -909,16 +909,16 @@  discard block
 block discarded – undo
909 909
 	 *
910 910
 	 * @param array $shipping_methods Array of selected shipping methods ids.
911 911
 	 */
912
-	public function update_shipping_method( $shipping_methods ) {
913
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
912
+	public function update_shipping_method($shipping_methods) {
913
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
914 914
 
915
-		if ( is_array( $shipping_methods ) ) {
916
-			foreach ( $shipping_methods as $i => $value ) {
917
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
915
+		if (is_array($shipping_methods)) {
916
+			foreach ($shipping_methods as $i => $value) {
917
+				$chosen_shipping_methods[$i] = wc_clean($value);
918 918
 			}
919 919
 		}
920 920
 
921
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
921
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
922 922
 	}
923 923
 
924 924
 	/**
@@ -929,38 +929,38 @@  discard block
 block discarded – undo
929 929
 	 * @return array $data
930 930
 	 */
931 931
 	public function ajax_get_selected_product_data() {
932
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
932
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
933 933
 
934 934
 		try {
935
-			$product_id   = absint( $_POST['product_id'] );
936
-			$qty          = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id );
937
-			$addon_value  = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0;
938
-			$product      = wc_get_product( $product_id );
935
+			$product_id   = absint($_POST['product_id']);
936
+			$qty          = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id);
937
+			$addon_value  = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0;
938
+			$product      = wc_get_product($product_id);
939 939
 			$variation_id = null;
940 940
 
941
-			if ( ! is_a( $product, 'WC_Product' ) ) {
942
-				throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) );
941
+			if ( ! is_a($product, 'WC_Product')) {
942
+				throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id));
943 943
 			}
944 944
 
945
-			if ( 'variable' === $product->get_type() && isset( $_POST['attributes'] ) ) {
946
-				$attributes = wc_clean( wp_unslash( $_POST['attributes'] ) );
945
+			if ('variable' === $product->get_type() && isset($_POST['attributes'])) {
946
+				$attributes = wc_clean(wp_unslash($_POST['attributes']));
947 947
 
948
-				$data_store   = WC_Data_Store::load( 'product' );
949
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
948
+				$data_store   = WC_Data_Store::load('product');
949
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
950 950
 
951
-				if ( ! empty( $variation_id ) ) {
952
-					$product = wc_get_product( $variation_id );
951
+				if ( ! empty($variation_id)) {
952
+					$product = wc_get_product($variation_id);
953 953
 				}
954 954
 			}
955 955
 
956 956
 			// Force quantity to 1 if sold individually and check for existing item in cart.
957
-			if ( $product->is_sold_individually() ) {
958
-				$qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id );
957
+			if ($product->is_sold_individually()) {
958
+				$qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id);
959 959
 			}
960 960
 
961
-			if ( ! $product->has_enough_stock( $qty ) ) {
961
+			if ( ! $product->has_enough_stock($qty)) {
962 962
 				/* translators: 1: product name 2: quantity in stock */
963
-				throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) );
963
+				throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product)));
964 964
 			}
965 965
 
966 966
 			$total = $qty * $product->get_price() + $addon_value;
@@ -972,27 +972,27 @@  discard block
 block discarded – undo
972 972
 
973 973
 			$items[] = array(
974 974
 				'label'  => $product->get_name() . $quantity_label,
975
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
975
+				'amount' => WC_Stripe_Helper::get_stripe_amount($total),
976 976
 			);
977 977
 
978
-			if ( wc_tax_enabled() ) {
978
+			if (wc_tax_enabled()) {
979 979
 				$items[] = array(
980
-					'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
980
+					'label'   => __('Tax', 'woocommerce-gateway-stripe'),
981 981
 					'amount'  => 0,
982 982
 					'pending' => true,
983 983
 				);
984 984
 			}
985 985
 
986
-			if ( wc_shipping_enabled() && $product->needs_shipping() ) {
986
+			if (wc_shipping_enabled() && $product->needs_shipping()) {
987 987
 				$items[] = array(
988
-					'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
988
+					'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
989 989
 					'amount'  => 0,
990 990
 					'pending' => true,
991 991
 				);
992 992
 
993 993
 				$data['shippingOptions'] = array(
994 994
 					'id'     => 'pending',
995
-					'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
995
+					'label'  => __('Pending', 'woocommerce-gateway-stripe'),
996 996
 					'detail' => '',
997 997
 					'amount' => 0,
998 998
 				);
@@ -1001,17 +1001,17 @@  discard block
 block discarded – undo
1001 1001
 			$data['displayItems'] = $items;
1002 1002
 			$data['total']        = array(
1003 1003
 				'label'   => $this->total_label,
1004
-				'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
1004
+				'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
1005 1005
 				'pending' => true,
1006 1006
 			);
1007 1007
 
1008
-			$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
1009
-			$data['currency']        = strtolower( get_woocommerce_currency() );
1010
-			$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
1008
+			$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
1009
+			$data['currency']        = strtolower(get_woocommerce_currency());
1010
+			$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
1011 1011
 
1012
-			wp_send_json( $data );
1013
-		} catch ( Exception $e ) {
1014
-			wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) );
1012
+			wp_send_json($data);
1013
+		} catch (Exception $e) {
1014
+			wp_send_json(array('error' => wp_strip_all_tags($e->getMessage())));
1015 1015
 		}
1016 1016
 	}
1017 1017
 
@@ -1023,33 +1023,33 @@  discard block
 block discarded – undo
1023 1023
 	 * @return array $data
1024 1024
 	 */
1025 1025
 	public function ajax_add_to_cart() {
1026
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
1026
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
1027 1027
 
1028
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1029
-			define( 'WOOCOMMERCE_CART', true );
1028
+		if ( ! defined('WOOCOMMERCE_CART')) {
1029
+			define('WOOCOMMERCE_CART', true);
1030 1030
 		}
1031 1031
 
1032 1032
 		WC()->shipping->reset_shipping();
1033 1033
 
1034
-		$product_id   = absint( $_POST['product_id'] );
1035
-		$qty          = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
1036
-		$product      = wc_get_product( $product_id );
1034
+		$product_id   = absint($_POST['product_id']);
1035
+		$qty          = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
1036
+		$product      = wc_get_product($product_id);
1037 1037
 		$product_type = $product->get_type();
1038 1038
 
1039 1039
 		// First empty the cart to prevent wrong calculation.
1040 1040
 		WC()->cart->empty_cart();
1041 1041
 
1042
-		if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
1043
-			$attributes = wc_clean( wp_unslash( $_POST['attributes'] ) );
1042
+		if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) {
1043
+			$attributes = wc_clean(wp_unslash($_POST['attributes']));
1044 1044
 
1045
-			$data_store   = WC_Data_Store::load( 'product' );
1046
-			$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
1045
+			$data_store   = WC_Data_Store::load('product');
1046
+			$variation_id = $data_store->find_matching_product_variation($product, $attributes);
1047 1047
 
1048
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
1048
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
1049 1049
 		}
1050 1050
 
1051
-		if ( 'simple' === $product_type || 'subscription' === $product_type ) {
1052
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
1051
+		if ('simple' === $product_type || 'subscription' === $product_type) {
1052
+			WC()->cart->add_to_cart($product->get_id(), $qty);
1053 1053
 		}
1054 1054
 
1055 1055
 		WC()->cart->calculate_totals();
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
 		$data          += $this->build_display_items();
1059 1059
 		$data['result'] = 'success';
1060 1060
 
1061
-		wp_send_json( $data );
1061
+		wp_send_json($data);
1062 1062
 	}
1063 1063
 
1064 1064
 	/**
@@ -1071,31 +1071,31 @@  discard block
 block discarded – undo
1071 1071
 	 * @version 4.0.0
1072 1072
 	 */
1073 1073
 	public function normalize_state() {
1074
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
1075
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
1076
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
1077
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
1074
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
1075
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
1076
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
1077
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
1078 1078
 
1079
-		if ( $billing_state && $billing_country ) {
1080
-			$valid_states = WC()->countries->get_states( $billing_country );
1079
+		if ($billing_state && $billing_country) {
1080
+			$valid_states = WC()->countries->get_states($billing_country);
1081 1081
 
1082 1082
 			// Valid states found for country.
1083
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
1084
-				foreach ( $valid_states as $state_abbr => $state ) {
1085
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
1083
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
1084
+				foreach ($valid_states as $state_abbr => $state) {
1085
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
1086 1086
 						$_POST['billing_state'] = $state_abbr;
1087 1087
 					}
1088 1088
 				}
1089 1089
 			}
1090 1090
 		}
1091 1091
 
1092
-		if ( $shipping_state && $shipping_country ) {
1093
-			$valid_states = WC()->countries->get_states( $shipping_country );
1092
+		if ($shipping_state && $shipping_country) {
1093
+			$valid_states = WC()->countries->get_states($shipping_country);
1094 1094
 
1095 1095
 			// Valid states found for country.
1096
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
1097
-				foreach ( $valid_states as $state_abbr => $state ) {
1098
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
1096
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
1097
+				foreach ($valid_states as $state_abbr => $state) {
1098
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
1099 1099
 						$_POST['shipping_state'] = $state_abbr;
1100 1100
 					}
1101 1101
 				}
@@ -1110,19 +1110,19 @@  discard block
 block discarded – undo
1110 1110
 	 * @version 4.0.0
1111 1111
 	 */
1112 1112
 	public function ajax_create_order() {
1113
-		if ( WC()->cart->is_empty() ) {
1114
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
1113
+		if (WC()->cart->is_empty()) {
1114
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
1115 1115
 		}
1116 1116
 
1117
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
1118
-			define( 'WOOCOMMERCE_CHECKOUT', true );
1117
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
1118
+			define('WOOCOMMERCE_CHECKOUT', true);
1119 1119
 		}
1120 1120
 
1121 1121
 		$this->normalize_state();
1122 1122
 
1123 1123
 		WC()->checkout()->process_checkout();
1124 1124
 
1125
-		die( 0 );
1125
+		die(0);
1126 1126
 	}
1127 1127
 
1128 1128
 	/**
@@ -1132,38 +1132,38 @@  discard block
 block discarded – undo
1132 1132
 	 * @version 4.0.0
1133 1133
 	 * @param array $address
1134 1134
 	 */
1135
-	protected function calculate_shipping( $address = array() ) {
1135
+	protected function calculate_shipping($address = array()) {
1136 1136
 		$country   = $address['country'];
1137 1137
 		$state     = $address['state'];
1138 1138
 		$postcode  = $address['postcode'];
1139 1139
 		$city      = $address['city'];
1140 1140
 		$address_1 = $address['address'];
1141 1141
 		$address_2 = $address['address_2'];
1142
-		$wc_states = WC()->countries->get_states( $country );
1142
+		$wc_states = WC()->countries->get_states($country);
1143 1143
 
1144 1144
 		/**
1145 1145
 		 * In some versions of Chrome, state can be a full name. So we need
1146 1146
 		 * to convert that to abbreviation as WC is expecting that.
1147 1147
 		 */
1148
-		if ( 2 < strlen( $state ) && ! empty( $wc_states ) && ! isset( $wc_states[ $state ] ) ) {
1149
-			$state = array_search( ucwords( strtolower( $state ) ), $wc_states, true );
1148
+		if (2 < strlen($state) && ! empty($wc_states) && ! isset($wc_states[$state])) {
1149
+			$state = array_search(ucwords(strtolower($state)), $wc_states, true);
1150 1150
 		}
1151 1151
 
1152 1152
 		WC()->shipping->reset_shipping();
1153 1153
 
1154
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
1155
-			$postcode = wc_format_postcode( $postcode, $country );
1154
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
1155
+			$postcode = wc_format_postcode($postcode, $country);
1156 1156
 		}
1157 1157
 
1158
-		if ( $country ) {
1159
-			WC()->customer->set_location( $country, $state, $postcode, $city );
1160
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
1158
+		if ($country) {
1159
+			WC()->customer->set_location($country, $state, $postcode, $city);
1160
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
1161 1161
 		} else {
1162 1162
 			WC()->customer->set_billing_address_to_base();
1163 1163
 			WC()->customer->set_shipping_address_to_base();
1164 1164
 		}
1165 1165
 
1166
-		WC()->customer->set_calculated_shipping( true );
1166
+		WC()->customer->set_calculated_shipping(true);
1167 1167
 		WC()->customer->save();
1168 1168
 
1169 1169
 		$packages = array();
@@ -1179,17 +1179,17 @@  discard block
 block discarded – undo
1179 1179
 		$packages[0]['destination']['address']   = $address_1;
1180 1180
 		$packages[0]['destination']['address_2'] = $address_2;
1181 1181
 
1182
-		foreach ( WC()->cart->get_cart() as $item ) {
1183
-			if ( $item['data']->needs_shipping() ) {
1184
-				if ( isset( $item['line_total'] ) ) {
1182
+		foreach (WC()->cart->get_cart() as $item) {
1183
+			if ($item['data']->needs_shipping()) {
1184
+				if (isset($item['line_total'])) {
1185 1185
 					$packages[0]['contents_cost'] += $item['line_total'];
1186 1186
 				}
1187 1187
 			}
1188 1188
 		}
1189 1189
 
1190
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1190
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1191 1191
 
1192
-		WC()->shipping->calculate_shipping( $packages );
1192
+		WC()->shipping->calculate_shipping($packages);
1193 1193
 	}
1194 1194
 
1195 1195
 	/**
@@ -1198,19 +1198,19 @@  discard block
 block discarded – undo
1198 1198
 	 * @since 3.1.0
1199 1199
 	 * @version 4.0.0
1200 1200
 	 */
1201
-	protected function build_shipping_methods( $shipping_methods ) {
1202
-		if ( empty( $shipping_methods ) ) {
1201
+	protected function build_shipping_methods($shipping_methods) {
1202
+		if (empty($shipping_methods)) {
1203 1203
 			return array();
1204 1204
 		}
1205 1205
 
1206 1206
 		$shipping = array();
1207 1207
 
1208
-		foreach ( $shipping_methods as $method ) {
1208
+		foreach ($shipping_methods as $method) {
1209 1209
 			$shipping[] = array(
1210 1210
 				'id'     => $method['id'],
1211 1211
 				'label'  => $method['label'],
1212 1212
 				'detail' => '',
1213
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1213
+				'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1214 1214
 			);
1215 1215
 		}
1216 1216
 
@@ -1223,9 +1223,9 @@  discard block
 block discarded – undo
1223 1223
 	 * @since 3.1.0
1224 1224
 	 * @version 4.0.0
1225 1225
 	 */
1226
-	protected function build_display_items( $itemized_display_items = false ) {
1227
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1228
-			define( 'WOOCOMMERCE_CART', true );
1226
+	protected function build_display_items($itemized_display_items = false) {
1227
+		if ( ! defined('WOOCOMMERCE_CART')) {
1228
+			define('WOOCOMMERCE_CART', true);
1229 1229
 		}
1230 1230
 
1231 1231
 		$items     = array();
@@ -1233,8 +1233,8 @@  discard block
 block discarded – undo
1233 1233
 		$discounts = 0;
1234 1234
 
1235 1235
 		// Default show only subtotal instead of itemization.
1236
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) || $itemized_display_items ) {
1237
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1236
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true) || $itemized_display_items) {
1237
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1238 1238
 				$amount         = $cart_item['line_subtotal'];
1239 1239
 				$subtotal      += $cart_item['line_subtotal'];
1240 1240
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
@@ -1243,61 +1243,61 @@  discard block
 block discarded – undo
1243 1243
 
1244 1244
 				$item = array(
1245 1245
 					'label'  => $product_name . $quantity_label,
1246
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1246
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1247 1247
 				);
1248 1248
 
1249 1249
 				$items[] = $item;
1250 1250
 			}
1251 1251
 		}
1252 1252
 
1253
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1254
-			$discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1253
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1254
+			$discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1255 1255
 		} else {
1256
-			$applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() );
1256
+			$applied_coupons = array_values(WC()->cart->get_coupon_discount_totals());
1257 1257
 
1258
-			foreach ( $applied_coupons as $amount ) {
1258
+			foreach ($applied_coupons as $amount) {
1259 1259
 				$discounts += (float) $amount;
1260 1260
 			}
1261 1261
 		}
1262 1262
 
1263
-		$discounts   = wc_format_decimal( $discounts, WC()->cart->dp );
1264
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1265
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1266
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1267
-		$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false );
1263
+		$discounts   = wc_format_decimal($discounts, WC()->cart->dp);
1264
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1265
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1266
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1267
+		$order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false);
1268 1268
 
1269
-		if ( wc_tax_enabled() ) {
1269
+		if (wc_tax_enabled()) {
1270 1270
 			$items[] = array(
1271
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1272
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1271
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1272
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1273 1273
 			);
1274 1274
 		}
1275 1275
 
1276
-		if ( WC()->cart->needs_shipping() ) {
1276
+		if (WC()->cart->needs_shipping()) {
1277 1277
 			$items[] = array(
1278
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1279
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1278
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1279
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1280 1280
 			);
1281 1281
 		}
1282 1282
 
1283
-		if ( WC()->cart->has_discount() ) {
1283
+		if (WC()->cart->has_discount()) {
1284 1284
 			$items[] = array(
1285
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1286
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1285
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1286
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1287 1287
 			);
1288 1288
 		}
1289 1289
 
1290
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1290
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1291 1291
 			$cart_fees = WC()->cart->fees;
1292 1292
 		} else {
1293 1293
 			$cart_fees = WC()->cart->get_fees();
1294 1294
 		}
1295 1295
 
1296 1296
 		// Include fees and taxes as display items.
1297
-		foreach ( $cart_fees as $key => $fee ) {
1297
+		foreach ($cart_fees as $key => $fee) {
1298 1298
 			$items[] = array(
1299 1299
 				'label'  => $fee->name,
1300
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1300
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1301 1301
 			);
1302 1302
 		}
1303 1303
 
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
1305 1305
 			'displayItems' => $items,
1306 1306
 			'total'        => array(
1307 1307
 				'label'   => $this->total_label,
1308
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1308
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1309 1309
 				'pending' => false,
1310 1310
 			),
1311 1311
 		);
Please login to merge, or discard this patch.