Completed
Pull Request — master (#1239)
by Valerie
10:51 queued 01:14
created
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +306 added lines, -306 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,
@@ -786,11 +786,11 @@  discard block
 block discarded – undo
786 786
 				'address_2' => FILTER_SANITIZE_STRING,
787 787
 			)
788 788
 		);
789
-		$product_view_options      = filter_input_array( INPUT_POST, [ 'is_product_page' => FILTER_SANITIZE_STRING ] );
790
-		$should_show_itemized_view = ! isset( $product_view_options['is_product_page'] ) ?: filter_var( $product_view_options['is_product_page'], FILTER_VALIDATE_BOOLEAN );
789
+		$product_view_options      = filter_input_array(INPUT_POST, ['is_product_page' => FILTER_SANITIZE_STRING]);
790
+		$should_show_itemized_view = ! isset($product_view_options['is_product_page']) ?: filter_var($product_view_options['is_product_page'], FILTER_VALIDATE_BOOLEAN);
791 791
 
792
-		$data = $this->get_shipping_options( $shipping_address, $should_show_itemized_view );
793
-		wp_send_json( $data );
792
+		$data = $this->get_shipping_options($shipping_address, $should_show_itemized_view);
793
+		wp_send_json($data);
794 794
 	}
795 795
 
796 796
 	/**
@@ -802,66 +802,66 @@  discard block
 block discarded – undo
802 802
 	 * @return array Shipping options data.
803 803
 	 * phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag
804 804
 	 */
805
-	public function get_shipping_options( $shipping_address, $itemized_display_items = false ) {
805
+	public function get_shipping_options($shipping_address, $itemized_display_items = false) {
806 806
 		try {
807 807
 			// Set the shipping options.
808 808
 			$data = array();
809 809
 
810 810
 			// Remember current shipping method before resetting.
811
-			$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
812
-			$this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $shipping_address ) );
811
+			$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
812
+			$this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $shipping_address));
813 813
 
814 814
 			$packages = WC()->shipping->get_packages();
815 815
 
