Completed
Push — master ( ba3dcd...d1b3b7 )
by Roy
02:18
created
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +219 added lines, -219 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,35 +66,35 @@  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, 'cart_scripts' ) );
70
-		add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) );
71
-		add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 );
72
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 );
73
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 );
74
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 );
75
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 );
76
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
77
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
78
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) );
79
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
80
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
81
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
69
+		add_action('wp_enqueue_scripts', array($this, 'cart_scripts'));
70
+		add_action('wp_enqueue_scripts', array($this, 'single_scripts'));
71
+		add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1);
72
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1);
73
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2);
74
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1);
75
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2);
76
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
77
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
78
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single'));
79
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
80
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
81
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
82 82
 	}
83 83
 
84 84
 	/**
85 85
 	 * Filters the gateway title to reflect Apple Pay.
86 86
 	 *
87 87
 	 */
88
-	public function filter_gateway_title( $title, $id ) {
88
+	public function filter_gateway_title($title, $id) {
89 89
 		global $post;
90 90
 
91
-		if ( ! is_object( $post ) ) {
91
+		if ( ! is_object($post)) {
92 92
 			return $title;
93 93
 		}
94 94
 
95
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
95
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
96 96
 
97
-		if ( 'stripe' === $id && ! empty( $method_title ) ) {
97
+		if ('stripe' === $id && ! empty($method_title)) {
98 98
 			return $method_title;
99 99
 		}
100 100
 
@@ -108,41 +108,41 @@  discard block
 block discarded – undo
108 108
 	 * @version 3.1.0
109 109
 	 */
110 110
 	public function single_scripts() {
111
-		if ( ! is_single() ) {
111
+		if ( ! is_single()) {
112 112
 			return;
113 113
 		}
114 114
 
115 115
 		global $post;
116 116
 
117
-		$product = wc_get_product( $post->ID );
117
+		$product = wc_get_product($post->ID);
118 118
 
119
-		if ( ! in_array( ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
119
+		if ( ! in_array((version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
120 120
 			return;
121 121
 		}
122 122
 
123
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
123
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
124 124
 
125
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
125
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
126 126
 
127
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
128
-		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 );
127
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
128
+		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);
129 129
 
130 130
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
131 131
 
132 132
 		$stripe_params = array(
133 133
 			'key'                                           => $publishable_key,
134 134
 			'currency_code'                                 => get_woocommerce_currency(),
135
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
135
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
136 136
 			'label'                                         => $this->statement_descriptor,
137
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
138
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
139
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
140
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
141
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
137
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
138
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
139
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
140
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
141
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
142 142
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
143 143
 		);
144 144
 
145
-		wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) );
145
+		wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params));
146 146
 	}
147 147
 
148 148
 	/**
@@ -152,34 +152,34 @@  discard block
 block discarded – undo
152 152
 	 * @version 3.1.0
153 153
 	 */
154 154
 	public function cart_scripts() {
155
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
155
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
156 156
 			return;
157 157
 		}
158 158
 
159
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
159
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
160 160
 
161
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
161
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
162 162
 
163
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
164
-		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 );
163
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
164
+		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);
165 165
 
166 166
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
167 167
 
168 168
 		$stripe_params = array(
169 169
 			'key'                                           => $publishable_key,
170 170
 			'currency_code'                                 => get_woocommerce_currency(),
171
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
171
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
172 172
 			'label'                                         => $this->statement_descriptor,
173
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
174
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
175
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
176
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
177
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
173
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
174
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
175
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
176
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
177
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
178 178
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
179 179
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
180 180
 		);
181 181
 
182
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
182
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
183 183
 	}
184 184
 
185 185
 	/**
@@ -208,25 +208,25 @@  discard block
 block discarded – undo
208 208
 		 */
209 209
 		if (
210 210
 			'yes' !== $this->_gateway_settings['apple_pay']
211
-			|| ! isset( $gateways['stripe'] )
211
+			|| ! isset($gateways['stripe'])
212 212
 		) {
213 213
 			return;
214 214
 		}
215 215
 
