Completed
Push — master ( 898bb5...80fce1 )
by Roy
03:14
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function __construct() {
115 115
 		$this->id                   = 'stripe';
116
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
117
-		$this->method_description   = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
116
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
117
+		$this->method_description   = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe');
118 118
 		$this->has_fields           = true;
119 119
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
120 120
 		$this->supports             = array(
@@ -142,42 +142,42 @@  discard block
 block discarded – undo
142 142
 		$this->init_settings();
143 143
 
144 144
 		// Get setting values.
145
-		$this->title                  = $this->get_option( 'title' );
146
-		$this->description            = $this->get_option( 'description' );
147
-		$this->enabled                = $this->get_option( 'enabled' );
148
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
149
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
150
-		$this->statement_descriptor   = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
151
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
152
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
153
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
154
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
155
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
156
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
157
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
158
-		$this->apple_pay              = 'yes' === $this->get_option( 'apple_pay', 'yes' );
159
-		$this->apple_pay_domain_set   = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
160
-		$this->apple_pay_button       = $this->get_option( 'apple_pay_button', 'black' );
161
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
162
-
163
-		if ( $this->stripe_checkout ) {
164
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
165
-		}
166
-
167
-		if ( $this->testmode ) {
168
-			$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
169
-			$this->description  = trim( $this->description );
170
-		}
171
-
172
-		WC_Stripe_API::set_secret_key( $this->secret_key );
145
+		$this->title                  = $this->get_option('title');
146
+		$this->description            = $this->get_option('description');
147
+		$this->enabled                = $this->get_option('enabled');
148
+		$this->testmode               = 'yes' === $this->get_option('testmode');
149
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
150
+		$this->statement_descriptor   = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
151
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
152
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
153
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
154
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
155
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
156
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
157
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
158
+		$this->apple_pay              = 'yes' === $this->get_option('apple_pay', 'yes');
159
+		$this->apple_pay_domain_set   = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
160
+		$this->apple_pay_button       = $this->get_option('apple_pay_button', 'black');
161
+		$this->logging                = 'yes' === $this->get_option('logging');
162
+
163
+		if ($this->stripe_checkout) {
164
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
165
+		}
166
+
167
+		if ($this->testmode) {
168
+			$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
169
+			$this->description  = trim($this->description);
170
+		}
171
+
172
+		WC_Stripe_API::set_secret_key($this->secret_key);
173 173
 
174 174
 		$this->init_apple_pay();
175 175
 
176 176
 		// Hooks.
177
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
178
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
179
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
180
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
177
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
178
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
179
+		add_action('admin_notices', array($this, 'admin_notices'));
180
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
181 181
 	}
182 182
 
183 183
 	/**
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 	 * @return string
188 188
 	 */
189 189
 	public function get_icon() {
190
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
191
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
190
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
191
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
192 192
 
193
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
194
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
195
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
193
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
194
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
195
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
196 196
 
197
-		if ( 'USD' === get_woocommerce_currency() ) {
198
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
199
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
200
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
197
+		if ('USD' === get_woocommerce_currency()) {
198
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
199
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
200
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
201 201
 		}
202 202
 
203
-		if ( $this->bitcoin && $this->stripe_checkout ) {
204
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
203
+		if ($this->bitcoin && $this->stripe_checkout) {
204
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
205 205
 		}
206 206
 
207
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
207
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
208 208
 	}
209 209
 
210 210
 	/**
@@ -215,11 +215,11 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return float|int
217 217
 	 */
218
-	public function get_stripe_amount( $total, $currency = '' ) {
219
-		if ( ! $currency ) {
218
+	public function get_stripe_amount($total, $currency = '') {
219
+		if ( ! $currency) {
220 220
 			$currency = get_woocommerce_currency();
221 221
 		}
222
-		switch ( strtoupper( $currency ) ) {
222
+		switch (strtoupper($currency)) {
223 223
 			// Zero decimal currencies.
224 224
 			case 'BIF' :
225 225
 			case 'CLP' :
@@ -236,10 +236,10 @@  discard block
 block discarded – undo
236 236
 			case 'XAF' :
237 237
 			case 'XOF' :
238 238
 			case 'XPF' :
239
-				$total = absint( $total );
239
+				$total = absint($total);
240 240
 				break;
241 241
 			default :
242
-				$total = round( $total, 2 ) * 100; // In cents.
242
+				$total = round($total, 2) * 100; // In cents.
243 243
 				break;
244 244
 		}
245 245
 		return $total;
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 	public function init_apple_pay() {
255 255
 		if ( 
256 256
 			is_admin() && 
257
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && 
258
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
259
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section']
257
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] && 
258
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
259
+			isset($_GET['section']) && 'stripe' === $_GET['section']
260 260
 		) {
261 261
 			$this->process_apple_pay_verification();
262 262
 		}
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
 	 * @version 3.1.0
270 270
 	 * @param string $secret_key
271 271
 	 */
272
-	private function _register_apple_pay_domain( $secret_key = '' ) {
273
-		if ( empty( $secret_key ) ) {
274
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
272
+	private function _register_apple_pay_domain($secret_key = '') {
273
+		if (empty($secret_key)) {
274
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
275 275
 		}
276 276
 
277 277
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -285,13 +285,13 @@  discard block
 block discarded – undo
285 285
 			'Authorization' => 'Bearer ' . $secret_key,
286 286
 		);
287 287
 
288
-		$response = wp_remote_post( $endpoint, array(
288
+		$response = wp_remote_post($endpoint, array(
289 289
 			'headers' => $headers,
290
-			'body'    => http_build_query( $data ),
291
-		) );
290
+			'body'    => http_build_query($data),
291
+		));
292 292
 
293
-		if ( 200 !== $response['response']['code'] ) {
294
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response['response']['message'] ) );
293
+		if (200 !== $response['response']['code']) {
294
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response['response']['message']));
295 295
 		}
296 296
 	}
297 297
 
@@ -302,48 +302,48 @@  discard block
 block discarded – undo
302 302
 	 * @version 3.1.0
303 303
 	 */
304 304
 	public function process_apple_pay_verification() {
305
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
305
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
306 306
 
307 307
 		try {
308
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
308
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
309 309
 			$dir      = '.well-known';
310 310
 			$file     = 'apple-developer-merchantid-domain-association';
311 311
 			$fullpath = $path . '/' . $dir . '/' . $file;
312 312
 
313
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
313
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
314 314
 				return;
315 315
 			}
316 316
 
317
-			if ( ! file_exists( $path . '/' . $dir ) ) {
318
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
319
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
317
+			if ( ! file_exists($path . '/' . $dir)) {
318
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
319
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
320 320
 				}
321 321
 			}
322 322
 
323
-			if ( ! file_exists( $fullpath ) ) {
324
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
325
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
323
+			if ( ! file_exists($fullpath)) {
324
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
325
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
326 326
 				}
327 327
 			}
328 328
 
329 329
 			// At this point then the domain association folder and file should be available.
330 330
 			// Proceed to verify/and or verify again.
331
-			$this->_register_apple_pay_domain( $this->secret_key );
331
+			$this->_register_apple_pay_domain($this->secret_key);
332 332
 
333 333
 			// No errors to this point, verification success!
334 334
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
335 335
 			$this->apple_pay_domain_set = true;
336 336
 
337
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
337
+			update_option('woocommerce_stripe_settings', $gateway_settings);
338 338
 
339
-			$this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) );
339
+			$this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe'));
340 340
 
341
-		} catch ( Exception $e ) {
341
+		} catch (Exception $e) {
342 342
 			$gateway_settings['apple_pay_domain_set'] = 'no';
343 343
 
344
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
344
+			update_option('woocommerce_stripe_settings', $gateway_settings);
345 345
 
346
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
346
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
347 347
 		}
348 348
 	}
349 349
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	 * Check if SSL is enabled and notify the user
352 352
 	 */
353 353
 	public function admin_notices() {
354
-		if ( 'no' === $this->enabled ) {
354
+		if ('no' === $this->enabled) {
355 355
 			return;
356 356
 		}
357 357
 
@@ -360,13 +360,13 @@  discard block
 block discarded – undo
360 360
 		 * when setting screen is displayed. So if domain verification is not set,
361 361
 		 * something went wrong so lets notify user.
362 362
 		 */
363
-		if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) {
364
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue.', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
363
+		if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) {
364
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue.', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
365 365
 		}
366 366
 
367 367
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
368
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
369
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>';
368
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
369
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>';
370 370
 		}
371 371
 	}
372 372
 
@@ -374,11 +374,11 @@  discard block
 block discarded – undo
374 374
 	 * Check if this gateway is enabled
375 375
 	 */
376 376
 	public function is_available() {
377
-		if ( 'yes' === $this->enabled ) {
378
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
377
+		if ('yes' === $this->enabled) {
378
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
379 379
 				return false;
380 380
 			}
381
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
381
+			if ( ! $this->secret_key || ! $this->publishable_key) {
382 382
 				return false;
383 383
 			}
384 384
 			return true;
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 	 * Initialise Gateway Settings Form Fields
391 391
 	 */
392 392
 	public function init_form_fields() {
393
-		$this->form_fields = include( 'settings-stripe.php' );
393
+		$this->form_fields = include('settings-stripe.php');
394 394
 	}
395 395
 
396 396
 	/**
@@ -398,54 +398,54 @@  discard block
 block discarded – undo
398 398
 	 */
399 399
 	public function payment_fields() {
400 400
 		$user                 = wp_get_current_user();
401
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
401
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
402 402
 		$total                = WC()->cart->total;
403 403
 
404 404
 		// If paying from order, we need to get total from order not cart.
405
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
406
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
405
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
406
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
407 407
 			$total = $order->get_total();
408 408
 		}
409 409
 
410
-		if ( $user->ID ) {
411
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
410
+		if ($user->ID) {
411
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
412 412
 			$user_email = $user_email ? $user_email : $user->user_email;
413 413
 		} else {
414 414
 			$user_email = '';
415 415
 		}
416 416
 
417
-		if ( is_add_payment_method_page() ) {
418
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
417
+		if (is_add_payment_method_page()) {
418
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
419 419
 		} else {
420 420
 			$pay_button_text = '';
421 421
 		}
422 422
 
423 423
 		echo '<div
424 424
 			id="stripe-payment-data"
425
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
425
+			data-panel-label="' . esc_attr($pay_button_text) . '"
426 426
 			data-description=""
427
-			data-email="' . esc_attr( $user_email ) . '"
428
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
429
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
430
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
431
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
432
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
433
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
434
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
427
+			data-email="' . esc_attr($user_email) . '"
428
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
429
+			data-name="' . esc_attr($this->statement_descriptor) . '"
430
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
431
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
432
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
433
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
434
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
435 435
 
436
-		if ( $this->description ) {
437
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
436
+		if ($this->description) {
437
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
438 438
 		}
439 439
 
440
-		if ( $display_tokenization ) {
440
+		if ($display_tokenization) {
441 441
 			$this->tokenization_script();
442 442
 			$this->saved_payment_methods();
443 443
 		}
444 444
 
445
-		if ( ! $this->stripe_checkout ) {
445
+		if ( ! $this->stripe_checkout) {
446 446
 			$this->form();
447 447
 
448
-			if ( $display_tokenization ) {
448
+			if ($display_tokenization) {
449 449
 				$this->save_payment_method_checkbox();
450 450
 			}
451 451
 		}
@@ -461,20 +461,20 @@  discard block
 block discarded – undo
461 461
 	 * @return array
462 462
 	 */
463 463
 	public function get_localized_messages() {
464
-		return apply_filters( 'wc_stripe_localized_messages', array(
465
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
466
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
467
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
468
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
469
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
470
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
471
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
472
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
473
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
474
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
475
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
476
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
477
-		) );
464
+		return apply_filters('wc_stripe_localized_messages', array(
465
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
466
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
467
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
468
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
469
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
470
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
471
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
472
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
473
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
474
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
475
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
476
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
477
+		));
478 478
 	}
479 479
 
480 480
 	/**
@@ -484,28 +484,28 @@  discard block
 block discarded – undo
484 484
 	 * @version 3.1.0
485 485
 	 */
486 486
 	public function admin_scripts() {
487
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
487
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
488 488
 			return;
489 489
 		}
490 490
 
491
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
491
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
492 492
 
493
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
493
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
494 494
 
495 495
 		$stripe_admin_params = array(
496 496
 			'localized_messages' => array(
497
-				'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ),
498
-				'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ),
499
-				're_verify_button_text'  => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ),
500
-				'missing_secret_key'     => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ),
497
+				'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'),
498
+				'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'),
499
+				're_verify_button_text'  => __('Re-verify Domain', 'woocommerce-gateway-stripe'),
500
+				'missing_secret_key'     => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'),
501 501
 			),
502
-			'ajaxurl'            => admin_url( 'admin-ajax.php' ),
502
+			'ajaxurl'            => admin_url('admin-ajax.php'),
503 503
 			'nonce'              => array( 
504
-				'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ),
504
+				'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'),
505 505
 			),
506 506
 		);
507 507
 
508
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) );
508
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params));
509 509
 	}
