Completed
Pull Request — master (#169)
by Matty
03:29
created
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +204 added lines, -204 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
 
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 	public function __construct() {
48 48
 		self::$_this = $this;
49 49
 
50
-		$this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
50
+		$this->_gateway_settings = get_option('woocommerce_stripe_settings', '');
51 51
 
52
-		$this->statement_descriptor = ! empty( $this->_gateway_settings['statement_descriptor'] ) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
52
+		$this->statement_descriptor = ! empty($this->_gateway_settings['statement_descriptor']) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
53 53
 
54 54
 		$this->init();
55 55
 	}
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
 	 * @version 3.1.0
67 67
 	 */
68 68
 	public function init() {
69
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
70
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 );
71
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 );
72
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 );
73
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
74
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
75
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
76
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
77
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
69
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
70
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1);
71
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1);
72
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2);
73
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
74
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
75
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
76
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
77
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
78 78
 	}
79 79
 
80 80
 	/**
@@ -85,47 +85,47 @@  discard block
 block discarded – undo
85 85
 	 * @version 3.1.0
86 86
 	 */
87 87
 	public static function process_apple_pay_domain() {
88
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_domain_nonce' ) ) {
89
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
88
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_domain_nonce')) {
89
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
90 90
 		}
91 91
 
92
-		$secret_key = wc_clean( $_POST['secret_key'] );
92
+		$secret_key = wc_clean($_POST['secret_key']);
93 93
 
