Completed
Push — master ( 77a32c...6a3485 )
by Roy
02:40
created
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +224 added lines, -224 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
 	}
@@ -67,50 +67,50 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	public function init() {
69 69
 		// If Apple Pay is not enabled no need to proceed further.
70
-		if ( 'yes' !== $this->_gateway_settings['apple_pay'] ) {
70
+		if ('yes' !== $this->_gateway_settings['apple_pay']) {
71 71
 			return;
72 72
 		}
73 73
 
74
-		add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) );
75
-		add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) );
74
+		add_action('wp_enqueue_scripts', array($this, 'cart_scripts'));
75
+		add_action('wp_enqueue_scripts', array($this, 'single_scripts'));
76 76
 
77 77
 		/**
78 78
 		 * In order to display the Apple Pay button in the correct position,
79 79
 		 * a new hook was added to WooCommerce 2.7. In older versions of WooCommerce,
80 80
 		 * CSS is used to position the button.
81 81
 		 */
82
-		if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
83
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 );
82
+		if (version_compare(WC_VERSION, '3.0.0', '<')) {
83
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1);
84 84
 		} else {
85
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 );
86
-		}
87
-
88
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 );
89
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 );
90
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 );
91
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 );
92
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
93
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
94
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) );
95
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
96
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
97
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
85
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1);
86
+		}
87
+
88
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1);
89
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2);
90
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1);
91
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2);
92
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
93
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
94
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single'));
95
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
96
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
97
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
98 98
 	}
99 99
 
100 100
 	/**
101 101
 	 * Filters the gateway title to reflect Apple Pay.
102 102
 	 *
103 103
 	 */
104
-	public function filter_gateway_title( $title, $id ) {
104
+	public function filter_gateway_title($title, $id) {
105 105
 		global $post;
106 106
 
107
-		if ( ! is_object( $post ) ) {
107
+		if ( ! is_object($post)) {
108 108
 			return $title;
109 109
 		}
110 110
 
111
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
111
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
112 112
 
113
-		if ( 'stripe' === $id && ! empty( $method_title ) ) {
113
+		if ('stripe' === $id && ! empty($method_title)) {
114 114
 			return $method_title;
115 115
 		}
116 116
 
@@ -124,41 +124,41 @@  discard block
 block discarded – undo
124 124
 	 * @version 3.1.0
125 125
 	 */
126 126
 	public function single_scripts() {
127
-		if ( ! is_single() ) {
127
+		if ( ! is_single()) {
128 128
 			return;
129 129
 		}
130 130
 
131 131
 		global $post;
132 132
 
133
-		$product = wc_get_product( $post->ID );
133
+		$product = wc_get_product($post->ID);
134 134
 
135
-		if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
135
+		if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
136 136
 			return;
137 137
 		}
138 138
 
139
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
139
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
140 140
 
141
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
141
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
142 142
 
143
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
144
-		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 );
143
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
144
+		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);
145 145
 
146 146
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
147 147
 
148 148
 		$stripe_params = array(
149 149
 			'key'                                           => $publishable_key,
150 150
 			'currency_code'                                 => get_woocommerce_currency(),
151
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
151
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
152 152
 			'label'                                         => $this->statement_descriptor,
153
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
154
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
155
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
156
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
157
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
153
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
154
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
155
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
156
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
157
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
158 158
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
159 159
 		);
160 160
 
161
-		wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) );
161
+		wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params));
162 162
 	}
163 163
 
164 164
 	/**
@@ -168,34 +168,34 @@  discard block
 block discarded – undo
168 168
 	 * @version 3.1.0
169 169
 	 */
170 170
 	public function cart_scripts() {
171
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
171
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
172 172
 			return;
173 173
 		}
174 174
 
175
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
175
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
176 176
 
177
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
177
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
178 178
 
179
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
180
-		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 );
179
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
180
+		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);
181 181
 
182 182
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
183 183
 
184 184
 		$stripe_params = array(
185 185
 			'key'                                           => $publishable_key,
186 186
 			'currency_code'                                 => get_woocommerce_currency(),
187
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
187
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
188 188
 			'label'                                         => $this->statement_descriptor,
189
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
190
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
191
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
192
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
193
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
189
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
190
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
191
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
192
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
193
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
194 194
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
195 195
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
196 196
 		);
197 197
 
198
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
198
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
199 199
 	}
200 200
 
201 201
 	/**
@@ -224,26 +224,26 @@  discard block
 block discarded – undo
224 224
 		 */
