Completed
Push — master ( c04060...67d8c3 )
by Roy
02:13
created
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +215 added lines, -215 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,44 +271,44 @@  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
 		global $post;
283 283
 
284
-		$product = wc_get_product( $post->ID );
285
-		$qty     = absint( $_POST['qty'] );
284
+		$product = wc_get_product($post->ID);
285
+		$qty     = absint($_POST['qty']);
286 286
 
287 287
 		/**
288 288
 		 * If this page is single product page, we need to simulate
289 289
 		 * adding the product to the cart taken account if it is a
290 290
 		 * simple or variable product.
291 291
 		 */
292
-		if ( is_single() ) {
292
+		if (is_single()) {
293 293
 			// First empty the cart to prevent wrong calculation.
294 294
 			WC()->cart->empty_cart();
295 295
 
296
-			if ( 'variable' === ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
297
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
296
+			if ('variable' === (version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
297
+				$attributes = array_map('wc_clean', $_POST['attributes']);
298 298
 
299
-				$variation_id = $product->get_matching_variation( $attributes );
299
+				$variation_id = $product->get_matching_variation($attributes);
300 300
 
301
-				WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
301
+				WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
302 302
 			}
303 303
 
304
-			if ( 'simple' === ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
305
-				WC()->cart->add_to_cart( $product->get_id(), $qty );
304
+			if ('simple' === (version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type())) {
305
+				WC()->cart->add_to_cart($product->get_id(), $qty);
306 306
 			}
307 307
 		}
308 308
 
309 309
 		WC()->cart->calculate_totals();
310 310
 
311
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
311
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
312 312
 	}
313 313
 
314 314
 	/**
@@ -318,11 +318,11 @@  discard block
 block discarded – undo
318 318
 	 * @version 3.1.0
319 319
 	 */
320 320
 	public function generate_apple_pay_cart() {
321
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
322
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
321
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
322
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
323 323
 		}
324 324
 
325
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
325
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
326 326
 	}
327 327
 
328 328
 	/**
@@ -332,29 +332,29 @@  discard block
 block discarded – undo
332 332
 	 * @version 3.1.0
333 333
 	 * @param array $address
334 334
 	 */
335
-	public function calculate_shipping( $address = array() ) {
336
-		$country  = strtoupper( $address['countryCode'] );
337
-		$state    = strtoupper( $address['administrativeArea'] );
335
+	public function calculate_shipping($address = array()) {
336
+		$country  = strtoupper($address['countryCode']);
337
+		$state    = strtoupper($address['administrativeArea']);
338 338
 		$postcode = $address['postalCode'];
339 339
 		$city     = $address['locality'];
340 340
 
341 341
 		WC()->shipping->reset_shipping();
342 342
 
343
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
344
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
345
-		} elseif ( $postcode ) {
346
-			$postcode = wc_format_postcode( $postcode, $country );
343
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
344
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
345
+		} elseif ($postcode) {
346
+			$postcode = wc_format_postcode($postcode, $country);
347 347
 		}
348 348
 
349
-		if ( $country ) {
350
-			WC()->customer->set_location( $country, $state, $postcode, $city );
351
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
349
+		if ($country) {
350
+			WC()->customer->set_location($country, $state, $postcode, $city);
351
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
352 352
 		} else {
353 353
 			WC()->customer->set_to_base();
354 354
 			WC()->customer->set_shipping_to_base();
355 355
 		}
356 356
 
357
-		WC()->customer->calculated_shipping( true );
357
+		WC()->customer->calculated_shipping(true);
358 358
 
359 359
 		/**
360 360
 		 * Set the shipping package.
@@ -376,17 +376,17 @@  discard block
 block discarded – undo
376 376
 		$packages[0]['destination']['postcode']  = $postcode;
377 377
 		$packages[0]['destination']['city']      = $city;
378 378
 
379
-		foreach ( WC()->cart->get_cart() as $item ) {
380
-			if ( $item['data']->needs_shipping() ) {
381
-				if ( isset( $item['line_total'] ) ) {
379
+		foreach (WC()->cart->get_cart() as $item) {
380
+			if ($item['data']->needs_shipping()) {
381
+				if (isset($item['line_total'])) {
382 382
 					$packages[0]['contents_cost'] += $item['line_total'];
383 383
 				}
384 384
 			}
385 385
 		}
386 386
 
387
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
387
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
388 388
 
389
-		WC()->shipping->calculate_shipping( $packages );
389
+		WC()->shipping->calculate_shipping($packages);
390 390
 	}
391 391
 
392 392
 	/**
@@ -396,18 +396,18 @@  discard block
 block discarded – undo
396 396
 	 * @version 3.1.0
397 397
 	 */
398 398
 	public function get_shipping_methods() {
399
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
400
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
399
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
400
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
401 401
 		}
402 402
 
403
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
404
-			define( 'WOOCOMMERCE_CART', true );
403
+		if ( ! defined('WOOCOMMERCE_CART')) {
404
+			define('WOOCOMMERCE_CART', true);
405 405
 		}
406 406
 
407 407
 		try {
408
-			$address = array_map( 'wc_clean', $_POST['address'] );
408
+			$address = array_map('wc_clean', $_POST['address']);
409 409
 
410
-			$this->calculate_shipping( $address );
410
+			$this->calculate_shipping($address);
411 411
 
412 412
 			// Set the shipping options.
413 413
 			$currency = get_woocommerce_currency();
@@ -415,13 +415,13 @@  discard block
 block discarded – undo
415 415
 
416 416
 			$packages = WC()->shipping->get_packages();
417 417
 
418
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
419
-				foreach ( $packages as $package_key => $package ) {
420
-					if ( empty( $package['rates'] ) ) {
421
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
418
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
419
+				foreach ($packages as $package_key => $package) {
420
+					if (empty($package['rates'])) {
421
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
422 422
 					}
423 423
 
424
-					foreach ( $package['rates'] as $key => $rate ) {
424
+					foreach ($package['rates'] as $key => $rate) {
425 425
 						$data[] = array(
426 426
 							'id'       => $rate->id,
427 427
 							'label'    => $rate->label,
@@ -435,16 +435,16 @@  discard block
 block discarded – undo
435 435
 				}
436 436
 
437 437
 				// Auto select the first shipping method.
438
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
438
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
439 439
 
440 440
 				WC()->cart->calculate_totals();
441 441
 
442
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
442
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
443 443
 			} else {
444
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
444
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
445 445
 			}
446
-		} catch ( Exception $e ) {
447
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
446
+		} catch (Exception $e) {
447
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
448 448
 		}
449 449
 	}
450 450
 
@@ -455,29 +455,29 @@  discard block
 block discarded – undo
455 455
 	 * @version 3.1.0
456 456
 	 */
457 457
 	public function update_shipping_method() {
458
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
459
-			define( 'WOOCOMMERCE_CART', true );
458
+		if ( ! defined('WOOCOMMERCE_CART')) {
459
+			define('WOOCOMMERCE_CART', true);
460 460
 		}
461 461
 
462
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
463
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
462
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
463
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
464 464
 		}
465 465
 
466
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
466
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
467 467
 
468
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
468
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
469 469
 
470 470
 		WC()->cart->calculate_totals();
471 471
 
472 472
 		// Send back the new cart total.
473 473
 		$currency  = get_woocommerce_currency();
474
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
474
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
475 475
 		$data      = array(
476 476
 			'total' => WC()->cart->total,
477 477
 		);
478 478
 
479 479
 		// Include fees and taxes as displayItems.
480
-		foreach ( WC()->cart->fees as $key => $fee ) {
480
+		foreach (WC()->cart->fees as $key => $fee) {
481 481
 			$data['items'][] = array(
482 482
 				'label'  => $fee->name,
483 483
 				'amount' => array(
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
 				),
487 487
 			);
488 488
 		}
489
-		if ( 0 < $tax_total ) {
489
+		if (0 < $tax_total) {
490 490
 			$data['items'][] = array(
491
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
491
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
492 492
 				'amount' => array(
493 493
 					'currency' => $currency,
494 494
 					'value'    => $tax_total,
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 			);
497 497
 		}
498 498
 
499
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
499
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
500 500
 	}
501 501
 
502 502
 	/**
@@ -507,37 +507,37 @@  discard block
 block discarded – undo
507 507
 	 * @version 3.1.0
508 508
 	 */
509 509
 	public function process_apple_pay() {
510
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
511
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
510
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
511
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
512 512
 		}
513 513
 
514 514
 		try {
515
-			$result = array_map( 'wc_clean', $_POST['result'] );
515
+			$result = array_map('wc_clean', $_POST['result']);
516 516
 
517
-			$order = $this->create_order( $result );
517
+			$order = $this->create_order($result);
518 518
 
519
-			$order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id();
519
+			$order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id();
520 520
 
521 521
 			// Handle payment.
522
-			if ( $order->get_total() > 0 ) {
522
+			if ($order->get_total() > 0) {
523 523
 
524
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
525
-					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 ) ) );
524
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
525
+					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 526
 				}
527 527
 
528
-				WC_Stripe::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" );
528
+				WC_Stripe::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}");
529 529
 
530 530
 				// Make the request.
531
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
531
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
532 532
 
533
-				if ( is_wp_error( $response ) ) {
533
+				if (is_wp_error($response)) {
534 534
 					$localized_messages = $this->get_localized_messages();
535 535
 
536
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
536
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
537 537
 				}
538 538
 
539 539
 				// Process valid response.
540
-				$this->process_response( $response, $order );
540
+				$this->process_response($response, $order);
541 541
 			} else {
542 542
 				$order->payment_complete();
543 543
 			}
@@ -545,24 +545,24 @@  discard block
 block discarded – undo
545 545
 			// Remove cart.
546 546
 			WC()->cart->empty_cart();
547 547
 
548
-			update_post_meta( $order_id, '_customer_user', get_current_user_id() );
549
-			update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
548
+			update_post_meta($order_id, '_customer_user', get_current_user_id());
549
+			update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
550 550
 
551 551
 			// Return thank you page redirect.
552
-			wp_send_json( array(
552
+			wp_send_json(array(
553 553
 				'success'  => 'true',
554
-				'redirect' => $this->get_return_url( $order ),
555
-			) );
554
+				'redirect' => $this->get_return_url($order),
555
+			));
556 556
 
557
-		} catch ( Exception $e ) {
558
-			WC()->session->set( 'refresh_totals', true );
559
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
557
+		} catch (Exception $e) {
558
+			WC()->session->set('refresh_totals', true);
559
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
560 560
 
561
-			if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
562
-				$this->send_failed_order_email( $order_id );
561
+			if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) {
562
+				$this->send_failed_order_email($order_id);
563 563
 			}
564 564
 
565
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
565
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
566 566
 		}
567 567
 	}
568 568
 
@@ -572,16 +572,16 @@  discard block
 block discarded – undo
572 572
 	 * @param string $source token
573 573
 	 * @return array()
574 574
 	 */
575
-	protected function generate_payment_request( $order, $source ) {
575
+	protected function generate_payment_request($order, $source) {
576 576
 		$post_data                = array();
577
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
578
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
579
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
577
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '2.7.0', '<') ? $order->get_order_currency() : $order->get_currency());
578
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
579
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
580 580
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
581 581
 
582
-		$billing_email      = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_email : $order->get_billing_email();
582
+		$billing_email = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_email : $order->get_billing_email();
583 583
 
584
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
584
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
585 585
 			$post_data['receipt_email'] = $billing_email;
586 586
 		}
587 587
 
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 		 * @param WC_Order $order
597 597
 		 * @param object $source
598 598
 		 */
599
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
599
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
600 600
 	}
601 601
 
602 602
 	/**
@@ -605,14 +605,14 @@  discard block
 block discarded – undo
605 605
 	 * @since 3.1.0
606 606
 	 * @version 3.1.0
607 607
 	 */
608
-	public function build_shipping_methods( $shipping_methods ) {
609
-		if ( empty( $shipping_methods ) ) {
608
+	public function build_shipping_methods($shipping_methods) {
609
+		if (empty($shipping_methods)) {
610 610
 			return array();
611 611
 		}
612 612
 
613 613
 		$shipping = array();
614 614
 
615
-		foreach ( $shipping_methods as $method ) {
615
+		foreach ($shipping_methods as $method) {
616 616
 			$shipping[] = array(
617 617
 				'label'      => $method['label'],
618 618
 				'detail'     => '',
@@ -631,53 +631,53 @@  discard block
 block discarded – undo
631 631
 	 * @version 3.1.0
632 632
 	 */
633 633
 	public function build_line_items() {
634
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
635
-			define( 'WOOCOMMERCE_CART', true );
634
+		if ( ! defined('WOOCOMMERCE_CART')) {
635
+			define('WOOCOMMERCE_CART', true);
636 636
 		}
637 637
 
638
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
638
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
639 639
 
640 640
 		$items = array();
641 641
 
642
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
643
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
642
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
643
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
644 644
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
645 645
 
646 646
 			$item = array(
647 647
 				'type'   => 'final',
648 648
 				'label'  => $values['data']->post->post_title . $quantity_label,
649
-				'amount' => wc_format_decimal( $amount, $decimals ),
649
+				'amount' => wc_format_decimal($amount, $decimals),
650 650
 			);
651 651
 
652 652
 			$items[] = $item;
653 653
 		}
654 654
 
655
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
656
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
657
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
658
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
659
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
655
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
656
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
657
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
658
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
659
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
660 660
 
661
-		if ( wc_tax_enabled() ) {
661
+		if (wc_tax_enabled()) {
662 662
 			$items[] = array(
663 663
 				'type'   => 'final',
664
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
664
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
665 665
 				'amount' => $tax,
666 666
 			);
667 667
 		}
668 668
 
669
-		if ( WC()->cart->needs_shipping() ) {
669
+		if (WC()->cart->needs_shipping()) {
670 670
 			$items[] = array(
671 671
 				'type'   => 'final',
672
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
672
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
673 673
 				'amount' => $shipping,
674 674
 			);
675 675
 		}
676 676
 
677
-		if ( WC()->cart->has_discount() ) {
677
+		if (WC()->cart->has_discount()) {
678 678
 			$items[] = array(
679 679
 				'type'   => 'final',
680
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
680
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
681 681
 				'amount' => $discounts,
682 682
 			);
683 683
 		}
@@ -693,24 +693,24 @@  discard block
 block discarded – undo
693 693
 	 * @param array $data
694 694
 	 * @return object $order
695 695
 	 */
696
-	public function create_order( $data = array() ) {
697
-		if ( empty( $data ) ) {
698
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
696
+	public function create_order($data = array()) {
697
+		if (empty($data)) {
698
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
699 699
 		}
700 700
 
701 701
 		$order = wc_create_order();
702
-		$order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id();
702
+		$order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id();
703 703
 
704
-		if ( is_wp_error( $order ) ) {
705
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
706
-		} elseif ( false === $order ) {
707
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
704
+		if (is_wp_error($order)) {
705
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
706
+		} elseif (false === $order) {
707
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
708 708
 		} else {
709
-			do_action( 'woocommerce_new_order', $order_id );
709
+			do_action('woocommerce_new_order', $order_id);
710 710
 		}
711 711
 
712 712
 		// Store the line items to the new/resumed order
713
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
713
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
714 714
 			$item_id = $order->add_product(
715 715
 				$values['data'],
716 716
 				$values['quantity'],
@@ -726,47 +726,47 @@  discard block
 block discarded – undo
726 726
 				)
727 727
 			);
728 728
 
729
-			if ( ! $item_id ) {
730
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
729
+			if ( ! $item_id) {
730
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
731 731
 			}
732 732
 
733 733
 			// Allow plugins to add order item meta
734
-			do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
734
+			do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
735 735
 		}
736 736
 
737 737
 		// Store fees
738
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
739
-			$item_id = $order->add_fee( $fee );
738
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
739
+			$item_id = $order->add_fee($fee);
740 740
 
741
-			if ( ! $item_id ) {
742
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
741
+			if ( ! $item_id) {
742
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
743 743
 			}
744 744
 
745 745
 			// Allow plugins to add order item meta to fees
746
-			do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
746
+			do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
747 747
 		}
748 748
 
749 749
 		// Store tax rows
750
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
751
-			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 ) {
752
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
750
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
751
+			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) {
752
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
753 753
 			}
754 754
 		}
755 755
 
756 756
 		// Store coupons
757
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
758
-			if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
759
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
757
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
758
+			if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) {
759
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
760 760
 			}
761 761
 		}
762 762
 
763 763
 		// Billing address
764 764
 		$billing_address = array();
765
-		if ( ! empty( $data['token']['card'] ) ) {
765
+		if ( ! empty($data['token']['card'])) {
766 766
 			// Name from Stripe is a full name string.
767
-			$name                          = explode( ' ', $data['token']['card']['name'] );
768
-			$lastname                      = array_pop( $name );
769
-			$firstname                     = implode( ' ', $name );
767
+			$name                          = explode(' ', $data['token']['card']['name']);
768
+			$lastname                      = array_pop($name);
769
+			$firstname                     = implode(' ', $name);
770 770
 			$billing_address['first_name'] = $firstname;
771 771
 			$billing_address['last_name']  = $lastname;
772 772
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
 
782 782
 		// Shipping address.
783 783
 		$shipping_address = array();
784
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
784
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
785 785
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
786 786
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
787 787
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 			$shipping_address['city']       = $data['shippingContact']['locality'];
793 793
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
794 794
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
795
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
795
+		} elseif ( ! empty($data['shippingContact'])) {
796 796
 			$shipping_address['first_name'] = $firstname;
797 797
 			$shipping_address['last_name']  = $lastname;
798 798
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -805,34 +805,34 @@  discard block
 block discarded – undo
805 805
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
806 806
 		}
807 807
 
808
-		$order->set_address( $billing_address, 'billing' );
809
-		$order->set_address( $shipping_address, 'shipping' );
808
+		$order->set_address($billing_address, 'billing');
809
+		$order->set_address($shipping_address, 'shipping');
810 810
 
811
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
811
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
812 812
 
813 813
 		// Get the rate object selected by user.
814
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
815
-			foreach ( $package['rates'] as $key => $rate ) {
814
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
815
+			foreach ($package['rates'] as $key => $rate) {
816 816
 				// Loop through user chosen shipping methods.
817
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
818
-					if ( $method === $key ) {
819
-						$order->add_shipping( $rate );
817
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
818
+					if ($method === $key) {
819
+						$order->add_shipping($rate);
820 820
 					}
821 821
 				}
822 822
 			}
823 823
 		}
824 824
 
825 825
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
826
-		$order->set_payment_method( $available_gateways['stripe'] );
827
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
828
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
829
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
830
-		$order->set_total( WC()->cart->tax_total, 'tax' );
831
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
832
-		$order->set_total( WC()->cart->total );
826
+		$order->set_payment_method($available_gateways['stripe']);
827
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
828
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
829
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
830
+		$order->set_total(WC()->cart->tax_total, 'tax');
831
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
832
+		$order->set_total(WC()->cart->total);
833 833
 
834 834
 		// If we got here, the order was created without problems!
835
-		wc_transaction_query( 'commit' );
835
+		wc_transaction_query('commit');
836 836
 
837 837
 		return $order;
838 838
 	}
Please login to merge, or discard this patch.