510 510
 
511 511
 	/**
@@ -516,49 +516,49 @@  discard block
 block discarded – undo
516 516
 	 * @access public
517 517
 	 */
518 518
 	public function payment_scripts() {
519
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
519
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
520 520
 			return;
521 521
 		}
522 522
 
523
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
523
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
524 524
 
525
-		if ( $this->stripe_checkout ) {
526
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
527
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe_checkout' ), WC_STRIPE_VERSION, true );
525
+		if ($this->stripe_checkout) {
526
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
527
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe_checkout'), WC_STRIPE_VERSION, true);
528 528
 		} else {
529
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
530
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
529
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
530
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
531 531
 		}
532 532
 
533 533
 		$stripe_params = array(
534 534
 			'key'                  => $this->publishable_key,
535
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
536
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
535
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
536
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
537 537
 		);
538 538
 
539 539
 		// If we're on the pay page we need to pass stripe.js the address of the order.
540
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
541
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
542
-			$order    = wc_get_order( $order_id );
540
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
541
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
542
+			$order    = wc_get_order($order_id);
543 543
 
544
-			$stripe_params['billing_first_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
545
-			$stripe_params['billing_last_name']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
546
-			$stripe_params['billing_address_1']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1();
547
-			$stripe_params['billing_address_2']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2();
548
-			$stripe_params['billing_state']      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_state : $order->get_billing_state();
549
-			$stripe_params['billing_city']       = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_city : $order->get_billing_city();
550
-			$stripe_params['billing_postcode']   = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode();
551
-			$stripe_params['billing_country']    = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_country : $order->get_billing_country();
544
+			$stripe_params['billing_first_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
545
+			$stripe_params['billing_last_name']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
546
+			$stripe_params['billing_address_1']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1();
547
+			$stripe_params['billing_address_2']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2();
548
+			$stripe_params['billing_state']      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_state : $order->get_billing_state();
549
+			$stripe_params['billing_city']       = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_city : $order->get_billing_city();
550
+			$stripe_params['billing_postcode']   = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_postcode : $order->get_billing_postcode();
551
+			$stripe_params['billing_country']    = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_country : $order->get_billing_country();
552 552
 		}
553 553
 
554
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
555
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
556
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
554
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
555
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
556
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
557 557
 
558 558
 		// merge localized messages to be use in JS
559
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
559
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
560 560
 
561
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
561
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
562 562
 	}
563 563
 
564 564
 	/**
@@ -567,35 +567,35 @@  discard block
 block discarded – undo
567 567
 	 * @param  object $source
568 568
 	 * @return array()
569 569
 	 */
570
-	protected function generate_payment_request( $order, $source ) {
570
+	protected function generate_payment_request($order, $source) {
571 571
 		$post_data                = array();
572
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
573
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
574
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
572
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
573
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
574
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
575 575
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
576 576
 
577
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
578
-		$billing_first_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
579
-		$billing_last_name  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
577
+		$billing_email      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
578
+		$billing_first_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
579
+		$billing_last_name  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
580 580
 
581
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
581
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
582 582
 			$post_data['receipt_email'] = $billing_email;
583 583
 		}
584 584
 
585
-		$post_data['expand[]']    = 'balance_transaction';
585
+		$post_data['expand[]'] = 'balance_transaction';
586 586
 
587 587
 		$metadata = array(
588
-			__( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
589
-			__( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
588
+			__('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
589
+			__('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
590 590
 		);
591 591
 
592
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
592
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
593 593
 
594
-		if ( $source->customer ) {
594
+		if ($source->customer) {
595 595
 			$post_data['customer'] = $source->customer;
596 596
 		}
597 597
 
598
-		if ( $source->source ) {
598
+		if ($source->source) {
599 599
 			$post_data['source'] = $source->source;
600 600
 		}
601 601
 
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 		 * @param WC_Order $order
608 608
 		 * @param object $source
609 609
 		 */
610
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
610
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
611 611
 	}
612 612
 
613 613
 	/**
@@ -619,37 +619,37 @@  discard block
 block discarded – undo
619 619
 	 * @throws Exception When card was not added or for and invalid card.
620 620
 	 * @return object
621 621
 	 */
622
-	protected function get_source( $user_id, $force_customer = false ) {
623
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
622
+	protected function get_source($user_id, $force_customer = false) {
623
+		$stripe_customer = new WC_Stripe_Customer($user_id);
624 624
 		$stripe_source   = false;
625 625
 		$token_id        = false;
626 626
 
627 627
 		// New CC info was entered and we have a new token to process
628
-		if ( isset( $_POST['stripe_token'] ) ) {
629
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
630
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
628
+		if (isset($_POST['stripe_token'])) {
629
+			$stripe_token     = wc_clean($_POST['stripe_token']);
630
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
631 631
 
632 632
 			// This is true if the user wants to store the card to their account.
633
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
634
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
633
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
634
+				$stripe_source = $stripe_customer->add_card($stripe_token);
635 635
 
636
-				if ( is_wp_error( $stripe_source ) ) {
637
-					throw new Exception( $stripe_source->get_error_message() );
636
+				if (is_wp_error($stripe_source)) {
637
+					throw new Exception($stripe_source->get_error_message());
638 638
 				}
639 639
 			} else {
640 640
 				// Not saving token, so don't define customer either.
641 641
 				$stripe_source   = $stripe_token;
642 642
 				$stripe_customer = false;
643 643
 			}
644
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
644
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
645 645
 			// Use an existing token, and then process the payment
646 646
 
647
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
648
-			$token    = WC_Payment_Tokens::get( $token_id );
647
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
648
+			$token    = WC_Payment_Tokens::get($token_id);
649 649
 
650
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
651
-				WC()->session->set( 'refresh_totals', true );
652
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
650
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
651
+				WC()->session->set('refresh_totals', true);
652
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
653 653
 			}
654 654
 
655 655
 			$stripe_source = $token->get_token();
@@ -673,19 +673,19 @@  discard block
 block discarded – undo
673 673
 	 * @param object $order
674 674
 	 * @return object
675 675
 	 */
676
-	protected function get_order_source( $order = null ) {
676
+	protected function get_order_source($order = null) {
677 677
 		$stripe_customer = new WC_Stripe_Customer();
678 678
 		$stripe_source   = false;
679 679
 		$token_id        = false;
680 680
 
681
-		if ( $order ) {
682
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
681
+		if ($order) {
682
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
683 683
 
684
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) {
685
-				$stripe_customer->set_id( $meta_value );
684
+			if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) {
685
+				$stripe_customer->set_id($meta_value);
686 686
 			}
687 687
 
688
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) {
688
+			if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) {
689 689
 				$stripe_source = $meta_value;
690 690
 			}
691 691
 		}
@@ -708,57 +708,57 @@  discard block
 block discarded – undo
708 708
 	 *
709 709
 	 * @return array|void
710 710
 	 */
711
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
711
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
712 712
 		try {
713
-			$order  = wc_get_order( $order_id );
714
-			$source = $this->get_source( get_current_user_id(), $force_customer );
713
+			$order  = wc_get_order($order_id);
714
+			$source = $this->get_source(get_current_user_id(), $force_customer);
715 715
 
716
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
717
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
718
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
719
-				throw new Exception( $error_msg );
716
+			if (empty($source->source) && empty($source->customer)) {
717
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
718
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
719
+				throw new Exception($error_msg);
720 720
 			}
721 721
 
722 722
 			// Store source to order meta.
723
-			$this->save_source( $order, $source );
723
+			$this->save_source($order, $source);
724 724
 
725 725
 			// Handle payment.
726
-			if ( $order->get_total() > 0 ) {
726
+			if ($order->get_total() > 0) {
727 727
 
728
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
729
-					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
728
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
729
+					throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
730 730
 				}
731 731
 
732
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
732
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
733 733
 
734 734
 				// Make the request.
735
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
735
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
736 736
 
737
-				if ( is_wp_error( $response ) ) {
737
+				if (is_wp_error($response)) {
738 738
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
739
-					if ( 'customer' === $response->get_error_code() && $retry ) {
740
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
741
-						return $this->process_payment( $order_id, false, $force_customer );
739
+					if ('customer' === $response->get_error_code() && $retry) {
740
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
741
+						return $this->process_payment($order_id, false, $force_customer);
742 742
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
743
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
744
-						$token = WC_Payment_Tokens::get( $source->token_id );
743
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
744
+						$token = WC_Payment_Tokens::get($source->token_id);
745 745
 						$token->delete();
746
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
747
-						$order->add_order_note( $message );
748
-						throw new Exception( $message );
746
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
747
+						$order->add_order_note($message);
748
+						throw new Exception($message);
749 749
 					}
750 750
 
751 751
 					$localized_messages = $this->get_localized_messages();
752 752
 
753
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
753
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
754 754
 
755
-					$order->add_order_note( $message );
755
+					$order->add_order_note($message);
756 756
 
757
-					throw new Exception( $message );
757
+					throw new Exception($message);
758 758
 				}
759 759
 
760 760
 				// Process valid response.
761
-				$this->process_response( $response, $order );
761
+				$this->process_response($response, $order);
762 762
 			} else {
763 763
 				$order->payment_complete();
764 764
 			}
@@ -766,23 +766,23 @@  discard block
 block discarded – undo
766 766
 			// Remove cart.
767 767
 			WC()->cart->empty_cart();
768 768
 
769
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
769
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
770 770
 
771 771
 			// Return thank you page redirect.
772 772
 			return array(
773 773
 				'result'   => 'success',
774
-				'redirect' => $this->get_return_url( $order ),
774
+				'redirect' => $this->get_return_url($order),
775 775
 			);
776 776
 
777
-		} catch ( Exception $e ) {
778
-			wc_add_notice( $e->getMessage(), 'error' );
779
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
777
+		} catch (Exception $e) {
778
+			wc_add_notice($e->getMessage(), 'error');
779
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
780 780
 
781
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
782
-				$this->send_failed_order_email( $order_id );
781
+			if ($order->has_status(array('pending', 'failed'))) {
782
+				$this->send_failed_order_email($order_id);
783 783
 			}
784 784
 
785
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
785
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
786 786
 
787 787
 			return array(
788 788
 				'result'   => 'fail',
@@ -797,56 +797,56 @@  discard block
 block discarded – undo
797 797
 	 * @param WC_Order $order For to which the source applies.
798 798
 	 * @param stdClass $source Source information.
799 799
 	 */
800
-	protected function save_source( $order, $source ) {
801
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
800
+	protected function save_source($order, $source) {
801
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
802 802
 
803 803
 		// Store source in the order.
804
-		if ( $source->customer ) {
805
-			update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
804
+		if ($source->customer) {
805
+			update_post_meta($order_id, '_stripe_customer_id', $source->customer);
806 806
 		}
807
-		if ( $source->source ) {
808
-			update_post_meta( $order_id, '_stripe_card_id', $source->source );
807
+		if ($source->source) {
808
+			update_post_meta($order_id, '_stripe_card_id', $source->source);
809 809
 		}
810 810
 	}
811 811
 
812 812
 	/**
813 813
 	 * Store extra meta data for an order from a Stripe Response.
814 814
 	 */
815
-	public function process_response( $response, $order ) {
816
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
815
+	public function process_response($response, $order) {
816
+		$this->log('Processing response: ' . print_r($response, true));
817 817
 
818
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
818
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
819 819
 
820 820
 		// Store charge data
821
-		update_post_meta( $order_id, '_stripe_charge_id', $response->id );
822
-		update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
821
+		update_post_meta($order_id, '_stripe_charge_id', $response->id);
822
+		update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
823 823
 
824 824
 		// Store other data such as fees
825
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
825
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
826 826
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
827 827
 			// values are in the local currency of the Stripe account, not from WC.
828
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe::format_number( $response->balance_transaction, 'fee' ) : 0;
829
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe::format_number( $response->balance_transaction, 'net' ) : 0;
830
-			update_post_meta( $order_id, 'Stripe Fee', $fee );
831
-			update_post_meta( $order_id, 'Net Revenue From Stripe', $net );
828
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe::format_number($response->balance_transaction, 'fee') : 0;
829
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe::format_number($response->balance_transaction, 'net') : 0;
830
+			update_post_meta($order_id, 'Stripe Fee', $fee);
831
+			update_post_meta($order_id, 'Net Revenue From Stripe', $net);
832 832
 		}
833 833
 
834
-		if ( $response->captured ) {
835
-			$order->payment_complete( $response->id );
834
+		if ($response->captured) {
835
+			$order->payment_complete($response->id);
836 836
 
837
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
838
-			$order->add_order_note( $message );
839
-			$this->log( 'Success: ' . $message );
837
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
838
+			$order->add_order_note($message);
839
+			$this->log('Success: ' . $message);
840 840
 
841 841
 		} else {
842
-			add_post_meta( $order_id, '_transaction_id', $response->id, true );
842
+			add_post_meta($order_id, '_transaction_id', $response->id, true);
843 843
 
844
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
845
-				version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
844
+			if ($order->has_status(array('pending', 'failed'))) {
845
+				version_compare(WC_VERSION, '3.0.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
846 846
 			}
847 847
 
848
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
849
-			$this->log( "Successful auth: $response->id" );
848
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
849
+			$this->log("Successful auth: $response->id");
850 850
 		}
851 851
 
852 852
 		return $response;
@@ -858,32 +858,32 @@  discard block
 block discarded – undo
858 858
 	 * @since 3.0.0
859 859
 	 */
860 860
 	public function add_payment_method() {
861
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
862
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
861
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
862
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
863 863
 			return;
864 864
 		}
865 865
 
866
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
867
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
866
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
867
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
868 868
 
869
-		if ( is_wp_error( $card ) ) {
869
+		if (is_wp_error($card)) {
870 870
 			$localized_messages = $this->get_localized_messages();
871
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
871
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
872 872
 
873 873
 			// loop through the errors to find matching localized message
874
-			foreach ( $card->errors as $error => $msg ) {
875
-				if ( isset( $localized_messages[ $error ] ) ) {
876
-					$error_msg = $localized_messages[ $error ];
874
+			foreach ($card->errors as $error => $msg) {
875
+				if (isset($localized_messages[$error])) {
876
+					$error_msg = $localized_messages[$error];
877 877
 				}
878 878
 			}
879 879
 
880
-			wc_add_notice( $error_msg, 'error' );
880
+			wc_add_notice($error_msg, 'error');
881 881
 			return;
882 882
 		}
883 883
 
884 884
 		return array(
885 885
 			'result'   => 'success',
886
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
886
+			'redirect' => wc_get_endpoint_url('payment-methods'),
887 887
 		);
888 888
 	}
889 889
 
@@ -893,36 +893,36 @@  discard block
 block discarded – undo
893 893
 	 * @param  float $amount
894 894
 	 * @return bool
895 895
 	 */
896
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
897
-		$order = wc_get_order( $order_id );
896
+	public function process_refund($order_id, $amount = null, $reason = '') {
897
+		$order = wc_get_order($order_id);
898 898
 
899
-		if ( ! $order || ! $order->get_transaction_id() ) {
899
+		if ( ! $order || ! $order->get_transaction_id()) {
900 900
 			return false;
901 901
 		}
902 902
 
903 903
 		$body = array();
904 904
 
905
-		if ( ! is_null( $amount ) ) {
906
-			$body['amount']	= $this->get_stripe_amount( $amount );
905
+		if ( ! is_null($amount)) {
906
+			$body['amount'] = $this->get_stripe_amount($amount);
907 907
 		}
908 908
 
909
-		if ( $reason ) {
909
+		if ($reason) {
910 910
 			$body['metadata'] = array(
911 911
 				'reason'	=> $reason,
912 912
 			);
913 913
 		}
914 914
 
915
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
915
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
916 916
 
917
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
917
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
918 918
 
919
-		if ( is_wp_error( $response ) ) {
920
-			$this->log( 'Error: ' . $response->get_error_message() );
919
+		if (is_wp_error($response)) {
920
+			$this->log('Error: ' . $response->get_error_message());
921 921
 			return $response;
922
-		} elseif ( ! empty( $response->id ) ) {
923
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
924
-			$order->add_order_note( $refund_message );
925
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
922
+		} elseif ( ! empty($response->id)) {
923
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
924
+			$order->add_order_note($refund_message);
925
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
926 926
 			return true;
927 927
 		}
928 928
 	}
@@ -935,10 +935,10 @@  discard block
 block discarded – undo
935 935
 	 * @param int $order_id
936 936
 	 * @return null
937 937
 	 */
938
-	public function send_failed_order_email( $order_id ) {
938
+	public function send_failed_order_email($order_id) {
939 939
 		$emails = WC()->mailer()->get_emails();
940
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
941
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
940
+		if ( ! empty($emails) && ! empty($order_id)) {
941
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
942 942
 		}
943 943
 	}
944 944
 
@@ -950,9 +950,9 @@  discard block
 block discarded – undo
950 950
 	 *
951 951
 	 * @param string $message
952 952
 	 */
953
-	public function log( $message ) {
954
-		if ( $this->logging ) {
955
-			WC_Stripe::log( $message );
953
+	public function log($message) {
954
+		if ($this->logging) {
955
+			WC_Stripe::log($message);
956 956
 		}
957 957
 	}
958 958
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -82,27 +82,27 @@  discard block
 block discarded – undo
82 82
 	public function __construct() {
83 83
 		self::$_this = $this;
84 84
 
85
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
85
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
86 86
 
87
-		$this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
87
+		$this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
88 88
 
89 89
 		// If both site title and statement descriptor is not set. Fallback.
90
-		if ( empty( $this->statement_descriptor ) ) {
90
+		if (empty($this->statement_descriptor)) {
91 91
 			$this->statement_descriptor = $_SERVER['SERVER_NAME'];
92 92
 		}
93 93
 
94
-		$this->enabled               = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false;
95
-		$this->testmode              = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false;
96
-		$this->capture               = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false;
97
-		$this->saved_cards           = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false;
98
-		$this->apple_pay             = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false;
99
-		$this->apple_pay_button      = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black';
100
-		$this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en';
101
-		$this->logging               = ( ! empty( $gateway_settings['logging'] ) && 'yes' === $gateway_settings['logging'] ) ? true : false;
102
-		$this->publishable_key       = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : '';
103
-
104
-		if ( $this->testmode ) {
105
-			$this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : '';
94
+		$this->enabled               = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false;
95
+		$this->testmode              = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false;
96
+		$this->capture               = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false;
97
+		$this->saved_cards           = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false;
98
+		$this->apple_pay             = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false;
99
+		$this->apple_pay_button      = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black';
100
+		$this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en';
101
+		$this->logging               = ( ! empty($gateway_settings['logging']) && 'yes' === $gateway_settings['logging']) ? true : false;
102
+		$this->publishable_key       = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : '';
103
+
104
+		if ($this->testmode) {
105
+			$this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : '';
106 106
 		}
107 107
 
108 108
 		$this->init();
@@ -121,53 +121,53 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function init() {
123 123
 		// If Apple Pay is not enabled no need to proceed further.
124
-		if ( ! $this->apple_pay ) {
124
+		if ( ! $this->apple_pay) {
125 125
 			return;
126 126
 		}
127 127
 
128
-		add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) );
129
-		add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) );
128
+		add_action('wp_enqueue_scripts', array($this, 'cart_scripts'));
129
+		add_action('wp_enqueue_scripts', array($this, 'single_scripts'));
130 130
 
131 131
 		/**
132 132
 		 * In order to display the Apple Pay button in the correct position,
133 133
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
134 134
 		 * CSS is used to position the button.
135 135
 		 */
136
-		if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
137
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 );
136
+		if (version_compare(WC_VERSION, '3.0.0', '<')) {
137
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1);
138 138
 		} else {
139
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 );
139
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1);
140 140
 		}
141 141
 
142
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 );
143
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 );
144
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 );
145
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 );
146
-		add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) );
147
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
148
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
149
-		add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) );
150
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) );
151
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
152
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
153
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
154
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
142
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1);
143
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2);
144
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1);
145
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2);
146
+		add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors'));
147
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
148
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
149
+		add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart'));
150
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single'));
151
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
152
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
153
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
154
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
155 155
 	}
156 156
 
157 157
 	/**
158 158
 	 * Filters the gateway title to reflect Apple Pay.
159 159
 	 *
160 160
 	 */
161
-	public function filter_gateway_title( $title, $id ) {
161
+	public function filter_gateway_title($title, $id) {
162 162
 		global $post;
163 163
 
164
-		if ( ! is_object( $post ) ) {
164
+		if ( ! is_object($post)) {
165 165
 			return $title;
166 166
 		}
167 167
 
168
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
168
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
169 169
 
170
-		if ( 'stripe' === $id && ! empty( $method_title ) ) {
170
+		if ('stripe' === $id && ! empty($method_title)) {
171 171
 			return $method_title;
172 172
 		}
173 173
 
@@ -181,13 +181,13 @@  discard block
 block discarded – undo
181 181
 	 * @version 3.1.4
182 182
 	 */
183 183
 	public function log_apple_pay_errors() {
184
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
185
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
184
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
185
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
186 186
 		}
187 187
 
188
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
188
+		$errors = wc_clean(stripslashes($_POST['errors']));
189 189
 
190
-		$this->log( 'Apple Pay: ' . $errors );
190
+		$this->log('Apple Pay: ' . $errors);
191 191
 
192 192
 		exit;
193 193
 	}
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
 	 * @since 3.1.4
199 199
 	 * @version 3.1.4
200 200
 	 */
201
-	public function postal_code_validation( $valid, $postcode, $country ) {
201
+	public function postal_code_validation($valid, $postcode, $country) {
202 202
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
203 203
 
204
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
204
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
205 205
 			return $valid;
206 206
 		}
207 207
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		 * when passing it back from the shippingcontactselected object. This causes WC to invalidate
211 211
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
212 212
 		 */
213
-		if ( 'GB' === $country || 'CA' === $country ) {
213
+		if ('GB' === $country || 'CA' === $country) {
214 214
 			return true;
215 215
 		}
216 216
 
@@ -224,42 +224,42 @@  discard block
 block discarded – undo
224 224
 	 * @version 3.1.4
225 225
 	 */
226 226
 	public function single_scripts() {
227
-		if ( ! is_single() ) {
227
+		if ( ! is_single()) {
228 228
 			return;
229 229
 		}
230 230
 
231 231
 		global $post;
232 232
 
233
-		$product = wc_get_product( $post->ID );
233
+		$product = wc_get_product($post->ID);
234 234
 
235
-		if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
235
+		if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
236 236
 			return;
237 237
 		}
238 238
 
239
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
239
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
240 240
 
241
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
241
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
242 242
 
243
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
244
-		wp_enqueue_script( 'woocommerce_stripe_apple_pay_single', plugins_url( 'assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
243
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
244
+		wp_enqueue_script('woocommerce_stripe_apple_pay_single', plugins_url('assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
245 245
 
246 246
 		$stripe_params = array(
247 247
 			'key'                                           => $this->publishable_key,
248 248
 			'currency_code'                                 => get_woocommerce_currency(),
249
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
249
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
250 250
 			'label'                                         => $this->statement_descriptor,
251
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
252
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
253
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
254
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
255
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
251
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
252
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
253
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
254
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
255
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
256 256
 			'needs_shipping'                                => $product->needs_shipping() ? 'yes' : 'no',
257 257
 			'i18n'                                          => array(
258
-				'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ),
258
+				'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'),
259 259
 			),
260 260
 		);
261 261
 
262
-		wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) );
262
+		wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params));
263 263
 	}
264 264
 
265 265
 	/**
@@ -269,32 +269,32 @@  discard block
 block discarded – undo
269 269
 	 * @version 3.1.0
270 270
 	 */
271 271
 	public function cart_scripts() {
272
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
272
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
273 273
 			return;
274 274
 		}
275 275
 
276
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
276
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
277 277
 
278
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
278
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
279 279
 
280
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
281
-		wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
280
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
281
+		wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
282 282
 
283 283
 		$stripe_params = array(
284 284
 			'key'                                           => $this->publishable_key,
285 285
 			'currency_code'                                 => get_woocommerce_currency(),
286
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
286
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
287 287
 			'label'                                         => $this->statement_descriptor,
288
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
289
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
290
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
291
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
292
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
288
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
289
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
290
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
291
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
292
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
293 293
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
294 294
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
295 295
 		);
296 296
 
297
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
297
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
298 298
 	}
299 299
 
300 300
 	/**
@@ -321,23 +321,23 @@  discard block
 block discarded – undo
321 321
 		 * In order for the Apple Pay button to show on product detail page,
322 322
 		 * Apple Pay must be enabled and Stripe gateway must be enabled.
323 323
 		 */
324
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
324
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
325 325
 			return;
326 326
 		}
327 327
 
328
-		if ( is_single() ) {
328
+		if (is_single()) {
329 329
 			global $post;
330 330
 
331
-			$product = wc_get_product( $post->ID );
331
+			$product = wc_get_product($post->ID);
332 332
 
333
-			if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
333
+			if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
334 334
 				return;
335 335
 			}
336 336
 		}
337 337
 
338 338
 		?>
339 339
 		<div class="apple-pay-button-wrapper">
340
-			<button class="apple-pay-button" lang="<?php echo esc_attr( $this->apple_pay_button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $this->apple_pay_button ); ?>;"></button>
340
+			<button class="apple-pay-button" lang="<?php echo esc_attr($this->apple_pay_button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($this->apple_pay_button); ?>;"></button>
341 341
 		</div>
342 342
 		<?php
343 343
 	}
@@ -355,21 +355,21 @@  discard block
 block discarded – undo
355 355
 		 * In order for the Apple Pay button to show on cart page,
356 356
 		 * Apple Pay must be enabled and Stripe gateway must be enabled.
357 357
 		 */
358
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
358
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
359 359
 			return;
360 360
 		}
361 361
 
362
-		if ( is_single() ) {
362
+		if (is_single()) {
363 363
 			global $post;
364 364
 
365
-			$product = wc_get_product( $post->ID );
365
+			$product = wc_get_product($post->ID);
366 366
 
367
-			if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
367
+			if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
368 368
 				return;
369 369
 			}
370 370
 		}
371 371
 		?>
372
-		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p>
372
+		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p>
373 373
 		<?php
374 374
 	}
375 375
 
@@ -380,51 +380,51 @@  discard block
 block discarded – undo
380 380
 	 * @version 3.1.0
381 381
 	 */
382 382
 	public function generate_apple_pay_single() {
383
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
384
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
383
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
384
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
385 385
 		}
386 386
 
387
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
388
-			define( 'WOOCOMMERCE_CART', true );
387
+		if ( ! defined('WOOCOMMERCE_CART')) {
388
+			define('WOOCOMMERCE_CART', true);
389 389
 		}
390 390
 
391 391
 		WC()->shipping->reset_shipping();
392 392
 
393 393
 		global $post;
394 394
 
395
-		$product = wc_get_product( $post->ID );
396
-		$qty     = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
395
+		$product = wc_get_product($post->ID);
396
+		$qty     = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
397 397
 
398 398
 		/**
399 399
 		 * If this page is single product page, we need to simulate
400 400
 		 * adding the product to the cart taken account if it is a
401 401
 		 * simple or variable product.
402 402
 		 */
403
-		if ( is_single() ) {
403
+		if (is_single()) {
404 404
 			// First empty the cart to prevent wrong calculation.
405 405
 			WC()->cart->empty_cart();
406 406
 
407
-			if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
408
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
407
+			if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
408
+				$attributes = array_map('wc_clean', $_POST['attributes']);
409 409
 
410
-				if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
411
-					$variation_id = $product->get_matching_variation( $attributes );
410
+				if (version_compare(WC_VERSION, '3.0.0', '<')) {
411
+					$variation_id = $product->get_matching_variation($attributes);
412 412
 				} else {
413
-					$data_store = WC_Data_Store::load( 'product' );
414
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
413
+					$data_store = WC_Data_Store::load('product');
414
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
415 415
 				}
416 416
 
417
-				WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
417
+				WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
418 418
 			}
419 419
 
420
-			if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
421
-				WC()->cart->add_to_cart( $product->get_id(), $qty );
420
+			if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) {
421
+				WC()->cart->add_to_cart($product->get_id(), $qty);
422 422
 			}
423 423
 		}
424 424
 
425 425
 		WC()->cart->calculate_totals();
426 426
 
427
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
427
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
428 428
 	}
429 429
 
430 430
 	/**
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
 	 * @version 3.1.0
435 435
 	 */
436 436
 	public function generate_apple_pay_cart() {
437
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
438
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
437
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
438
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
439 439
 		}
440 440
 
441
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
441
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
442 442
 	}
443 443
 
444 444
 	/**
@@ -459,29 +459,29 @@  discard block
 block discarded – undo
459 459
 	 * @version 3.1.0
460 460
 	 * @param array $address
461 461
 	 */
462
-	public function calculate_shipping( $address = array() ) {
463
-		$country  = strtoupper( $address['countryCode'] );
464
-		$state    = strtoupper( $address['administrativeArea'] );
462
+	public function calculate_shipping($address = array()) {
463
+		$country  = strtoupper($address['countryCode']);
464
+		$state    = strtoupper($address['administrativeArea']);
465 465
 		$postcode = $address['postalCode'];
466 466
 		$city     = $address['locality'];
467 467
 
468 468
 		WC()->shipping->reset_shipping();
469 469
 
470
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
471
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
472
-		} elseif ( $postcode ) {
473
-			$postcode = wc_format_postcode( $postcode, $country );
470
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
471
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
472
+		} elseif ($postcode) {
473
+			$postcode = wc_format_postcode($postcode, $country);
474 474
 		}
475 475
 
476
-		if ( $country ) {
477
-			WC()->customer->set_location( $country, $state, $postcode, $city );
478
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
476
+		if ($country) {
477
+			WC()->customer->set_location($country, $state, $postcode, $city);
478
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
479 479
 		} else {
480 480
 			WC()->customer->set_to_base();
481 481
 			WC()->customer->set_shipping_to_base();
482 482
 		}
483 483
 
484
-		WC()->customer->calculated_shipping( true );
484
+		WC()->customer->calculated_shipping(true);
485 485
 
486 486
 		/**
487 487
 		 * Set the shipping package.
@@ -503,17 +503,17 @@  discard block
 block discarded – undo
503 503
 		$packages[0]['destination']['postcode']  = $postcode;
504 504
 		$packages[0]['destination']['city']      = $city;
505 505
 
506
-		foreach ( WC()->cart->get_cart() as $item ) {
507
-			if ( $item['data']->needs_shipping() ) {
508
-				if ( isset( $item['line_total'] ) ) {
506
+		foreach (WC()->cart->get_cart() as $item) {
507
+			if ($item['data']->needs_shipping()) {
508
+				if (isset($item['line_total'])) {
509 509
 					$packages[0]['contents_cost'] += $item['line_total'];
510 510
 				}
511 511
 			}
512 512
 		}
513 513
 
514
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
514
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
515 515
 
516
-		WC()->shipping->calculate_shipping( $packages );
516
+		WC()->shipping->calculate_shipping($packages);
517 517
 	}
518 518
 
519 519
 	/**
@@ -523,18 +523,18 @@  discard block
 block discarded – undo
523 523
 	 * @version 3.1.0
524 524
 	 */
525 525
 	public function get_shipping_methods() {
526
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
527
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
526
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
527
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
528 528
 		}
529 529
 
530
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
531
-			define( 'WOOCOMMERCE_CART', true );
530
+		if ( ! defined('WOOCOMMERCE_CART')) {
531
+			define('WOOCOMMERCE_CART', true);
532 532
 		}
533 533
 
534 534
 		try {
535
-			$address = array_map( 'wc_clean', $_POST['address'] );
535
+			$address = array_map('wc_clean', $_POST['address']);
536 536
 
537
-			$this->calculate_shipping( $address );
537
+			$this->calculate_shipping($address);
538 538
 
539 539
 			// Set the shipping options.
540 540
 			$currency = get_woocommerce_currency();
@@ -542,13 +542,13 @@  discard block
 block discarded – undo
542 542
 
543 543
 			$packages = WC()->shipping->get_packages();
544 544
 
545
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
546
-				foreach ( $packages as $package_key => $package ) {
547
-					if ( empty( $package['rates'] ) ) {
548
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
545
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
546
+				foreach ($packages as $package_key => $package) {
547
+					if (empty($package['rates'])) {
548
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
549 549
 					}
550 550
 
551
-					foreach ( $package['rates'] as $key => $rate ) {
551
+					foreach ($package['rates'] as $key => $rate) {
552 552
 						$data[] = array(
553 553
 							'id'       => $rate->id,
554 554
 							'label'    => $rate->label,
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
 				}
563 563
 
564 564
 				// Auto select the first shipping method.
565
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
565
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
566 566
 
567 567
 				WC()->cart->calculate_totals();
568 568
 
569
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
569
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
570 570
 			} else {
571
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
571
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
572 572
 			}
573
-		} catch ( Exception $e ) {
574
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
573
+		} catch (Exception $e) {
574
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
575 575
 		}
576 576
 	}
577 577
 
@@ -582,29 +582,29 @@  discard block
 block discarded – undo
582 582
 	 * @version 3.1.0
583 583
 	 */
584 584
 	public function update_shipping_method() {
585
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
586
-			define( 'WOOCOMMERCE_CART', true );
585
+		if ( ! defined('WOOCOMMERCE_CART')) {
586
+			define('WOOCOMMERCE_CART', true);
587 587
 		}
588 588
 
589
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
590
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
589
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
590
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
591 591
 		}
592 592
 
593
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
593
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
594 594
 
595
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
595
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
596 596
 
597 597
 		WC()->cart->calculate_totals();
598 598
 
599 599
 		// Send back the new cart total.
600 600
 		$currency  = get_woocommerce_currency();
601
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
601
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
602 602
 		$data      = array(
603 603
 			'total' => WC()->cart->total,
604 604
 		);
605 605
 
606 606
 		// Include fees and taxes as displayItems.
607
-		foreach ( WC()->cart->fees as $key => $fee ) {
607
+		foreach (WC()->cart->fees as $key => $fee) {
608 608
 			$data['items'][] = array(
609 609
 				'label'  => $fee->name,
610 610
 				'amount' => array(
@@ -613,9 +613,9 @@  discard block
 block discarded – undo
613 613
 				),
614 614
 			);
615 615
 		}
616
-		if ( 0 < $tax_total ) {
616
+		if (0 < $tax_total) {
617 617
 			$data['items'][] = array(
618
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
618
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
619 619
 				'amount' => array(
620 620
 					'currency' => $currency,
621 621
 					'value'    => $tax_total,
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 			);
624 624
 		}
625 625
 
626
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
626
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
627 627
 	}
628 628
 
629 629
 	/**
@@ -634,37 +634,37 @@  discard block
 block discarded – undo
634 634
 	 * @version 3.1.0
635 635
 	 */
636 636
 	public function process_apple_pay() {
637
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
638
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
637
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
638
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
639 639
 		}
640 640
 
641 641
 		try {
642
-			$result = array_map( 'wc_clean', $_POST['result'] );
642
+			$result = array_map('wc_clean', $_POST['result']);
643 643
 
644
-			$order = $this->create_order( $result );
644
+			$order = $this->create_order($result);
645 645
 
646
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
646
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
647 647
 
648 648
 			// Handle payment.
649
-			if ( $order->get_total() > 0 ) {
649
+			if ($order->get_total() > 0) {
650 650
 
651
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
652
-					return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) );
651
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
652
+					return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100)));
653 653
 				}
654 654
 
655
-				$this->log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" );
655
+				$this->log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}");
656 656
 
657 657
 				// Make the request.
658
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
658
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
659 659
 
660
-				if ( is_wp_error( $response ) ) {
660
+				if (is_wp_error($response)) {
661 661
 					$localized_messages = $this->get_localized_messages();
662 662
 
663
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
663
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
664 664
 				}
665 665
 
666 666
 				// Process valid response.
667
-				$this->process_response( $response, $order );
667
+				$this->process_response($response, $order);
668 668
 			} else {
669 669
 				$order->payment_complete();
670 670
 			}
@@ -672,24 +672,24 @@  discard block
 block discarded – undo
672 672
 			// Remove cart.
673 673
 			WC()->cart->empty_cart();
674 674
 
675
-			update_post_meta( $order_id, '_customer_user', get_current_user_id() );
676
-			update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
675
+			update_post_meta($order_id, '_customer_user', get_current_user_id());
676
+			update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
677 677
 
678 678
 			// Return thank you page redirect.
679
-			wp_send_json( array(
679
+			wp_send_json(array(
680 680
 				'success'  => 'true',
681
-				'redirect' => $this->get_return_url( $order ),
682
-			) );
681
+				'redirect' => $this->get_return_url($order),
682
+			));
683 683
 
684
-		} catch ( Exception $e ) {
685
-			WC()->session->set( 'refresh_totals', true );
686
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
684
+		} catch (Exception $e) {
685
+			WC()->session->set('refresh_totals', true);
686
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
687 687
 
688
-			if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
689
-				$this->send_failed_order_email( $order_id );
688
+			if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) {
689
+				$this->send_failed_order_email($order_id);
690 690
 			}
691 691
 
692
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
692
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
693 693
 		}
694 694
 	}
695 695
 
@@ -699,16 +699,16 @@  discard block
 block discarded – undo
699 699
 	 * @param string $source token
700 700
 	 * @return array()
701 701
 	 */
702
-	protected function generate_payment_request( $order, $source ) {
702
+	protected function generate_payment_request($order, $source) {
703 703
 		$post_data                = array();
704
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
705
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
706
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
704
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
705
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
706
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
707 707
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
708 708
 
709
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
709
+		$billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
710 710
 
711
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
711
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
712 712
 			$post_data['receipt_email'] = $billing_email;
713 713
 		}
714 714
 
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 		 * @param WC_Order $order
724 724
 		 * @param object $source
725 725
 		 */
726
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
726
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
727 727
 	}
728 728
 
729 729
 	/**
@@ -732,14 +732,14 @@  discard block
 block discarded – undo
732 732
 	 * @since 3.1.0
733 733
 	 * @version 3.1.0
734 734
 	 */
735
-	public function build_shipping_methods( $shipping_methods ) {
736
-		if ( empty( $shipping_methods ) ) {
735
+	public function build_shipping_methods($shipping_methods) {
736
+		if (empty($shipping_methods)) {
737 737
 			return array();
738 738
 		}
739 739
 
740 740
 		$shipping = array();
741 741
 
742
-		foreach ( $shipping_methods as $method ) {
742
+		foreach ($shipping_methods as $method) {
743 743
 			$shipping[] = array(
744 744
 				'label'      => $method['label'],
745 745
 				'detail'     => '',
@@ -758,65 +758,65 @@  discard block
 block discarded – undo
758 758
 	 * @version 3.1.0
759 759
 	 */
760 760
 	public function build_line_items() {
761
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
762
-			define( 'WOOCOMMERCE_CART', true );
761
+		if ( ! defined('WOOCOMMERCE_CART')) {
762
+			define('WOOCOMMERCE_CART', true);
763 763
 		}
764 764
 
765
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
765
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
766 766
 		
767 767
 		$items    = array();
768 768
 		$subtotal = 0;
769 769
 
770
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
771
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
772
-			$subtotal       += $values['line_subtotal'];
770
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
771
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
772
+			$subtotal += $values['line_subtotal'];
773 773
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
774 774
 
775 775
 			$item = array(
776 776
 				'type'   => 'final',
777 777
 				'label'  => $values['data']->post->post_title . $quantity_label,
778
-				'amount' => wc_format_decimal( $amount, $decimals ),
778
+				'amount' => wc_format_decimal($amount, $decimals),
779 779
 			);
780 780
 
781 781
 			$items[] = $item;
782 782
 		}
783 783
 
784 784
 		// Default show only subtotal instead of itemization.
785
-		if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) {
785
+		if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) {
786 786
 			$items = array();
787 787
 			$items[] = array(
788 788
 				'type'   => 'final',
789
-				'label'  => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ),
790
-				'amount' => wc_format_decimal( $subtotal, $decimals ),
789
+				'label'  => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')),
790
+				'amount' => wc_format_decimal($subtotal, $decimals),
791 791
 			);
792 792
 		}
793 793
 
794
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
795
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
796
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
797
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
798
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
794
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
795
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
796
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
797
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
798
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
799 799
 
800
-		if ( wc_tax_enabled() ) {
800
+		if (wc_tax_enabled()) {
801 801
 			$items[] = array(
802 802
 				'type'   => 'final',
803
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
803
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
804 804
 				'amount' => $tax,
805 805
 			);
806 806
 		}
807 807
 
808
-		if ( WC()->cart->needs_shipping() ) {
808
+		if (WC()->cart->needs_shipping()) {
809 809
 			$items[] = array(
810 810
 				'type'   => 'final',
811
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
811
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
812 812
 				'amount' => $shipping,
813 813
 			);
814 814
 		}
815 815
 
816
-		if ( WC()->cart->has_discount() ) {
816
+		if (WC()->cart->has_discount()) {
817 817
 			$items[] = array(
818 818
 				'type'   => 'final',
819
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
819
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
820 820
 				'amount' => '-' . $discounts,
821 821
 			);
822 822
 		}
@@ -832,24 +832,24 @@  discard block
 block discarded – undo
832 832
 	 * @param array $data
833 833
 	 * @return object $order
834 834
 	 */
835
-	public function create_order( $data = array() ) {
836
-		if ( empty( $data ) ) {
837
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
835
+	public function create_order($data = array()) {
836
+		if (empty($data)) {
837
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
838 838
 		}
839 839
 
840 840
 		$order = wc_create_order();
841
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
841
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
842 842
 
843
-		if ( is_wp_error( $order ) ) {
844
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
845
-		} elseif ( false === $order ) {
846
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
843
+		if (is_wp_error($order)) {
844
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
845
+		} elseif (false === $order) {
846
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
847 847
 		} else {
848
-			do_action( 'woocommerce_new_order', $order_id );
848
+			do_action('woocommerce_new_order', $order_id);
849 849
 		}
850 850
 
851 851
 		// Store the line items to the new/resumed order
852
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
852
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
853 853
 			$item_id = $order->add_product(
854 854
 				$values['data'],
855 855
 				$values['quantity'],
@@ -865,25 +865,25 @@  discard block
 block discarded – undo
865 865
 				)
866 866
 			);
867 867
 
868
-			if ( ! $item_id ) {
869
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
868
+			if ( ! $item_id) {
869
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
870 870
 			}
871 871
 
872 872
 			// Allow plugins to add order item meta
873
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
874
-				do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
873
+			if (version_compare(WC_VERSION, '3.0', '<')) {
874
+				do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
875 875
 			} else {
876
-				do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() );
876
+				do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id());
877 877
 			}
878 878
 		}
879 879
 
880 880
 		// Store fees
881
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
882
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
883
-				$item_id = $order->add_fee( $fee );
881
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
882
+			if (version_compare(WC_VERSION, '3.0', '<')) {
883
+				$item_id = $order->add_fee($fee);
884 884
 			} else {
885 885
 				$item = new WC_Order_Item_Fee();
886
-				$item->set_props( array(
886
+				$item->set_props(array(
887 887
 					'name'      => $fee->name,
888 888
 					'tax_class' => $fee->taxable ? $fee->tax_class : 0,
889 889
 					'total'     => $fee->amount,
@@ -892,79 +892,79 @@  discard block
 block discarded – undo
892 892
 						'total' => $fee->tax_data,
893 893
 					),
894 894
 					'order_id'  => $order->get_id(),
895
-				) );
895
+				));
896 896
 				$item_id = $item->save();
897
-				$order->add_item( $item );
897
+				$order->add_item($item);
898 898
 			}
899 899
 
900
-			if ( ! $item_id ) {
901
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
900
+			if ( ! $item_id) {
901
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
902 902
 			}
903 903
 
904 904
 			// Allow plugins to add order item meta to fees
905
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
906
-				do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
905
+			if (version_compare(WC_VERSION, '3.0', '<')) {
906
+				do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
907 907
 			} else {
908
-				do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() );
908
+				do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id());
909 909
 			}
910 910
 		}
911 911
 
912 912
 		// Store tax rows
913
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
914
-			$tax_amount = WC()->cart->get_tax_amount( $tax_rate_id );
915
-			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id );
913
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
914
+			$tax_amount = WC()->cart->get_tax_amount($tax_rate_id);
915
+			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id);
916 916
 
917
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
918
-				$item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount );
917
+			if (version_compare(WC_VERSION, '3.0', '<')) {
918
+				$item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount);
919 919
 			} else {
920 920
 				$item = new WC_Order_Item_Tax();
921
-				$item->set_props( array(
921
+				$item->set_props(array(
922 922
 					'rate_id'            => $tax_rate_id,
923 923
 					'tax_total'          => $tax_amount,
924 924
 					'shipping_tax_total' => $shipping_tax_amount,
925
-				) );
926
-				$item->set_rate( $tax_rate_id );
927
-				$item->set_order_id( $order->get_id() );
925
+				));
926
+				$item->set_rate($tax_rate_id);
927
+				$item->set_order_id($order->get_id());
928 928
 				$item_id = $item->save();
929
-				$order->add_item( $item );
929
+				$order->add_item($item);
930 930
 			}
931 931
 
932
-			if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
933
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
932
+			if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
933
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
934 934
 			}
935 935
 		}
936 936
 
937 937
 		// Store coupons
938
-		$discount = WC()->cart->get_coupon_discount_amount( $code );
939
-		$discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code );
938
+		$discount = WC()->cart->get_coupon_discount_amount($code);
939
+		$discount_tax = WC()->cart->get_coupon_discount_tax_amount($code);
940 940
 
941
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
942
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
943
-				$coupon_id = $order->add_coupon( $code, $discount, $discount_tax );
941
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
942
+			if (version_compare(WC_VERSION, '3.0', '<')) {
943
+				$coupon_id = $order->add_coupon($code, $discount, $discount_tax);
944 944
 			} else {
945 945
 				$item = new WC_Order_Item_Coupon();
946
-				$item->set_props( array(
946
+				$item->set_props(array(
947 947
 					'code'         => $code,
948 948
 					'discount'     => $discount,
949 949
 					'discount_tax' => $discount_tax,
950 950
 					'order_id'     => $order->get_id(),
951
-				) );
951
+				));
952 952
 				$coupon_id = $item->save();
953
-				$order->add_item( $item );
953
+				$order->add_item($item);
954 954
 			}
955 955
 
956
-			if ( ! $coupon_id ) {
957
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
956
+			if ( ! $coupon_id) {
957
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
958 958
 			}
959 959
 		}
960 960
 
961 961
 		// Billing address
962 962
 		$billing_address = array();
963
-		if ( ! empty( $data['token']['card'] ) ) {
963
+		if ( ! empty($data['token']['card'])) {
964 964
 			// Name from Stripe is a full name string.
965
-			$name                          = explode( ' ', $data['token']['card']['name'] );
966
-			$lastname                      = array_pop( $name );
967
-			$firstname                     = implode( ' ', $name );
965
+			$name                          = explode(' ', $data['token']['card']['name']);
966
+			$lastname                      = array_pop($name);
967
+			$firstname                     = implode(' ', $name);
968 968
 			$billing_address['first_name'] = $firstname;
969 969
 			$billing_address['last_name']  = $lastname;
970 970
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 
980 980
 		// Shipping address.
981 981
 		$shipping_address = array();
982
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
982
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
983 983
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
984 984
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
985 985
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
 			$shipping_address['city']       = $data['shippingContact']['locality'];
991 991
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
992 992
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
993
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
993
+		} elseif ( ! empty($data['shippingContact'])) {
994 994
 			$shipping_address['first_name'] = $firstname;
995 995
 			$shipping_address['last_name']  = $lastname;
996 996
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -1003,33 +1003,33 @@  discard block
 block discarded – undo
1003 1003
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
1004 1004
 		}
1005 1005
 
1006
-		$order->set_address( $billing_address, 'billing' );
1007
-		$order->set_address( $shipping_address, 'shipping' );
1006
+		$order->set_address($billing_address, 'billing');
1007
+		$order->set_address($shipping_address, 'shipping');
1008 1008
 
1009
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
1009
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
1010 1010
 
1011 1011
 		// Get the rate object selected by user.
1012
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
1013
-			foreach ( $package['rates'] as $key => $rate ) {
1012
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
1013
+			foreach ($package['rates'] as $key => $rate) {
1014 1014
 				// Loop through user chosen shipping methods.
1015
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
1016
-					if ( $method === $key ) {
1017
-						if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1018
-							$order->add_shipping( $rate );
1015
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
1016
+					if ($method === $key) {
1017
+						if (version_compare(WC_VERSION, '3.0', '<')) {
1018
+							$order->add_shipping($rate);
1019 1019
 						} else {
1020 1020
 							$item = new WC_Order_Item_Shipping();
1021
-							$item->set_props( array(
1021
+							$item->set_props(array(
1022 1022
 								'method_title' => $rate->label,
1023 1023
 								'method_id'    => $rate->id,
1024
-								'total'        => wc_format_decimal( $rate->cost ),
1024
+								'total'        => wc_format_decimal($rate->cost),
1025 1025
 								'taxes'        => $rate->taxes,
1026 1026
 								'order_id'     => $order->get_id(),
1027
-							) );
1028
-							foreach ( $rate->get_meta_data() as $key => $value ) {
1029
-								$item->add_meta_data( $key, $value, true );
1027
+							));
1028
+							foreach ($rate->get_meta_data() as $key => $value) {
1029
+								$item->add_meta_data($key, $value, true);
1030 1030
 							}
1031 1031
 							$item->save();
1032
-							$order->add_item( $item );
1032
+							$order->add_item($item);
1033 1033
 						}
1034 1034
 					}
1035 1035
 				}
@@ -1037,16 +1037,16 @@  discard block
 block discarded – undo
1037 1037
 		}
1038 1038
 
1039 1039
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
1040
-		$order->set_payment_method( $available_gateways['stripe'] );
1041
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
1042
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
1043
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
1044
-		$order->set_total( WC()->cart->tax_total, 'tax' );
1045
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
1046
-		$order->set_total( WC()->cart->total );
1040
+		$order->set_payment_method($available_gateways['stripe']);
1041
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
1042
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
1043
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
1044
+		$order->set_total(WC()->cart->tax_total, 'tax');
1045
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
1046
+		$order->set_total(WC()->cart->total);
1047 1047
 
1048 1048
 		// If we got here, the order was created without problems!
1049
-		wc_transaction_query( 'commit' );
1049
+		wc_transaction_query('commit');
1050 1050
 
1051 1051
 		return $order;
1052 1052
 	}
@@ -1059,9 +1059,9 @@  discard block
 block discarded – undo
1059 1059
 	 *
1060 1060
 	 * @param string $message
1061 1061
 	 */
1062
-	public function log( $message ) {
1063
-		if ( $this->logging ) {
1064
-			WC_Stripe::log( $message );
1062
+	public function log($message) {
1063
+		if ($this->logging) {
1064
+			WC_Stripe::log($message);
1065 1065
 		}
1066 1066
 	}
1067 1067
 }
Please login to merge, or discard this patch.