225 225
 		if (
226 226
 			'yes' !== $this->_gateway_settings['apple_pay']
227
-			|| ! isset( $gateways['stripe'] )
227
+			|| ! isset($gateways['stripe'])
228 228
 		) {
229 229
 			return;
230 230
 		}
231 231
 
232
-		if ( is_single() ) {
232
+		if (is_single()) {
233 233
 			global $post;
234 234
 
235
-			$product = wc_get_product( $post->ID );
235
+			$product = wc_get_product($post->ID);
236 236
 
237
-			if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
237
+			if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
238 238
 				return;
239 239
 			}
240 240
 		}
241 241
 
242
-		$apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black';
243
-		$button_lang      = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en';
242
+		$apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black';
243
+		$button_lang      = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en';
244 244
 		?>
245 245
 		<div class="apple-pay-button-wrapper">
246
-			<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>
246
+			<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>
247 247
 		</div>
248 248
 		<?php
249 249
 	}
@@ -263,22 +263,22 @@  discard block
 block discarded – undo
263 263
 		 */
264 264
 		if (
265 265
 			'yes' !== $this->_gateway_settings['apple_pay']
266
-			|| ! isset( $gateways['stripe'] )
266
+			|| ! isset($gateways['stripe'])
267 267
 		) {
268 268
 			return;
269 269
 		}
270 270
 
271
-		if ( is_single() ) {
271
+		if (is_single()) {
272 272
 			global $post;
273 273
 
274
-			$product = wc_get_product( $post->ID );
274
+			$product = wc_get_product($post->ID);
275 275
 
276
-			if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
276
+			if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
277 277
 				return;
278 278
 			}
279 279
 		}
280 280
 		?>
281
-		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p>
281
+		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p>
282 282
 		<?php
283 283
 	}
284 284
 
@@ -289,46 +289,46 @@  discard block
 block discarded – undo
289 289
 	 * @version 3.1.0
290 290
 	 */
291 291
 	public function generate_apple_pay_single() {
292
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
293
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
292
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
293
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
294 294
 		}
295 295
 
296
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
297
-			define( 'WOOCOMMERCE_CART', true );
296
+		if ( ! defined('WOOCOMMERCE_CART')) {
297
+			define('WOOCOMMERCE_CART', true);
298 298
 		}
299 299
 
300 300
 		WC()->shipping->reset_shipping();
301 301
 
302 302
 		global $post;
303 303
 
304
-		$product = wc_get_product( $post->ID );
305
-		$qty     = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
304
+		$product = wc_get_product($post->ID);
305
+		$qty     = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
306 306
 
307 307
 		/**
308 308
 		 * If this page is single product page, we need to simulate
309 309
 		 * adding the product to the cart taken account if it is a
310 310
 		 * simple or variable product.
311 311
 		 */
312
-		if ( is_single() ) {
312
+		if (is_single()) {
313 313
 			// First empty the cart to prevent wrong calculation.
314 314
 			WC()->cart->empty_cart();
315 315
 
316
-			if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
317
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
316
+			if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
317
+				$attributes = array_map('wc_clean', $_POST['attributes']);
318 318
 
319
-				$variation_id = $product->get_matching_variation( $attributes );
319
+				$variation_id = $product->get_matching_variation($attributes);
320 320
 
321
-				WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
321
+				WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
322 322
 			}
323 323
 
324
-			if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
325
-				WC()->cart->add_to_cart( $product->get_id(), $qty );
324
+			if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) {
325
+				WC()->cart->add_to_cart($product->get_id(), $qty);
326 326
 			}
327 327
 		}
328 328
 
329 329
 		WC()->cart->calculate_totals();
330 330
 
331
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
331
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
332 332
 	}
333 333
 
334 334
 	/**
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
 	 * @version 3.1.0
339 339
 	 */
340 340
 	public function generate_apple_pay_cart() {
341
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
342
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
341
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
342
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
343 343
 		}
344 344
 
345
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
345
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
346 346
 	}
347 347
 
348 348
 	/**
@@ -352,29 +352,29 @@  discard block
 block discarded – undo
352 352
 	 * @version 3.1.0
353 353
 	 * @param array $address
354 354
 	 */