94 94
 		try {
95
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
95
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
96 96
 			$dir      = '.well-known';
97 97
 			$file     = 'apple-developer-merchantid-domain-association';
98 98
 			$fullpath = $path . '/' . $dir . '/' . $file;
99
-			$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
99
+			$gateway_settings = get_option('woocommerce_stripe_settings', '');
100 100
 
101
-			if ( ! file_exists( $path . '/' . $dir ) || ! file_exists( $fullpath ) ) {
102
-				if ( ! mkdir( $path . '/' . $dir, 0755 ) ) {
103
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
101
+			if ( ! file_exists($path . '/' . $dir) || ! file_exists($fullpath)) {
102
+				if ( ! mkdir($path . '/' . $dir, 0755)) {
103
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
104 104
 				}
105 105
 
106
-				if ( ! file_exists( $path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association' ) ) {
107
-					if ( ! copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
108
-						throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
106
+				if ( ! file_exists($path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association')) {
107
+					if ( ! copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
108
+						throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
109 109
 					}
110 110
 				}
111 111
 			}
112 112
 
113 113
 			// At this point then the domain association folder and file should be available.
114 114
 			// Proceed to verify/and or verify again.
115
-			WC_Stripe_Apple_Pay::_register_apple_pay_domain( $secret_key );
115
+			WC_Stripe_Apple_Pay::_register_apple_pay_domain($secret_key);
116 116
 
117 117
 			// No errors to this point, verification success!
118 118
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
119 119
 
120
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
120
+			update_option('woocommerce_stripe_settings', $gateway_settings);
121 121
 
122
-			wp_send_json( array( 'success' => true, 'message' => __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) ) );
123
-		} catch ( Exception $e ) {
122
+			wp_send_json(array('success' => true, 'message' => __('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe')));
123
+		} catch (Exception $e) {
124 124
 			$gateway_settings['apple_pay_domain_set'] = 'no';
125 125
 
126
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
126
+			update_option('woocommerce_stripe_settings', $gateway_settings);
127 127
 
128
-			wp_send_json( array( 'success' => false, 'message' => $e->getMessage() ) );
128
+			wp_send_json(array('success' => false, 'message' => $e->getMessage()));
129 129
 		}
130 130
 	}
131 131
 
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 	 * @version 3.1.0
137 137
 	 * @param string $secret_key
138 138
 	 */
139
-	private static function _register_apple_pay_domain( $secret_key = '' ) {
140
-		if ( empty( $secret_key ) ) {
141
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
139
+	private static function _register_apple_pay_domain($secret_key = '') {
140
+		if (empty($secret_key)) {
141
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
142 142
 		}
143 143
 
144 144
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -152,13 +152,13 @@  discard block
 block discarded – undo
152 152
 			'Authorization' => 'Bearer ' . $secret_key,
153 153
 		);
154 154
 
155
-		$response = wp_remote_post( $endpoint, array(
155
+		$response = wp_remote_post($endpoint, array(
156 156
 			'headers' => $headers,
157
-			'body'    => http_build_query( $data ),
158
-		) );
157
+			'body'    => http_build_query($data),
158
+		));
159 159
 
160
-		if ( 200 !== $response['response']['code'] ) {
161
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response['response']['message'] ) );
160
+		if (200 !== $response['response']['code']) {
161
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response['response']['message']));
162 162
 		}
163 163
 	}
164 164
 
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
 	 * Filters the gateway title to reflect Apple Pay.
167 167
 	 *
168 168
 	 */
169
-	public function filter_gateway_title( $title, $id ) {
169
+	public function filter_gateway_title($title, $id) {
170 170
 		global $post;
171 171
 
172
-		if ( ! is_object( $post ) ) {
172
+		if ( ! is_object($post)) {
173 173
 			return $title;
174 174
 		}
175 175
 
176
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
176
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
177 177
 
178
-		if ( 'stripe' === $id && ! empty( $method_title ) ) {
178
+		if ('stripe' === $id && ! empty($method_title)) {
179 179
 			return $method_title;
180 180
 		}
181 181
 
@@ -189,38 +189,38 @@  discard block
 block discarded – undo
189 189
 	 * @version 3.1.0
190 190
 	 */
191 191
 	public function payment_scripts() {
192
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
192
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
193 193
 			return;
194 194
 		}
195 195
 
196
-		if ( ! $this->is_supported_product_type() ) {
196
+		if ( ! $this->is_supported_product_type()) {
197 197
 			return;
198 198
 		}
199 199
 
200
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
200
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
201 201
 
202
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
202
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
203 203
 
204
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
205
-		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 );
204
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
205
+		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);
206 206
 
207 207
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
208 208
 
209 209
 		$stripe_params = array(
210 210
 			'key'                                           => $publishable_key,
211 211
 			'currency_code'                                 => get_woocommerce_currency(),
212
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
212
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
213 213
 			'label'                                         => $this->statement_descriptor,
214
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
215
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
216
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
217
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
218
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
214
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
215
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
216
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
217
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
218
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
219 219
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
220 220
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
221 221
 		);
222 222
 
223
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
223
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
224 224
 	}
225 225
 
226 226
 	/**
@@ -228,8 +228,8 @@  discard block
 block discarded – undo
228 228
 	 *
229 229
 	 */
230 230
 	public function is_supported_product_type() {
231
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
232
-			if ( 'subscription' === $values['data']->product_type ) {
231
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
232
+			if ('subscription' === $values['data']->product_type) {
233 233
 				return false;
234 234
 			}
235 235
 		}
@@ -252,19 +252,19 @@  discard block
 block discarded – undo
252 252
 		 */
253 253
 		if (
254 254
 			'yes' !== $this->_gateway_settings['apple_pay']
255
-			|| ! isset( $gateways['stripe'] )
255
+			|| ! isset($gateways['stripe'])
256 256
 		) {
257 257
 			return;
258 258
 		}
259 259
 
260
-		if ( ! $this->is_supported_product_type() ) {
260
+		if ( ! $this->is_supported_product_type()) {
261 261
 			return;
262 262
 		}
263 263
 
264
-		$apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black';
265
-		$button_lang      = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en';
264
+		$apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black';
265
+		$button_lang      = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en';
266 266
 		?>
267
-		<button class="apple-pay-button" lang="<?php echo esc_attr( $button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $apple_pay_button ); ?>;"></button>
267
+		<button class="apple-pay-button" lang="<?php echo esc_attr($button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($apple_pay_button); ?>;"></button>
268 268
 		<?php
269 269
 	}
270 270
 
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
 		 */
284 284
 		if (
285 285
 			'yes' !== $this->_gateway_settings['apple_pay']
286
-			|| ! isset( $gateways['stripe'] )
286
+			|| ! isset($gateways['stripe'])
287 287
 		) {
288 288
 			return;
289 289
 		}
290 290
 
291
-		if ( ! $this->is_supported_product_type() ) {
291
+		if ( ! $this->is_supported_product_type()) {
292 292
 			return;
293 293
 		}
294 294
 		?>
295
-		<p class="apple-pay-button-checkout-separator">- <?php _e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p>
295
+		<p class="apple-pay-button-checkout-separator">- <?php _e('Or', 'woocommerce-gateway-stripe'); ?> -</p>
296 296
 		<?php
297 297
 	}
298 298
 
@@ -303,11 +303,11 @@  discard block
 block discarded – undo
303 303
 	 * @version 3.1.0
304 304
 	 */
305 305
 	public function generate_apple_pay_cart() {
306
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
307
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
306
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
307
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
308 308
 		}
309 309
 
310
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
310
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
311 311
 	}
312 312
 
313 313
 	/**
@@ -317,29 +317,29 @@  discard block
 block discarded – undo
317 317
 	 * @version 3.1.0
318 318
 	 * @param array $address
319 319
 	 */
320
-	public function calculate_shipping( $address = array() ) {
321
-		$country  = strtoupper( $address['countryCode'] );
322
-		$state    = strtoupper( $address['administrativeArea'] );
320
+	public function calculate_shipping($address = array()) {
321
+		$country  = strtoupper($address['countryCode']);
322
+		$state    = strtoupper($address['administrativeArea']);
323 323
 		$postcode = $address['postalCode'];
324 324
 		$city     = $address['locality'];
325 325
 
326 326
 		WC()->shipping->reset_shipping();
327 327
 
328
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
329
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
330
-		} elseif ( $postcode ) {
331
-			$postcode = wc_format_postcode( $postcode, $country );
328
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
329
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
330
+		} elseif ($postcode) {
331
+			$postcode = wc_format_postcode($postcode, $country);
332 332
 		}
333 333
 
334
-		if ( $country ) {
335
-			WC()->customer->set_location( $country, $state, $postcode, $city );
336
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
334
+		if ($country) {
335
+			WC()->customer->set_location($country, $state, $postcode, $city);
336
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
337 337
 		} else {
338 338
 			WC()->customer->set_to_base();
339 339
 			WC()->customer->set_shipping_to_base();
340 340
 		}
341 341
 
342
-		WC()->customer->calculated_shipping( true );
342
+		WC()->customer->calculated_shipping(true);
343 343
 
344 344
 		/**
345 345
 		 * Set the shipping package.
@@ -361,17 +361,17 @@  discard block
 block discarded – undo
361 361
 		$packages[0]['destination']['postcode']  = $postcode;
362 362
 		$packages[0]['destination']['city']      = $city;
363 363
 
364
-		foreach ( WC()->cart->get_cart() as $item ) {
365
-			if ( $item['data']->needs_shipping() ) {
366
-				if ( isset( $item['line_total'] ) ) {
364
+		foreach (WC()->cart->get_cart() as $item) {
365
+			if ($item['data']->needs_shipping()) {
366
+				if (isset($item['line_total'])) {
367 367
 					$packages[0]['contents_cost'] += $item['line_total'];
368 368
 				}
369 369
 			}
370 370
 		}
371 371
 
372
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
372
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
373 373
 
374
-		WC()->shipping->calculate_shipping( $packages );
374
+		WC()->shipping->calculate_shipping($packages);
375 375
 	}
376 376
 
377 377
 	/**
@@ -381,18 +381,18 @@  discard block
 block discarded – undo
381 381
 	 * @version 3.1.0
382 382
 	 */
383 383
 	public function get_shipping_methods() {
384
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
385
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
384
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
385
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
386 386
 		}
387 387
 
388
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
389
-			define( 'WOOCOMMERCE_CART', true );
388
+		if ( ! defined('WOOCOMMERCE_CART')) {
389
+			define('WOOCOMMERCE_CART', true);
390 390
 		}
391 391
 
392 392
 		try {
393
-			$address = array_map( 'wc_clean', $_POST['address'] );
393
+			$address = array_map('wc_clean', $_POST['address']);
394 394
 
395
-			$this->calculate_shipping( $address );
395
+			$this->calculate_shipping($address);
396 396
 
397 397
 			// Set the shipping options.
398 398
 			$currency = get_woocommerce_currency();
@@ -400,13 +400,13 @@  discard block
 block discarded – undo
400 400
 
401 401
 			$packages = WC()->shipping->get_packages();
402 402
 
403
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
404
-				foreach ( $packages as $package_key => $package ) {
405
-					if ( empty( $package['rates'] ) ) {
406
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
403
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
404
+				foreach ($packages as $package_key => $package) {
405
+					if (empty($package['rates'])) {
406
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
407 407
 					}
408 408
 
409
-					foreach ( $package['rates'] as $key => $rate ) {
409
+					foreach ($package['rates'] as $key => $rate) {
410 410
 						$data[] = array(
411 411
 							'id'       => $rate->id,
412 412
 							'label'    => $rate->label,
@@ -420,16 +420,16 @@  discard block
 block discarded – undo
420 420
 				}
421 421
 
422 422
 				// Auto select the first shipping method.
423
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
423
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
424 424
 
425 425
 				WC()->cart->calculate_totals();
426 426
 
427
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
427
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
428 428
 			} else {
429
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
429
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
430 430
 			}
431
-		} catch ( Exception $e ) {
432
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
431
+		} catch (Exception $e) {
432
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
433 433
 		}
434 434
 	}
435 435
 
@@ -440,29 +440,29 @@  discard block
 block discarded – undo
440 440
 	 * @version 3.1.0
441 441
 	 */
442 442
 	public function update_shipping_method() {
443
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
444
-			define( 'WOOCOMMERCE_CART', true );
443
+		if ( ! defined('WOOCOMMERCE_CART')) {
444
+			define('WOOCOMMERCE_CART', true);
445 445
 		}
446 446
 
447
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
448
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
447
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
448
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
449 449
 		}
450 450
 
451
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
451
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
452 452
 
453
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
453
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
454 454
 
455 455
 		WC()->cart->calculate_totals();
456 456
 
457 457
 		// Send back the new cart total.
458 458
 		$currency  = get_woocommerce_currency();
459
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
459
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
460 460
 		$data      = array(
461 461
 			'total' => WC()->cart->total,
462 462
 		);
463 463
 
464 464
 		// Include fees and taxes as displayItems.
465
-		foreach ( WC()->cart->fees as $key => $fee ) {
465
+		foreach (WC()->cart->fees as $key => $fee) {
466 466
 			$data['items'][] = array(
467 467
 				'label'  => $fee->name,
468 468
 				'amount' => array(
@@ -471,9 +471,9 @@  discard block
 block discarded – undo
471 471
 				),
472 472
 			);
473 473
 		}
474
-		if ( 0 < $tax_total ) {
474
+		if (0 < $tax_total) {
475 475
 			$data['items'][] = array(
476
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
476
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
477 477
 				'amount' => array(
478 478
 					'currency' => $currency,
479 479
 					'value'    => $tax_total,
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 			);
482 482
 		}
483 483
 
484
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
484
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
485 485
 	}
486 486
 
487 487
 	/**
@@ -492,35 +492,35 @@  discard block
 block discarded – undo
492 492
 	 * @version 3.1.0
493 493
 	 */
494 494
 	public function process_apple_pay() {
495
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
496
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
495
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
496
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
497 497
 		}
498 498
 
499 499
 		try {
500
-			$result = array_map( 'wc_clean', $_POST['result'] );
500
+			$result = array_map('wc_clean', $_POST['result']);
501 501
 
502
-			$order = $this->create_order( $result );
502
+			$order = $this->create_order($result);
503 503
 
504 504
 			// Handle payment.
505
-			if ( $order->get_total() > 0 ) {
505
+			if ($order->get_total() > 0) {
506 506
 
507
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
508
-					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 ) ) );
507
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
508
+					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)));
509 509
 				}
510 510
 
511
-				WC_Stripe::log( "Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}" );
511
+				WC_Stripe::log("Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}");
512 512
 
513 513
 				// Make the request.
514
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
514
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
515 515
 
516
-				if ( is_wp_error( $response ) ) {
516
+				if (is_wp_error($response)) {
517 517
 					$localized_messages = $this->get_localized_messages();
518 518
 
519
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
519
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
520 520
 				}
521 521
 
522 522
 				// Process valid response.
523
-				$this->process_response( $response, $order );
523
+				$this->process_response($response, $order);
524 524
 			} else {
525 525
 				$order->payment_complete();
526 526
 			}
@@ -528,24 +528,24 @@  discard block
 block discarded – undo
528 528
 			// Remove cart.
529 529
 			WC()->cart->empty_cart();
530 530
 
531
-			update_post_meta( $order->id, '_customer_user', get_current_user_id() );
532
-			update_post_meta( $order->id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
531
+			update_post_meta($order->id, '_customer_user', get_current_user_id());
532
+			update_post_meta($order->id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
533 533
 
534 534
 			// Return thank you page redirect.
535
-			wp_send_json( array(
535
+			wp_send_json(array(
536 536
 				'success'  => 'true',
537
-				'redirect' => $this->get_return_url( $order ),
538
-			) );
537
+				'redirect' => $this->get_return_url($order),
538
+			));
539 539
 
540
-		} catch ( Exception $e ) {
541
-			WC()->session->set( 'refresh_totals', true );
542
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
540
+		} catch (Exception $e) {
541
+			WC()->session->set('refresh_totals', true);
542
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
543 543
 
544
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
545
-				$this->send_failed_order_email( $order->id );
544
+			if ($order->has_status(array('pending', 'failed'))) {
545
+				$this->send_failed_order_email($order->id);
546 546
 			}
547 547
 
548
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
548
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
549 549
 		}
550 550
 	}
551 551
 
@@ -555,14 +555,14 @@  discard block
 block discarded – undo
555 555
 	 * @param string $source token
556 556
 	 * @return array()
557 557
 	 */
558
-	protected function generate_payment_request( $order, $source ) {
558
+	protected function generate_payment_request($order, $source) {
559 559
 		$post_data                = array();
560
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
561
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
562
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
560
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
561
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
562
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
563 563
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
564 564
 
565
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
565
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
566 566
 			$post_data['receipt_email'] = $order->billing_email;
567 567
 		}
568 568
 
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 		 * @param WC_Order $order
578 578
 		 * @param object $source
579 579
 		 */
580
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
580
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
581 581
 	}
582 582
 
583 583
 	/**
@@ -586,14 +586,14 @@  discard block
 block discarded – undo
586 586
 	 * @since 3.1.0
587 587
 	 * @version 3.1.0
588 588
 	 */
589
-	public function build_shipping_methods( $shipping_methods ) {
590
-		if ( empty( $shipping_methods ) ) {
589
+	public function build_shipping_methods($shipping_methods) {
590
+		if (empty($shipping_methods)) {
591 591
 			return array();
592 592
 		}
593 593
 
594 594
 		$shipping = array();
595 595
 
596
-		foreach ( $shipping_methods as $method ) {
596
+		foreach ($shipping_methods as $method) {
597 597
 			$shipping[] = array(
598 598
 				'label'      => $method['label'],
599 599
 				'detail'     => '',
@@ -612,53 +612,53 @@  discard block
 block discarded – undo
612 612
 	 * @version 3.1.0
613 613
 	 */
614 614
 	public function build_line_items() {
615
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
616
-			define( 'WOOCOMMERCE_CART', true );
615
+		if ( ! defined('WOOCOMMERCE_CART')) {
616
+			define('WOOCOMMERCE_CART', true);
617 617
 		}
618 618
 
619
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
619
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
620 620
 
621 621
 		$items = array();
622 622
 
623
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
624
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
623
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
624
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
625 625
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
626 626
 
627 627
 			$item = array(
628 628
 				'type'   => 'final',
629 629
 				'label'  => $values['data']->post->post_title . $quantity_label,
630
-				'amount' => wc_format_decimal( $amount, $decimals ),
630
+				'amount' => wc_format_decimal($amount, $decimals),
631 631
 			);
632 632
 
633 633
 			$items[] = $item;
634 634
 		}
635 635
 
636
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
637
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
638
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
639
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
640
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
636
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
637
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
638
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
639
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
640
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
641 641
 
642
-		if ( wc_tax_enabled() ) {
642
+		if (wc_tax_enabled()) {
643 643
 			$items[] = array(
644 644
 				'type'   => 'final',
645
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
645
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
646 646
 				'amount' => $tax,
647 647
 			);
648 648
 		}
649 649
 
650
-		if ( WC()->cart->needs_shipping() ) {
650
+		if (WC()->cart->needs_shipping()) {
651 651
 			$items[] = array(
652 652
 				'type'   => 'final',
653
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
653
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
654 654
 				'amount' => $shipping,
655 655
 			);
656 656
 		}
657 657
 
658
-		if ( WC()->cart->has_discount() ) {
658
+		if (WC()->cart->has_discount()) {
659 659
 			$items[] = array(
660 660
 				'type'   => 'final',
661
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
661
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
662 662
 				'amount' => $discounts,
663 663
 			);
664 664
 		}
@@ -674,24 +674,24 @@  discard block
 block discarded – undo
674 674
 	 * @param array $data
675 675
 	 * @return object $order
676 676
 	 */
677
-	public function create_order( $data = array() ) {
678
-		if ( empty( $data ) ) {
679
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
677
+	public function create_order($data = array()) {
678
+		if (empty($data)) {
679
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
680 680
 		}
681 681
 
682 682
 		$order = wc_create_order();
683 683
 
684
-		if ( is_wp_error( $order ) ) {
685
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
686
-		} elseif ( false === $order ) {
687
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
684
+		if (is_wp_error($order)) {
685
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
686
+		} elseif (false === $order) {
687
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
688 688
 		} else {
689 689
 			$order_id = $order->id;
690
-			do_action( 'woocommerce_new_order', $order_id );
690
+			do_action('woocommerce_new_order', $order_id);
691 691
 		}
692 692
 
693 693
 		// Store the line items to the new/resumed order
694
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
694
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
695 695
 			$item_id = $order->add_product(
696 696
 				$values['data'],
697 697
 				$values['quantity'],
@@ -707,47 +707,47 @@  discard block
 block discarded – undo
707 707
 				)
708 708
 			);
709 709
 
710
-			if ( ! $item_id ) {
711
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
710
+			if ( ! $item_id) {
711
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
712 712
 			}
713 713
 
714 714
 			// Allow plugins to add order item meta
715
-			do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
715
+			do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
716 716
 		}
717 717
 
718 718
 		// Store fees
719
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
720
-			$item_id = $order->add_fee( $fee );
719
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
720
+			$item_id = $order->add_fee($fee);
721 721
 
722
-			if ( ! $item_id ) {
723
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
722
+			if ( ! $item_id) {
723
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
724 724
 			}
725 725
 
726 726
 			// Allow plugins to add order item meta to fees
727
-			do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
727
+			do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
728 728
 		}
729 729
 
730 730
 		// Store tax rows
731
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
732
-			if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
733
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
731
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
732
+			if ($tax_rate_id && ! $order->add_tax($tax_rate_id, WC()->cart->get_tax_amount($tax_rate_id), WC()->cart->get_shipping_tax_amount($tax_rate_id)) && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
733
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
734 734
 			}
735 735
 		}
736 736
 
737 737
 		// Store coupons
738
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
739
-			if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
740
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
738
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
739
+			if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) {
740
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
741 741
 			}
742 742
 		}
743 743
 
744 744
 		// Billing address
745 745
 		$billing_address = array();
746
-		if ( ! empty( $data['token']['card'] ) ) {
746
+		if ( ! empty($data['token']['card'])) {
747 747
 			// Name from Stripe is a full name string.
748
-			$name                          = explode( ' ', $data['token']['card']['name'] );
749
-			$lastname                      = array_pop( $name );
750
-			$firstname                     = implode( ' ', $name );
748
+			$name                          = explode(' ', $data['token']['card']['name']);
749
+			$lastname                      = array_pop($name);
750
+			$firstname                     = implode(' ', $name);
751 751
 			$billing_address['first_name'] = $firstname;
752 752
 			$billing_address['last_name']  = $lastname;
753 753
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 
763 763
 		// Shipping address.
764 764
 		$shipping_address = array();
765
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
765
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
766 766
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
767 767
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
768 768
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 			$shipping_address['city']       = $data['shippingContact']['locality'];
774 774
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
775 775
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
776
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
776
+		} elseif ( ! empty($data['shippingContact'])) {
777 777
 			$shipping_address['first_name'] = $firstname;
778 778
 			$shipping_address['last_name']  = $lastname;
779 779
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -786,34 +786,34 @@  discard block
 block discarded – undo
786 786
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
787 787
 		}
788 788
 
789
-		$order->set_address( $billing_address, 'billing' );
790
-		$order->set_address( $shipping_address, 'shipping' );
789
+		$order->set_address($billing_address, 'billing');
790
+		$order->set_address($shipping_address, 'shipping');
791 791
 
792
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
792
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
793 793
 
794 794
 		// Get the rate object selected by user.
795
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
796
-			foreach ( $package['rates'] as $key => $rate ) {
795
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
796
+			foreach ($package['rates'] as $key => $rate) {
797 797
 				// Loop through user chosen shipping methods.
798
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
799
-					if ( $method === $key ) {
800
-						$order->add_shipping( $rate );
798
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
799
+					if ($method === $key) {
800
+						$order->add_shipping($rate);
801 801
 					}
802 802
 				}
803 803
 			}
804 804
 		}
805 805
 
806 806
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
807
-		$order->set_payment_method( $available_gateways['stripe'] );
808
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
809
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
810
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
811
-		$order->set_total( WC()->cart->tax_total, 'tax' );
812
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
813
-		$order->set_total( WC()->cart->total );
807
+		$order->set_payment_method($available_gateways['stripe']);
808
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
809
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
810
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
811
+		$order->set_total(WC()->cart->tax_total, 'tax');
812
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
813
+		$order->set_total(WC()->cart->total);
814 814
 
815 815
 		// If we got here, the order was created without problems!
816
-		wc_transaction_query( 'commit' );
816
+		wc_transaction_query('commit');
817 817
 
818 818
 		return $order;
819 819
 	}
Please login to merge, or discard this patch.