216
-		if ( is_single() ) {
216
+		if (is_single()) {
217 217
 			global $post;
218 218
 
219
-			$product = wc_get_product( $post->ID );
219
+			$product = wc_get_product($post->ID);
220 220
 
221
-			if ( ! in_array( ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
221
+			if ( ! in_array((version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
222 222
 				return;
223 223
 			}
224 224
 		}
225 225
 
226
-		$apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black';
227
-		$button_lang      = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en';
226
+		$apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black';
227
+		$button_lang      = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en';
228 228
 		?>
229
-		<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>
229
+		<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>
230 230
 		<?php
231 231
 	}
232 232
 
@@ -245,22 +245,22 @@  discard block
 block discarded – undo
245 245
 		 */
246 246
 		if (
247 247
 			'yes' !== $this->_gateway_settings['apple_pay']
248
-			|| ! isset( $gateways['stripe'] )
248
+			|| ! isset($gateways['stripe'])
249 249
 		) {
250 250
 			return;
251 251
 		}
252 252
 
253
-		if ( is_single() ) {
253
+		if (is_single()) {
254 254
 			global $post;
255 255
 
256
-			$product = wc_get_product( $post->ID );
256
+			$product = wc_get_product($post->ID);
257 257
 
258
-			if ( ! in_array( ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
258
+			if ( ! in_array((version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
259 259
 				return;
260 260
 			}
261 261
 		}
262 262
 		?>
263
-		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p>
263
+		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p>
264 264
 		<?php
265 265
 	}
266 266
 
@@ -271,46 +271,46 @@  discard block
 block discarded – undo
271 271
 	 * @version 3.1.0
272 272
 	 */
273 273
 	public function generate_apple_pay_single() {
274
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
275
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
274
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
275
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
276 276
 		}
277 277
 
278
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
279
-			define( 'WOOCOMMERCE_CART', true );
278
+		if ( ! defined('WOOCOMMERCE_CART')) {
279
+			define('WOOCOMMERCE_CART', true);
280 280
 		}
281 281
 
282 282
 		WC()->shipping->reset_shipping();
283 283
 
284 284
 		global $post;
285 285
 
286
-		$product = wc_get_product( $post->ID );
287
-		$qty     = absint( $_POST['qty'] );
286
+		$product = wc_get_product($post->ID);
287
+		$qty     = absint($_POST['qty']);
288 288
 
289 289
 		/**
290 290
 		 * If this page is single product page, we need to simulate
291 291
 		 * adding the product to the cart taken account if it is a
292 292
 		 * simple or variable product.
293 293
 		 */
294
-		if ( is_single() ) {
294
+		if (is_single()) {
295 295
 			// First empty the cart to prevent wrong calculation.
296 296
 			WC()->cart->empty_cart();
297 297
 
298
-			if ( 'variable' === ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
299
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
298
+			if ('variable' === (version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
299
+				$attributes = array_map('wc_clean', $_POST['attributes']);
300 300
 
301
-				$variation_id = $product->get_matching_variation( $attributes );
301
+				$variation_id = $product->get_matching_variation($attributes);
302 302
 
303
-				WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
303
+				WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
304 304
 			}
305 305
 
306
-			if ( 'simple' === ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
307
-				WC()->cart->add_to_cart( $product->get_id(), $qty );
306
+			if ('simple' === (version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type())) {
307
+				WC()->cart->add_to_cart($product->get_id(), $qty);
308 308
 			}
309 309
 		}
310 310
 
311 311
 		WC()->cart->calculate_totals();
312 312
 
313
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
313
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
314 314
 	}
315 315
 
316 316
 	/**
@@ -320,11 +320,11 @@  discard block
 block discarded – undo
320 320
 	 * @version 3.1.0
321 321
 	 */
322 322
 	public function generate_apple_pay_cart() {
323
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
324
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
323
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
324
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
325 325
 		}
326 326
 
327
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
327
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
328 328
 	}
329 329
 
330 330
 	/**
@@ -334,29 +334,29 @@  discard block
 block discarded – undo
334 334
 	 * @version 3.1.0
335 335
 	 * @param array $address
336 336
 	 */
337
-	public function calculate_shipping( $address = array() ) {
338
-		$country  = strtoupper( $address['countryCode'] );
339
-		$state    = strtoupper( $address['administrativeArea'] );
337
+	public function calculate_shipping($address = array()) {
338
+		$country  = strtoupper($address['countryCode']);
339
+		$state    = strtoupper($address['administrativeArea']);
340 340
 		$postcode = $address['postalCode'];
341 341
 		$city     = $address['locality'];
342 342
 
343 343
 		WC()->shipping->reset_shipping();
344 344
 
345
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
346
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
347
-		} elseif ( $postcode ) {
348
-			$postcode = wc_format_postcode( $postcode, $country );
345
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
346
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
347
+		} elseif ($postcode) {
348
+			$postcode = wc_format_postcode($postcode, $country);
349 349
 		}
350 350
 
351
-		if ( $country ) {
352
-			WC()->customer->set_location( $country, $state, $postcode, $city );
353
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
351
+		if ($country) {
352
+			WC()->customer->set_location($country, $state, $postcode, $city);
353
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
354 354
 		} else {
355 355
 			WC()->customer->set_to_base();
356 356
 			WC()->customer->set_shipping_to_base();
357 357
 		}
358 358
 
359
-		WC()->customer->calculated_shipping( true );
359
+		WC()->customer->calculated_shipping(true);
360 360
 
361 361
 		/**
362 362
 		 * Set the shipping package.
@@ -378,17 +378,17 @@  discard block
 block discarded – undo
378 378
 		$packages[0]['destination']['postcode']  = $postcode;
379 379
 		$packages[0]['destination']['city']      = $city;
380 380
 
381
-		foreach ( WC()->cart->get_cart() as $item ) {
382
-			if ( $item['data']->needs_shipping() ) {
383
-				if ( isset( $item['line_total'] ) ) {
381
+		foreach (WC()->cart->get_cart() as $item) {
382
+			if ($item['data']->needs_shipping()) {
383
+				if (isset($item['line_total'])) {
384 384
 					$packages[0]['contents_cost'] += $item['line_total'];
385 385
 				}
386 386
 			}
387 387
 		}
388 388
 
389
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
389
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
390 390
 
391
-		WC()->shipping->calculate_shipping( $packages );
391
+		WC()->shipping->calculate_shipping($packages);
392 392
 	}
393 393
 
394 394
 	/**
@@ -398,18 +398,18 @@  discard block
 block discarded – undo
398 398
 	 * @version 3.1.0
399 399
 	 */
400 400
 	public function get_shipping_methods() {
401
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
402
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
401
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
402
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
403 403
 		}
404 404
 
405
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
406
-			define( 'WOOCOMMERCE_CART', true );
405
+		if ( ! defined('WOOCOMMERCE_CART')) {
406
+			define('WOOCOMMERCE_CART', true);
407 407
 		}
408 408
 
409 409
 		try {
410
-			$address = array_map( 'wc_clean', $_POST['address'] );
410
+			$address = array_map('wc_clean', $_POST['address']);
411 411
 
412
-			$this->calculate_shipping( $address );
412
+			$this->calculate_shipping($address);
413 413
 
414 414
 			// Set the shipping options.
415 415
 			$currency = get_woocommerce_currency();
@@ -417,13 +417,13 @@  discard block
 block discarded – undo
417 417
 
418 418
 			$packages = WC()->shipping->get_packages();
419 419
 
420
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
421
-				foreach ( $packages as $package_key => $package ) {
422
-					if ( empty( $package['rates'] ) ) {
423
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
420
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
421
+				foreach ($packages as $package_key => $package) {
422
+					if (empty($package['rates'])) {
423
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
424 424
 					}
425 425
 
426
-					foreach ( $package['rates'] as $key => $rate ) {
426
+					foreach ($package['rates'] as $key => $rate) {
427 427
 						$data[] = array(
428 428
 							'id'       => $rate->id,
429 429
 							'label'    => $rate->label,
@@ -437,16 +437,16 @@  discard block
 block discarded – undo
437 437
 				}
438 438
 
439 439
 				// Auto select the first shipping method.
440
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
440
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
441 441
 
442 442
 				WC()->cart->calculate_totals();
443 443
 
444
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
444
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
445 445
 			} else {
446
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
446
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
447 447
 			}
448
-		} catch ( Exception $e ) {
449
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
448
+		} catch (Exception $e) {
449
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
450 450
 		}
451 451
 	}
452 452
 
@@ -457,29 +457,29 @@  discard block
 block discarded – undo
457 457
 	 * @version 3.1.0
458 458
 	 */
459 459
 	public function update_shipping_method() {
460
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
461
-			define( 'WOOCOMMERCE_CART', true );
460
+		if ( ! defined('WOOCOMMERCE_CART')) {
461
+			define('WOOCOMMERCE_CART', true);
462 462
 		}
463 463
 
464
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
465
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
464
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
465
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
466 466
 		}
467 467
 
468
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
468
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
469 469
 
470
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
470
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
471 471
 
472 472
 		WC()->cart->calculate_totals();
473 473
 
474 474
 		// Send back the new cart total.
475 475
 		$currency  = get_woocommerce_currency();
476
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
476
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
477 477
 		$data      = array(
478 478
 			'total' => WC()->cart->total,
479 479
 		);
480 480
 
481 481
 		// Include fees and taxes as displayItems.
482
-		foreach ( WC()->cart->fees as $key => $fee ) {
482
+		foreach (WC()->cart->fees as $key => $fee) {
483 483
 			$data['items'][] = array(
484 484
 				'label'  => $fee->name,
485 485
 				'amount' => array(
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
 				),
489 489
 			);
490 490
 		}
491
-		if ( 0 < $tax_total ) {
491
+		if (0 < $tax_total) {
492 492
 			$data['items'][] = array(
493
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
493
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
494 494
 				'amount' => array(
495 495
 					'currency' => $currency,
496 496
 					'value'    => $tax_total,
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 			);
499 499
 		}
500 500
 
501
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
501
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
502 502
 	}
503 503
 
504 504
 	/**
@@ -509,37 +509,37 @@  discard block
 block discarded – undo
509 509
 	 * @version 3.1.0
510 510
 	 */
511 511
 	public function process_apple_pay() {
512
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
513
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
512
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
513
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
514 514
 		}
515 515
 
516 516
 		try {
517
-			$result = array_map( 'wc_clean', $_POST['result'] );
517
+			$result = array_map('wc_clean', $_POST['result']);
518 518
 
519
-			$order = $this->create_order( $result );
519
+			$order = $this->create_order($result);
520 520
 
521
-			$order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id();
521
+			$order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id();
522 522
 
523 523
 			// Handle payment.
524
-			if ( $order->get_total() > 0 ) {
524
+			if ($order->get_total() > 0) {
525 525
 
526
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
527
-					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 ) ) );
526
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
527
+					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)));
528 528
 				}
529 529
 
530
-				WC_Stripe::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" );
530
+				WC_Stripe::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}");
531 531
 
532 532
 				// Make the request.
533
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
533
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
534 534
 
535
-				if ( is_wp_error( $response ) ) {
535
+				if (is_wp_error($response)) {
536 536
 					$localized_messages = $this->get_localized_messages();
537 537
 
538
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
538
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
539 539
 				}
540 540
 
541 541
 				// Process valid response.
542
-				$this->process_response( $response, $order );
542
+				$this->process_response($response, $order);
543 543
 			} else {
544 544
 				$order->payment_complete();
545 545
 			}
@@ -547,24 +547,24 @@  discard block
 block discarded – undo
547 547
 			// Remove cart.
548 548
 			WC()->cart->empty_cart();
549 549
 
550
-			update_post_meta( $order_id, '_customer_user', get_current_user_id() );
551
-			update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
550
+			update_post_meta($order_id, '_customer_user', get_current_user_id());
551
+			update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
552 552
 
553 553
 			// Return thank you page redirect.
554
-			wp_send_json( array(
554
+			wp_send_json(array(
555 555
 				'success'  => 'true',
556
-				'redirect' => $this->get_return_url( $order ),
557
-			) );
556
+				'redirect' => $this->get_return_url($order),
557
+			));
558 558
 
559
-		} catch ( Exception $e ) {
560
-			WC()->session->set( 'refresh_totals', true );
561
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
559
+		} catch (Exception $e) {
560
+			WC()->session->set('refresh_totals', true);
561
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
562 562
 
563
-			if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
564
-				$this->send_failed_order_email( $order_id );
563
+			if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) {
564
+				$this->send_failed_order_email($order_id);
565 565
 			}
566 566
 
567
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
567
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
568 568
 		}
569 569
 	}
570 570
 
@@ -574,16 +574,16 @@  discard block
 block discarded – undo
574 574
 	 * @param string $source token
575 575
 	 * @return array()
576 576
 	 */
577
-	protected function generate_payment_request( $order, $source ) {
577
+	protected function generate_payment_request($order, $source) {
578 578
 		$post_data                = array();
579
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
580
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
581
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
579
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '2.7.0', '<') ? $order->get_order_currency() : $order->get_currency());
580
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
581
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
582 582
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
583 583
 
584
-		$billing_email      = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_email : $order->get_billing_email();
584
+		$billing_email = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_email : $order->get_billing_email();
585 585
 
586
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
586
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
587 587
 			$post_data['receipt_email'] = $billing_email;
588 588
 		}
589 589
 
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 		 * @param WC_Order $order
599 599
 		 * @param object $source
600 600
 		 */
601
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
601
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
602 602
 	}
603 603
 
604 604
 	/**
@@ -607,14 +607,14 @@  discard block
 block discarded – undo
607 607
 	 * @since 3.1.0
608 608
 	 * @version 3.1.0
609 609
 	 */
610
-	public function build_shipping_methods( $shipping_methods ) {
611
-		if ( empty( $shipping_methods ) ) {
610
+	public function build_shipping_methods($shipping_methods) {
611
+		if (empty($shipping_methods)) {
612 612
 			return array();
613 613
 		}
614 614
 
615 615
 		$shipping = array();
616 616
 
617
-		foreach ( $shipping_methods as $method ) {
617
+		foreach ($shipping_methods as $method) {
618 618
 			$shipping[] = array(
619 619
 				'label'      => $method['label'],
620 620
 				'detail'     => '',
@@ -633,65 +633,65 @@  discard block
 block discarded – undo
633 633
 	 * @version 3.1.0
634 634
 	 */
635 635
 	public function build_line_items() {
636
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
637
-			define( 'WOOCOMMERCE_CART', true );
636
+		if ( ! defined('WOOCOMMERCE_CART')) {
637
+			define('WOOCOMMERCE_CART', true);
638 638
 		}
639 639
 
640
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
640
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
641 641
 		
642 642
 		$items    = array();
643 643
 		$subtotal = 0;
644 644
 
645
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
646
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
647
-			$subtotal       += $values['line_subtotal']; 
645
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
646
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
647
+			$subtotal += $values['line_subtotal']; 
648 648
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
649 649
 
650 650
 			$item = array(
651 651
 				'type'   => 'final',
652 652
 				'label'  => $values['data']->post->post_title . $quantity_label,
653
-				'amount' => wc_format_decimal( $amount, $decimals ),
653
+				'amount' => wc_format_decimal($amount, $decimals),
654 654
 			);
655 655
 
656 656
 			$items[] = $item;
657 657
 		}
658 658
 
659 659
 		// Default show only subtotal instead of itemization.
660
-		if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) {
660
+		if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) {
661 661
 			$items = array();
662 662
 			$items[] = array(
663 663
 				'type'   => 'final',
664
-				'label'  => __( 'Sub-Total', 'woocommerce-gateway-stripe' ),
665
-				'amount' => wc_format_decimal( $subtotal, $decimals ),
664
+				'label'  => __('Sub-Total', 'woocommerce-gateway-stripe'),
665
+				'amount' => wc_format_decimal($subtotal, $decimals),
666 666
 			);
667 667
 		}
668 668
 
669
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
670
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
671
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
672
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
673
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
669
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
670
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
671
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
672
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
673
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
674 674
 
675
-		if ( wc_tax_enabled() ) {
675
+		if (wc_tax_enabled()) {
676 676
 			$items[] = array(
677 677
 				'type'   => 'final',
678
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
678
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
679 679
 				'amount' => $tax,
680 680
 			);
681 681
 		}
682 682
 
683
-		if ( WC()->cart->needs_shipping() ) {
683
+		if (WC()->cart->needs_shipping()) {
684 684
 			$items[] = array(
685 685
 				'type'   => 'final',
686
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
686
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
687 687
 				'amount' => $shipping,
688 688
 			);
689 689
 		}
690 690
 
691
-		if ( WC()->cart->has_discount() ) {
691
+		if (WC()->cart->has_discount()) {
692 692
 			$items[] = array(
693 693
 				'type'   => 'final',
694
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
694
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
695 695
 				'amount' => '-' . $discounts,
696 696
 			);
697 697
 		}
@@ -707,24 +707,24 @@  discard block
 block discarded – undo
707 707
 	 * @param array $data
708 708
 	 * @return object $order
709 709
 	 */
710
-	public function create_order( $data = array() ) {
711
-		if ( empty( $data ) ) {
712
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
710
+	public function create_order($data = array()) {
711
+		if (empty($data)) {
712
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
713 713
 		}
714 714
 
715 715
 		$order = wc_create_order();
716
-		$order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id();
716
+		$order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id();
717 717
 
718
-		if ( is_wp_error( $order ) ) {
719
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
720
-		} elseif ( false === $order ) {
721
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
718
+		if (is_wp_error($order)) {
719
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
720
+		} elseif (false === $order) {
721
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
722 722
 		} else {
723
-			do_action( 'woocommerce_new_order', $order_id );
723
+			do_action('woocommerce_new_order', $order_id);
724 724
 		}
725 725
 
726 726
 		// Store the line items to the new/resumed order
727
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
727
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
728 728
 			$item_id = $order->add_product(
729 729
 				$values['data'],
730 730
 				$values['quantity'],
@@ -740,47 +740,47 @@  discard block
 block discarded – undo
740 740
 				)
741 741
 			);
742 742
 
743
-			if ( ! $item_id ) {
744
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
743
+			if ( ! $item_id) {
744
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
745 745
 			}
746 746
 
747 747
 			// Allow plugins to add order item meta
748
-			do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
748
+			do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
749 749
 		}
750 750
 
751 751
 		// Store fees
752
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
753
-			$item_id = $order->add_fee( $fee );
752
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
753
+			$item_id = $order->add_fee($fee);
754 754
 
755
-			if ( ! $item_id ) {
756
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
755
+			if ( ! $item_id) {
756
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
757 757
 			}
758 758
 
759 759
 			// Allow plugins to add order item meta to fees
760
-			do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
760
+			do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
761 761
 		}
762 762
 
763 763
 		// Store tax rows
764
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
765
-			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 ) {
766
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
764
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
765
+			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) {
766
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
767 767
 			}
768 768
 		}
769 769
 
770 770
 		// Store coupons
771
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
772
-			if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
773
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
771
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
772
+			if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) {
773
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
774 774
 			}
775 775
 		}
776 776
 
777 777
 		// Billing address
778 778
 		$billing_address = array();
779
-		if ( ! empty( $data['token']['card'] ) ) {
779
+		if ( ! empty($data['token']['card'])) {
780 780
 			// Name from Stripe is a full name string.
781
-			$name                          = explode( ' ', $data['token']['card']['name'] );
782
-			$lastname                      = array_pop( $name );
783
-			$firstname                     = implode( ' ', $name );
781
+			$name                          = explode(' ', $data['token']['card']['name']);
782
+			$lastname                      = array_pop($name);
783
+			$firstname                     = implode(' ', $name);
784 784
 			$billing_address['first_name'] = $firstname;
785 785
 			$billing_address['last_name']  = $lastname;
786 786
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 
796 796
 		// Shipping address.
797 797
 		$shipping_address = array();
798
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
798
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
799 799
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
800 800
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
801 801
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 			$shipping_address['city']       = $data['shippingContact']['locality'];
807 807
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
808 808
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
809
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
809
+		} elseif ( ! empty($data['shippingContact'])) {
810 810
 			$shipping_address['first_name'] = $firstname;
811 811
 			$shipping_address['last_name']  = $lastname;
812 812
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -819,34 +819,34 @@  discard block
 block discarded – undo
819 819
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
820 820
 		}
821 821
 
822
-		$order->set_address( $billing_address, 'billing' );
823
-		$order->set_address( $shipping_address, 'shipping' );
822
+		$order->set_address($billing_address, 'billing');
823
+		$order->set_address($shipping_address, 'shipping');
824 824
 
825
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
825
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
826 826
 
827 827
 		// Get the rate object selected by user.
828
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
829
-			foreach ( $package['rates'] as $key => $rate ) {
828
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
829
+			foreach ($package['rates'] as $key => $rate) {
830 830
 				// Loop through user chosen shipping methods.
831
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
832
-					if ( $method === $key ) {
833
-						$order->add_shipping( $rate );
831
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
832
+					if ($method === $key) {
833
+						$order->add_shipping($rate);
834 834
 					}
835 835
 				}
836 836
 			}
837 837
 		}
838 838
 
839 839
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
840
-		$order->set_payment_method( $available_gateways['stripe'] );
841
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
842
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
843
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
844
-		$order->set_total( WC()->cart->tax_total, 'tax' );
845
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
846
-		$order->set_total( WC()->cart->total );
840
+		$order->set_payment_method($available_gateways['stripe']);
841
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
842
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
843
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
844
+		$order->set_total(WC()->cart->tax_total, 'tax');
845
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
846
+		$order->set_total(WC()->cart->total);
847 847
 
848 848
 		// If we got here, the order was created without problems!
849
-		wc_transaction_query( 'commit' );
849
+		wc_transaction_query('commit');
850 850
 
851 851
 		return $order;
852 852
 	}
Please login to merge, or discard this patch.