355
-	public function calculate_shipping( $address = array() ) {
356
-		$country  = strtoupper( $address['countryCode'] );
357
-		$state    = strtoupper( $address['administrativeArea'] );
355
+	public function calculate_shipping($address = array()) {
356
+		$country  = strtoupper($address['countryCode']);
357
+		$state    = strtoupper($address['administrativeArea']);
358 358
 		$postcode = $address['postalCode'];
359 359
 		$city     = $address['locality'];
360 360
 
361 361
 		WC()->shipping->reset_shipping();
362 362
 
363
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
364
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
365
-		} elseif ( $postcode ) {
366
-			$postcode = wc_format_postcode( $postcode, $country );
363
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
364
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
365
+		} elseif ($postcode) {
366
+			$postcode = wc_format_postcode($postcode, $country);
367 367
 		}
368 368
 
369
-		if ( $country ) {
370
-			WC()->customer->set_location( $country, $state, $postcode, $city );
371
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
369
+		if ($country) {
370
+			WC()->customer->set_location($country, $state, $postcode, $city);
371
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
372 372
 		} else {
373 373
 			WC()->customer->set_to_base();
374 374
 			WC()->customer->set_shipping_to_base();
375 375
 		}
376 376
 
377
-		WC()->customer->calculated_shipping( true );
377
+		WC()->customer->calculated_shipping(true);
378 378
 
379 379
 		/**
380 380
 		 * Set the shipping package.
@@ -396,17 +396,17 @@  discard block
 block discarded – undo
396 396
 		$packages[0]['destination']['postcode']  = $postcode;
397 397
 		$packages[0]['destination']['city']      = $city;
398 398
 
399
-		foreach ( WC()->cart->get_cart() as $item ) {
400
-			if ( $item['data']->needs_shipping() ) {
401
-				if ( isset( $item['line_total'] ) ) {
399
+		foreach (WC()->cart->get_cart() as $item) {
400
+			if ($item['data']->needs_shipping()) {
401
+				if (isset($item['line_total'])) {
402 402
 					$packages[0]['contents_cost'] += $item['line_total'];
403 403
 				}
404 404
 			}
405 405
 		}
406 406
 
407
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
407
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
408 408
 
409
-		WC()->shipping->calculate_shipping( $packages );
409
+		WC()->shipping->calculate_shipping($packages);
410 410
 	}
411 411
 
412 412
 	/**
@@ -416,18 +416,18 @@  discard block
 block discarded – undo
416 416
 	 * @version 3.1.0
417 417
 	 */
418 418
 	public function get_shipping_methods() {
419
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
420
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
419
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
420
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
421 421
 		}
422 422
 
423
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
424
-			define( 'WOOCOMMERCE_CART', true );
423
+		if ( ! defined('WOOCOMMERCE_CART')) {
424
+			define('WOOCOMMERCE_CART', true);
425 425
 		}
426 426
 
427 427
 		try {
428
-			$address = array_map( 'wc_clean', $_POST['address'] );
428
+			$address = array_map('wc_clean', $_POST['address']);
429 429
 
430
-			$this->calculate_shipping( $address );
430
+			$this->calculate_shipping($address);
431 431
 
432 432
 			// Set the shipping options.
433 433
 			$currency = get_woocommerce_currency();
@@ -435,13 +435,13 @@  discard block
 block discarded – undo
435 435
 
436 436
 			$packages = WC()->shipping->get_packages();
437 437
 
438
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
439
-				foreach ( $packages as $package_key => $package ) {
440
-					if ( empty( $package['rates'] ) ) {
441
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
438
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
439
+				foreach ($packages as $package_key => $package) {
440
+					if (empty($package['rates'])) {
441
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
442 442
 					}
443 443
 
444
-					foreach ( $package['rates'] as $key => $rate ) {
444
+					foreach ($package['rates'] as $key => $rate) {
445 445
 						$data[] = array(
446 446
 							'id'       => $rate->id,
447 447
 							'label'    => $rate->label,
@@ -455,16 +455,16 @@  discard block
 block discarded – undo
455 455
 				}
456 456
 
457 457
 				// Auto select the first shipping method.
458
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
458
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
459 459
 
460 460
 				WC()->cart->calculate_totals();
461 461
 
462
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
462
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
463 463
 			} else {
464
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
464
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
465 465
 			}
466
-		} catch ( Exception $e ) {
467
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
466
+		} catch (Exception $e) {
467
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
468 468
 		}
469 469
 	}
470 470
 
@@ -475,29 +475,29 @@  discard block
 block discarded – undo
475 475
 	 * @version 3.1.0
476 476
 	 */
477 477
 	public function update_shipping_method() {
478
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
479
-			define( 'WOOCOMMERCE_CART', true );
478
+		if ( ! defined('WOOCOMMERCE_CART')) {
479
+			define('WOOCOMMERCE_CART', true);
480 480
 		}
481 481
 
482
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
483
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
482
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
483
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
484 484
 		}
485 485
 
486
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
486
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
487 487
 
488
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
488
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
489 489
 
490 490
 		WC()->cart->calculate_totals();
491 491
 
492 492
 		// Send back the new cart total.
493 493
 		$currency  = get_woocommerce_currency();
494
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
494
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
495 495
 		$data      = array(
496 496
 			'total' => WC()->cart->total,
497 497
 		);
498 498
 
499 499
 		// Include fees and taxes as displayItems.
500
-		foreach ( WC()->cart->fees as $key => $fee ) {
500
+		foreach (WC()->cart->fees as $key => $fee) {
501 501
 			$data['items'][] = array(
502 502
 				'label'  => $fee->name,
503 503
 				'amount' => array(
@@ -506,9 +506,9 @@  discard block
 block discarded – undo
506 506
 				),
507 507
 			);
508 508
 		}
509
-		if ( 0 < $tax_total ) {
509
+		if (0 < $tax_total) {
510 510
 			$data['items'][] = array(
511
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
511
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
512 512
 				'amount' => array(
513 513
 					'currency' => $currency,
514 514
 					'value'    => $tax_total,
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 			);
517 517
 		}
518 518
 
519
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
519
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
520 520
 	}
521 521
 
522 522
 	/**
@@ -527,37 +527,37 @@  discard block
 block discarded – undo
527 527
 	 * @version 3.1.0
528 528
 	 */
529 529
 	public function process_apple_pay() {
530
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
531
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
530
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
531
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
532 532
 		}
533 533
 
534 534
 		try {
535
-			$result = array_map( 'wc_clean', $_POST['result'] );
535
+			$result = array_map('wc_clean', $_POST['result']);
536 536
 
537
-			$order = $this->create_order( $result );
537
+			$order = $this->create_order($result);
538 538
 
539
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
539
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
540 540
 
541 541
 			// Handle payment.
542
-			if ( $order->get_total() > 0 ) {
542
+			if ($order->get_total() > 0) {
543 543
 
544
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
545
-					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 ) ) );
544
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
545
+					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)));
546 546
 				}
547 547
 
548
-				WC_Stripe::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" );
548
+				WC_Stripe::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}");
549 549
 
550 550
 				// Make the request.
551
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
551
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
552 552
 
553
-				if ( is_wp_error( $response ) ) {
553
+				if (is_wp_error($response)) {
554 554
 					$localized_messages = $this->get_localized_messages();
555 555
 
556
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
556
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
557 557
 				}
558 558
 
559 559
 				// Process valid response.
560
-				$this->process_response( $response, $order );
560
+				$this->process_response($response, $order);
561 561
 			} else {
562 562
 				$order->payment_complete();
563 563
 			}
@@ -565,24 +565,24 @@  discard block
 block discarded – undo
565 565
 			// Remove cart.
566 566
 			WC()->cart->empty_cart();
567 567
 
568
-			update_post_meta( $order_id, '_customer_user', get_current_user_id() );
569
-			update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
568
+			update_post_meta($order_id, '_customer_user', get_current_user_id());
569
+			update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
570 570
 
571 571
 			// Return thank you page redirect.
572
-			wp_send_json( array(
572
+			wp_send_json(array(
573 573
 				'success'  => 'true',
574
-				'redirect' => $this->get_return_url( $order ),
575
-			) );
574
+				'redirect' => $this->get_return_url($order),
575
+			));
576 576
 
577
-		} catch ( Exception $e ) {
578
-			WC()->session->set( 'refresh_totals', true );
579
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
577
+		} catch (Exception $e) {
578
+			WC()->session->set('refresh_totals', true);
579
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
580 580
 
581
-			if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
582
-				$this->send_failed_order_email( $order_id );
581
+			if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) {
582
+				$this->send_failed_order_email($order_id);
583 583
 			}
584 584
 
585
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
585
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
586 586
 		}