816
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
817
-				foreach ( $packages as $package_key => $package ) {
818
-					if ( empty( $package['rates'] ) ) {
819
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
816
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
817
+				foreach ($packages as $package_key => $package) {
818
+					if (empty($package['rates'])) {
819
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
820 820
 					}
821 821
 
822
-					foreach ( $package['rates'] as $key => $rate ) {
822
+					foreach ($package['rates'] as $key => $rate) {
823 823
 						$data['shipping_options'][] = array(
824 824
 							'id'     => $rate->id,
825 825
 							'label'  => $rate->label,
826 826
 							'detail' => '',
827
-							'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
827
+							'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost),
828 828
 						);
829 829
 					}
830 830
 				}
831 831
 			} else {
832
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
832
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
833 833
 			}
834 834
 
835 835
 			// The first shipping option is automatically applied on the client.
836 836
 			// Keep chosen shipping method by sorting shipping options if the method still available for new address.
837 837
 			// Fallback to the first available shipping method.
838
-			if ( isset( $data['shipping_options'][0] ) ) {
839
-				if ( isset( $chosen_shipping_methods[0] ) ) {
838
+			if (isset($data['shipping_options'][0])) {
839
+				if (isset($chosen_shipping_methods[0])) {
840 840
 					$chosen_method_id         = $chosen_shipping_methods[0];
841
-					$compare_shipping_options = function ( $a, $b ) use ( $chosen_method_id ) {
842
-						if ( $a['id'] === $chosen_method_id ) {
841
+					$compare_shipping_options = function($a, $b) use ($chosen_method_id) {
842
+						if ($a['id'] === $chosen_method_id) {
843 843
 							return -1;
844 844
 						}
845 845
 
846
-						if ( $b['id'] === $chosen_method_id ) {
846
+						if ($b['id'] === $chosen_method_id) {
847 847
 							return 1;
848 848
 						}
849 849
 
850 850
 						return 0;
851 851
 					};
852
-					usort( $data['shipping_options'], $compare_shipping_options );
852
+					usort($data['shipping_options'], $compare_shipping_options);
853 853
 				}
854 854
 
855 855
 				$first_shipping_method_id = $data['shipping_options'][0]['id'];
856
-				$this->update_shipping_method( [ $first_shipping_method_id ] );
856
+				$this->update_shipping_method([$first_shipping_method_id]);
857 857
 			}
858 858
 
859 859
 			WC()->cart->calculate_totals();
860 860
 
861
-			$data          += $this->build_display_items( $itemized_display_items );
861
+			$data          += $this->build_display_items($itemized_display_items);
862 862
 			$data['result'] = 'success';
863
-		} catch ( Exception $e ) {
864
-			$data          += $this->build_display_items( $itemized_display_items );
863
+		} catch (Exception $e) {
864
+			$data          += $this->build_display_items($itemized_display_items);
865 865
 			$data['result'] = 'invalid_shipping_address';
866 866
 		}
867 867
 
@@ -872,25 +872,25 @@  discard block
 block discarded – undo
872 872
 	 * Update shipping method.
873 873
 	 */
874 874
 	public function ajax_update_shipping_method() {
875
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
875
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
876 876
 
877
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
878
-			define( 'WOOCOMMERCE_CART', true );
877
+		if ( ! defined('WOOCOMMERCE_CART')) {
878
+			define('WOOCOMMERCE_CART', true);
879 879
 		}
880 880
 
881
-		$shipping_methods = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
882
-		$this->update_shipping_method( $shipping_methods );
881
+		$shipping_methods = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
882
+		$this->update_shipping_method($shipping_methods);
883 883
 
884 884
 		WC()->cart->calculate_totals();
885 885
 
886
-		$product_view_options      = filter_input_array( INPUT_POST, [ 'is_product_page' => FILTER_SANITIZE_STRING ] );
887
-		$should_show_itemized_view = ! isset( $product_view_options['is_product_page'] ) ?: filter_var( $product_view_options['is_product_page'], FILTER_VALIDATE_BOOLEAN );
886
+		$product_view_options      = filter_input_array(INPUT_POST, ['is_product_page' => FILTER_SANITIZE_STRING]);
887
+		$should_show_itemized_view = ! isset($product_view_options['is_product_page']) ?: filter_var($product_view_options['is_product_page'], FILTER_VALIDATE_BOOLEAN);
888 888
 
889 889
 		$data           = array();
890
-		$data          += $this->build_display_items( $should_show_itemized_view );
890
+		$data          += $this->build_display_items($should_show_itemized_view);
891 891
 		$data['result'] = 'success';
892 892
 
893
-		wp_send_json( $data );
893
+		wp_send_json($data);
894 894
 	}
895 895
 
896 896
 	/**
@@ -898,16 +898,16 @@  discard block
 block discarded – undo
898 898
 	 *
899 899
 	 * @param array $shipping_methods Array of selected shipping methods ids.
900 900
 	 */
901
-	public function update_shipping_method( $shipping_methods ) {
902
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
901
+	public function update_shipping_method($shipping_methods) {
902
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
903 903
 
904
-		if ( is_array( $shipping_methods ) ) {
905
-			foreach ( $shipping_methods as $i => $value ) {
906
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
904
+		if (is_array($shipping_methods)) {
905
+			foreach ($shipping_methods as $i => $value) {
906
+				$chosen_shipping_methods[$i] = wc_clean($value);
907 907
 			}
908 908
 		}
909 909
 
910
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
910
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
911 911
 	}
912 912
 
913 913
 	/**
@@ -918,38 +918,38 @@  discard block
 block discarded – undo
918 918
 	 * @return array $data
919 919
 	 */
920 920
 	public function ajax_get_selected_product_data() {
921
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
921
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
922 922
 
923 923
 		try {
924
-			$product_id   = absint( $_POST['product_id'] );
925
-			$qty          = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id );
926
-			$addon_value  = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0;
927
-			$product      = wc_get_product( $product_id );
924
+			$product_id   = absint($_POST['product_id']);
925
+			$qty          = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id);
926
+			$addon_value  = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0;
927
+			$product      = wc_get_product($product_id);
928 928
 			$variation_id = null;
929 929
 
930
-			if ( ! is_a( $product, 'WC_Product' ) ) {
931
-				throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) );
930
+			if ( ! is_a($product, 'WC_Product')) {
931
+				throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id));
932 932
 			}
933 933
 
934
-			if ( 'variable' === $product->get_type() && isset( $_POST['attributes'] ) ) {
935
-				$attributes = wc_clean( wp_unslash( $_POST['attributes'] ) );
934
+			if ('variable' === $product->get_type() && isset($_POST['attributes'])) {
935
+				$attributes = wc_clean(wp_unslash($_POST['attributes']));
936 936
 
937
-				$data_store   = WC_Data_Store::load( 'product' );
938
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
937
+				$data_store   = WC_Data_Store::load('product');
938
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
939 939
 
940
-				if ( ! empty( $variation_id ) ) {
941
-					$product = wc_get_product( $variation_id );
940
+				if ( ! empty($variation_id)) {
941
+					$product = wc_get_product($variation_id);
942 942
 				}
943 943
 			}
944 944
 
945 945
 			// Force quantity to 1 if sold individually and check for existing item in cart.
946
-			if ( $product->is_sold_individually() ) {
947
-				$qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id );
946
+			if ($product->is_sold_individually()) {
947
+				$qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id);
948 948
 			}
949 949
 
950
-			if ( ! $product->has_enough_stock( $qty ) ) {
950
+			if ( ! $product->has_enough_stock($qty)) {
951 951
 				/* translators: 1: product name 2: quantity in stock */
952
-				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 ) ) );
952
+				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)));
953 953
 			}
954 954
 
955 955
 			$total = $qty * $product->get_price() + $addon_value;
@@ -961,27 +961,27 @@  discard block
 block discarded – undo
961 961
 
962 962
 			$items[] = array(
963 963
 				'label'  => $product->get_name() . $quantity_label,
964
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
964
+				'amount' => WC_Stripe_Helper::get_stripe_amount($total),
965 965
 			);
966 966
 
967
-			if ( wc_tax_enabled() ) {
967
+			if (wc_tax_enabled()) {
968 968
 				$items[] = array(
969
-					'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
969
+					'label'   => __('Tax', 'woocommerce-gateway-stripe'),
970 970
 					'amount'  => 0,
971 971
 					'pending' => true,
972 972
 				);
973 973
 			}
974 974
 
975
-			if ( wc_shipping_enabled() && $product->needs_shipping() ) {
975
+			if (wc_shipping_enabled() && $product->needs_shipping()) {
976 976
 				$items[] = array(
977
-					'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
977
+					'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
978 978
 					'amount'  => 0,
979 979
 					'pending' => true,
980 980
 				);
981 981
 
982 982
 				$data['shippingOptions'] = array(
983 983
 					'id'     => 'pending',
984
-					'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
984
+					'label'  => __('Pending', 'woocommerce-gateway-stripe'),
985 985
 					'detail' => '',
986 986
 					'amount' => 0,
987 987
 				);
@@ -990,17 +990,17 @@  discard block
 block discarded – undo
990 990
 			$data['displayItems'] = $items;
991 991
 			$data['total']        = array(
992 992
 				'label'   => $this->total_label,
993
-				'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
993
+				'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
994 994
 				'pending' => true,
995 995
 			);
996 996
 
997
-			$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
998
-			$data['currency']        = strtolower( get_woocommerce_currency() );
999
-			$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
997
+			$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
998
+			$data['currency']        = strtolower(get_woocommerce_currency());
999
+			$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
1000 1000
 
1001
-			wp_send_json( $data );
1002
-		} catch ( Exception $e ) {
1003
-			wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) );
1001
+			wp_send_json($data);
1002
+		} catch (Exception $e) {
1003
+			wp_send_json(array('error' => wp_strip_all_tags($e->getMessage())));
1004 1004
 		}
1005 1005
 	}
1006 1006
 
@@ -1012,33 +1012,33 @@  discard block
 block discarded – undo
1012 1012
 	 * @return array $data
1013 1013
 	 */
1014 1014
 	public function ajax_add_to_cart() {
1015
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
1015
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
1016 1016
 
1017
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1018
-			define( 'WOOCOMMERCE_CART', true );
1017
+		if ( ! defined('WOOCOMMERCE_CART')) {
1018
+			define('WOOCOMMERCE_CART', true);
1019 1019
 		}
1020 1020
 
1021 1021
 		WC()->shipping->reset_shipping();
1022 1022
 
1023
-		$product_id   = absint( $_POST['product_id'] );
1024
-		$qty          = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
1025
-		$product      = wc_get_product( $product_id );
1023
+		$product_id   = absint($_POST['product_id']);
1024
+		$qty          = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
1025
+		$product      = wc_get_product($product_id);
1026 1026
 		$product_type = $product->get_type();
1027 1027
 
1028 1028
 		// First empty the cart to prevent wrong calculation.
1029 1029
 		WC()->cart->empty_cart();
1030 1030
 
1031
-		if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
1032
-			$attributes = wc_clean( wp_unslash( $_POST['attributes'] ) );
1031
+		if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) {
1032
+			$attributes = wc_clean(wp_unslash($_POST['attributes']));
1033 1033
 
1034
-			$data_store   = WC_Data_Store::load( 'product' );
1035
-			$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
1034
+			$data_store   = WC_Data_Store::load('product');
1035
+			$variation_id = $data_store->find_matching_product_variation($product, $attributes);
1036 1036
 
1037
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
1037
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
1038 1038
 		}
1039 1039
 
1040
-		if ( 'simple' === $product_type || 'subscription' === $product_type ) {
1041
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
1040
+		if ('simple' === $product_type || 'subscription' === $product_type) {
1041
+			WC()->cart->add_to_cart($product->get_id(), $qty);
1042 1042
 		}
1043 1043
 
1044 1044
 		WC()->cart->calculate_totals();
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 		$data          += $this->build_display_items();
1048 1048
 		$data['result'] = 'success';
1049 1049
 
1050
-		wp_send_json( $data );
1050
+		wp_send_json($data);
1051 1051
 	}
1052 1052
 
1053 1053
 	/**
@@ -1060,31 +1060,31 @@  discard block
 block discarded – undo
1060 1060
 	 * @version 4.0.0
1061 1061
 	 */
1062 1062
 	public function normalize_state() {
1063
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
1064
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
1065
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
1066
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
1063
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
1064
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
1065
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
1066
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
1067 1067
 
1068
-		if ( $billing_state && $billing_country ) {
1069
-			$valid_states = WC()->countries->get_states( $billing_country );
1068
+		if ($billing_state && $billing_country) {
1069
+			$valid_states = WC()->countries->get_states($billing_country);
1070 1070
 
1071 1071
 			// Valid states found for country.
1072
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
1073
-				foreach ( $valid_states as $state_abbr => $state ) {
1074
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
1072
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
1073
+				foreach ($valid_states as $state_abbr => $state) {
1074
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
1075 1075
 						$_POST['billing_state'] = $state_abbr;
1076 1076
 					}
1077 1077
 				}
1078 1078
 			}
1079 1079
 		}
1080 1080
 
1081
-		if ( $shipping_state && $shipping_country ) {
1082
-			$valid_states = WC()->countries->get_states( $shipping_country );
1081
+		if ($shipping_state && $shipping_country) {
1082
+			$valid_states = WC()->countries->get_states($shipping_country);
1083 1083
 
1084 1084
 			// Valid states found for country.
1085
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
1086
-				foreach ( $valid_states as $state_abbr => $state ) {
1087
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
1085
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
1086
+				foreach ($valid_states as $state_abbr => $state) {
1087
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
1088 1088
 						$_POST['shipping_state'] = $state_abbr;
1089 1089
 					}
1090 1090
 				}
@@ -1099,19 +1099,19 @@  discard block
 block discarded – undo
1099 1099
 	 * @version 4.0.0
1100 1100
 	 */
1101 1101
 	public function ajax_create_order() {
1102
-		if ( WC()->cart->is_empty() ) {
1103
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
1102
+		if (WC()->cart->is_empty()) {
1103
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
1104 1104
 		}
1105 1105
 
1106
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
1107
-			define( 'WOOCOMMERCE_CHECKOUT', true );
1106
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
1107
+			define('WOOCOMMERCE_CHECKOUT', true);
1108 1108
 		}
1109 1109
 
1110 1110
 		$this->normalize_state();
1111 1111
 
1112 1112
 		WC()->checkout()->process_checkout();
1113 1113
 
1114
-		die( 0 );
1114
+		die(0);
1115 1115
 	}
1116 1116
 
1117 1117
 	/**
@@ -1121,38 +1121,38 @@  discard block
 block discarded – undo
1121 1121
 	 * @version 4.0.0
1122 1122
 	 * @param array $address
1123 1123
 	 */
1124
-	protected function calculate_shipping( $address = array() ) {
1124
+	protected function calculate_shipping($address = array()) {
1125 1125
 		$country   = $address['country'];
1126 1126
 		$state     = $address['state'];
1127 1127
 		$postcode  = $address['postcode'];
1128 1128
 		$city      = $address['city'];
1129 1129
 		$address_1 = $address['address'];
1130 1130
 		$address_2 = $address['address_2'];
1131
-		$wc_states = WC()->countries->get_states( $country );
1131
+		$wc_states = WC()->countries->get_states($country);
1132 1132
 
1133 1133
 		/**
1134 1134
 		 * In some versions of Chrome, state can be a full name. So we need
1135 1135
 		 * to convert that to abbreviation as WC is expecting that.
1136 1136
 		 */
1137
-		if ( 2 < strlen( $state ) && ! empty( $wc_states ) && ! isset( $wc_states[ $state ] ) ) {
1138
-			$state = array_search( ucwords( strtolower( $state ) ), $wc_states, true );
1137
+		if (2 < strlen($state) && ! empty($wc_states) && ! isset($wc_states[$state])) {
1138
+			$state = array_search(ucwords(strtolower($state)), $wc_states, true);
1139 1139
 		}
1140 1140
 
1141 1141
 		WC()->shipping->reset_shipping();
1142 1142
 
1143
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
1144
-			$postcode = wc_format_postcode( $postcode, $country );
1143
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
1144
+			$postcode = wc_format_postcode($postcode, $country);
1145 1145
 		}
1146 1146
 
1147
-		if ( $country ) {
1148
-			WC()->customer->set_location( $country, $state, $postcode, $city );
1149
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
1147
+		if ($country) {
1148
+			WC()->customer->set_location($country, $state, $postcode, $city);
1149
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
1150 1150
 		} else {
1151 1151
 			WC()->customer->set_billing_address_to_base();
1152 1152
 			WC()->customer->set_shipping_address_to_base();
1153 1153
 		}
1154 1154
 
1155
-		WC()->customer->set_calculated_shipping( true );
1155
+		WC()->customer->set_calculated_shipping(true);
1156 1156
 		WC()->customer->save();
1157 1157
 
1158 1158
 		$packages = array();
@@ -1168,17 +1168,17 @@  discard block
 block discarded – undo
1168 1168
 		$packages[0]['destination']['address']   = $address_1;
1169 1169
 		$packages[0]['destination']['address_2'] = $address_2;
1170 1170
 
1171
-		foreach ( WC()->cart->get_cart() as $item ) {
1172
-			if ( $item['data']->needs_shipping() ) {
1173
-				if ( isset( $item['line_total'] ) ) {
1171
+		foreach (WC()->cart->get_cart() as $item) {
1172
+			if ($item['data']->needs_shipping()) {
1173
+				if (isset($item['line_total'])) {
1174 1174
 					$packages[0]['contents_cost'] += $item['line_total'];
1175 1175
 				}
1176 1176
 			}
1177 1177
 		}
1178 1178
 
1179
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1179
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1180 1180
 
1181
-		WC()->shipping->calculate_shipping( $packages );
1181
+		WC()->shipping->calculate_shipping($packages);
1182 1182
 	}
1183 1183
 
1184 1184
 	/**
@@ -1187,19 +1187,19 @@  discard block
 block discarded – undo
1187 1187
 	 * @since 3.1.0
1188 1188
 	 * @version 4.0.0
1189 1189
 	 */
1190
-	protected function build_shipping_methods( $shipping_methods ) {
1191
-		if ( empty( $shipping_methods ) ) {
1190
+	protected function build_shipping_methods($shipping_methods) {
1191
+		if (empty($shipping_methods)) {
1192 1192
 			return array();
1193 1193
 		}
1194 1194
 
1195 1195
 		$shipping = array();
1196 1196
 
1197
-		foreach ( $shipping_methods as $method ) {
1197
+		foreach ($shipping_methods as $method) {
1198 1198
 			$shipping[] = array(
1199 1199
 				'id'     => $method['id'],
1200 1200
 				'label'  => $method['label'],
1201 1201
 				'detail' => '',
1202
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1202
+				'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1203 1203
 			);
1204 1204
 		}
1205 1205
 
@@ -1212,9 +1212,9 @@  discard block
 block discarded – undo
1212 1212
 	 * @since 3.1.0
1213 1213
 	 * @version 4.0.0
1214 1214
 	 */
1215
-	protected function build_display_items( $itemized_display_items = false ) {
1216
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1217
-			define( 'WOOCOMMERCE_CART', true );
1215
+	protected function build_display_items($itemized_display_items = false) {
1216
+		if ( ! defined('WOOCOMMERCE_CART')) {
1217
+			define('WOOCOMMERCE_CART', true);
1218 1218
 		}
1219 1219
 
1220 1220
 		$items     = array();
@@ -1222,8 +1222,8 @@  discard block
 block discarded – undo
1222 1222
 		$discounts = 0;
1223 1223
 
1224 1224
 		// Default show only subtotal instead of itemization.
1225
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) || $itemized_display_items ) {
1226
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1225
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true) || $itemized_display_items) {
1226
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1227 1227
 				$amount         = $cart_item['line_subtotal'];
1228 1228
 				$subtotal      += $cart_item['line_subtotal'];
1229 1229
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
@@ -1232,61 +1232,61 @@  discard block
 block discarded – undo
1232 1232
 
1233 1233
 				$item = array(
1234 1234
 					'label'  => $product_name . $quantity_label,
1235
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1235
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1236 1236
 				);
1237 1237
 
1238 1238
 				$items[] = $item;
1239 1239
 			}
1240 1240
 		}
1241 1241
 
1242
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1243
-			$discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1242
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1243
+			$discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1244 1244
 		} else {
1245
-			$applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() );
1245
+			$applied_coupons = array_values(WC()->cart->get_coupon_discount_totals());
1246 1246
 
1247
-			foreach ( $applied_coupons as $amount ) {
1247
+			foreach ($applied_coupons as $amount) {
1248 1248
 				$discounts += (float) $amount;
1249 1249
 			}
1250 1250
 		}
1251 1251
 
1252
-		$discounts   = wc_format_decimal( $discounts, WC()->cart->dp );
1253
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1254
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1255
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1256
-		$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false );
1252
+		$discounts   = wc_format_decimal($discounts, WC()->cart->dp);
1253
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1254
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1255
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1256
+		$order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false);
1257 1257
 
1258
-		if ( wc_tax_enabled() ) {
1258
+		if (wc_tax_enabled()) {
1259 1259
 			$items[] = array(
1260
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1261
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1260
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1261
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1262 1262
 			);
1263 1263
 		}
1264 1264
 
1265
-		if ( WC()->cart->needs_shipping() ) {
1265
+		if (WC()->cart->needs_shipping()) {
1266 1266
 			$items[] = array(
1267
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1268
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1267
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1268
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1269 1269
 			);
1270 1270
 		}
1271 1271
 
1272
-		if ( WC()->cart->has_discount() ) {
1272
+		if (WC()->cart->has_discount()) {
1273 1273
 			$items[] = array(
1274
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1275
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1274
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1275
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1276 1276
 			);
1277 1277
 		}
1278 1278
 
1279
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1279
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1280 1280
 			$cart_fees = WC()->cart->fees;
1281 1281
 		} else {
1282 1282
 			$cart_fees = WC()->cart->get_fees();
1283 1283
 		}
1284 1284
 
1285 1285
 		// Include fees and taxes as display items.
1286
-		foreach ( $cart_fees as $key => $fee ) {
1286
+		foreach ($cart_fees as $key => $fee) {
1287 1287
 			$items[] = array(
1288 1288
 				'label'  => $fee->name,
1289
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1289
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1290 1290
 			);
1291 1291
 		}
1292 1292
 
@@ -1294,7 +1294,7 @@  discard block
 block discarded – undo
1294 1294
 			'displayItems' => $items,
1295 1295
 			'total'        => array(
1296 1296
 				'label'   => $this->total_label,
1297
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1297
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1298 1298
 				'pending' => false,
1299 1299
 			),
1300 1300
 		);
Please login to merge, or discard this patch.