587 587
 	}
588 588
 
@@ -592,16 +592,16 @@  discard block
 block discarded – undo
592 592
 	 * @param string $source token
593 593
 	 * @return array()
594 594
 	 */
595
-	protected function generate_payment_request( $order, $source ) {
595
+	protected function generate_payment_request($order, $source) {
596 596
 		$post_data                = array();
597
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
598
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
599
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
597
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
598
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
599
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
600 600
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
601 601
 
602
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
602
+		$billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
603 603
 
604
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
604
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
605 605
 			$post_data['receipt_email'] = $billing_email;
606 606
 		}
607 607
 
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 		 * @param WC_Order $order
617 617
 		 * @param object $source
618 618
 		 */
619
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
619
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
620 620
 	}
621 621
 
622 622
 	/**
@@ -625,14 +625,14 @@  discard block
 block discarded – undo
625 625
 	 * @since 3.1.0
626 626
 	 * @version 3.1.0
627 627
 	 */
628
-	public function build_shipping_methods( $shipping_methods ) {
629
-		if ( empty( $shipping_methods ) ) {
628
+	public function build_shipping_methods($shipping_methods) {
629
+		if (empty($shipping_methods)) {
630 630
 			return array();
631 631
 		}
632 632
 
633 633
 		$shipping = array();
634 634
 
635
-		foreach ( $shipping_methods as $method ) {
635
+		foreach ($shipping_methods as $method) {
636 636
 			$shipping[] = array(
637 637
 				'label'      => $method['label'],
638 638
 				'detail'     => '',
@@ -651,65 +651,65 @@  discard block
 block discarded – undo
651 651
 	 * @version 3.1.0
652 652
 	 */
653 653
 	public function build_line_items() {
654
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
655
-			define( 'WOOCOMMERCE_CART', true );
654
+		if ( ! defined('WOOCOMMERCE_CART')) {
655
+			define('WOOCOMMERCE_CART', true);
656 656
 		}
657 657
 
658
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
658
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
659 659
 		
660 660
 		$items    = array();
661 661
 		$subtotal = 0;
662 662
 
663
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
664
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
665
-			$subtotal       += $values['line_subtotal'];
663
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
664
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
665
+			$subtotal += $values['line_subtotal'];
666 666
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
667 667
 
668 668
 			$item = array(
669 669
 				'type'   => 'final',
670 670
 				'label'  => $values['data']->post->post_title . $quantity_label,
671
-				'amount' => wc_format_decimal( $amount, $decimals ),
671
+				'amount' => wc_format_decimal($amount, $decimals),
672 672
 			);
673 673
 
674 674
 			$items[] = $item;
675 675
 		}
676 676
 
677 677
 		// Default show only subtotal instead of itemization.
678
-		if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) {
678
+		if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) {
679 679
 			$items = array();
680 680
 			$items[] = array(
681 681
 				'type'   => 'final',
682
-				'label'  => __( 'Sub-Total', 'woocommerce-gateway-stripe' ),
683
-				'amount' => wc_format_decimal( $subtotal, $decimals ),
682
+				'label'  => __('Sub-Total', 'woocommerce-gateway-stripe'),
683
+				'amount' => wc_format_decimal($subtotal, $decimals),
684 684
 			);
685 685
 		}
686 686
 
687
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
688
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
689
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
690
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
691
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
687
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
688
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
689
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
690
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
691
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
692 692
 
693
-		if ( wc_tax_enabled() ) {
693
+		if (wc_tax_enabled()) {
694 694
 			$items[] = array(
695 695
 				'type'   => 'final',
696
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
696
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
697 697
 				'amount' => $tax,
698 698
 			);
699 699
 		}
700 700
 
701
-		if ( WC()->cart->needs_shipping() ) {
701
+		if (WC()->cart->needs_shipping()) {
702 702
 			$items[] = array(
703 703
 				'type'   => 'final',
704
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
704
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
705 705
 				'amount' => $shipping,
706 706
 			);
707 707
 		}
708 708
 
709
-		if ( WC()->cart->has_discount() ) {
709
+		if (WC()->cart->has_discount()) {
710 710
 			$items[] = array(
711 711
 				'type'   => 'final',
712
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
712
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
713 713
 				'amount' => '-' . $discounts,
714 714
 			);
715 715
 		}
@@ -725,24 +725,24 @@  discard block
 block discarded – undo
725 725
 	 * @param array $data
726 726
 	 * @return object $order
727 727
 	 */
728
-	public function create_order( $data = array() ) {
729
-		if ( empty( $data ) ) {
730
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
728
+	public function create_order($data = array()) {
729
+		if (empty($data)) {
730
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
731 731
 		}
732 732
 
733 733
 		$order = wc_create_order();
734
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
734
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
735 735
 
736
-		if ( is_wp_error( $order ) ) {
737
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
738
-		} elseif ( false === $order ) {
739
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
736
+		if (is_wp_error($order)) {
737
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
738
+		} elseif (false === $order) {
739
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
740 740
 		} else {
741
-			do_action( 'woocommerce_new_order', $order_id );
741
+			do_action('woocommerce_new_order', $order_id);
742 742
 		}
743 743
 
744 744
 		// Store the line items to the new/resumed order
745
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
745
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
746 746
 			$item_id = $order->add_product(
747 747
 				$values['data'],
748 748
 				$values['quantity'],
@@ -758,47 +758,47 @@  discard block
 block discarded – undo
758 758
 				)
759 759
 			);
760 760
 
761
-			if ( ! $item_id ) {
762
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
761
+			if ( ! $item_id) {
762
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
763 763
 			}
764 764
 
765 765
 			// Allow plugins to add order item meta
766
-			do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
766
+			do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
767 767
 		}
768 768
 
769 769
 		// Store fees
770
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
771
-			$item_id = $order->add_fee( $fee );
770
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
771
+			$item_id = $order->add_fee($fee);
772 772
 
773
-			if ( ! $item_id ) {
774
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
773
+			if ( ! $item_id) {
774
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
775 775
 			}
776 776
 
777 777
 			// Allow plugins to add order item meta to fees
778
-			do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
778
+			do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
779 779
 		}
780 780
 
781 781
 		// Store tax rows
782
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
783
-			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 ) {
784
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
782
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
783
+			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) {
784
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
785 785
 			}
786 786
 		}
787 787
 
788 788
 		// Store coupons
789
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
790
-			if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
791
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
789
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
790
+			if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) {
791
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
792 792
 			}
793 793
 		}
794 794
 
795 795
 		// Billing address
796 796
 		$billing_address = array();
797
-		if ( ! empty( $data['token']['card'] ) ) {
797
+		if ( ! empty($data['token']['card'])) {
798 798
 			// Name from Stripe is a full name string.
799
-			$name                          = explode( ' ', $data['token']['card']['name'] );
800
-			$lastname                      = array_pop( $name );
801
-			$firstname                     = implode( ' ', $name );
799
+			$name                          = explode(' ', $data['token']['card']['name']);
800
+			$lastname                      = array_pop($name);
801
+			$firstname                     = implode(' ', $name);
802 802
 			$billing_address['first_name'] = $firstname;
803 803
 			$billing_address['last_name']  = $lastname;
804 804
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
 
814 814
 		// Shipping address.
815 815
 		$shipping_address = array();
816
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
816
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
817 817
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
818 818
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
819 819
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			$shipping_address['city']       = $data['shippingContact']['locality'];
825 825
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
826 826
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
827
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
827
+		} elseif ( ! empty($data['shippingContact'])) {
828 828
 			$shipping_address['first_name'] = $firstname;
829 829
 			$shipping_address['last_name']  = $lastname;
830 830
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -837,34 +837,34 @@  discard block
 block discarded – undo
837 837
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
838 838
 		}
839 839
 
840
-		$order->set_address( $billing_address, 'billing' );
841
-		$order->set_address( $shipping_address, 'shipping' );
840
+		$order->set_address($billing_address, 'billing');
841
+		$order->set_address($shipping_address, 'shipping');
842 842
 
843
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
843
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
844 844
 
845 845
 		// Get the rate object selected by user.
846
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
847
-			foreach ( $package['rates'] as $key => $rate ) {
846
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
847
+			foreach ($package['rates'] as $key => $rate) {
848 848
 				// Loop through user chosen shipping methods.
849
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
850
-					if ( $method === $key ) {
851
-						$order->add_shipping( $rate );
849
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
850
+					if ($method === $key) {
851
+						$order->add_shipping($rate);
852 852
 					}
853 853
 				}
854 854
 			}
855 855
 		}
856 856
 
857 857
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
858
-		$order->set_payment_method( $available_gateways['stripe'] );
859
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
860
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
861
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
862
-		$order->set_total( WC()->cart->tax_total, 'tax' );
863
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
864
-		$order->set_total( WC()->cart->total );
858
+		$order->set_payment_method($available_gateways['stripe']);
859
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
860
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
861
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
862
+		$order->set_total(WC()->cart->tax_total, 'tax');
863
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
864
+		$order->set_total(WC()->cart->total);
865 865
 
866 866
 		// If we got here, the order was created without problems!
867
-		wc_transaction_query( 'commit' );
867
+		wc_transaction_query('commit');
868 868
 
869 869
 		return $order;
870 870
 	}
Please login to merge, or discard this patch.