Completed
Push — master ( 1097c7...2c7ec5 )
by Roy
02:23
created
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +260 added lines, -260 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,51 +67,51 @@  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 3.0. 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_apple_pay_clear_cart', array( $this, 'clear_cart' ) );
95
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) );
96
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
97
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
98
-		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_apple_pay_clear_cart', array($this, 'clear_cart'));
95
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single'));
96
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
97
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
98
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
99 99
 	}
100 100
 
101 101
 	/**
102 102
 	 * Filters the gateway title to reflect Apple Pay.
103 103
 	 *
104 104
 	 */
105
-	public function filter_gateway_title( $title, $id ) {
105
+	public function filter_gateway_title($title, $id) {
106 106
 		global $post;
107 107
 
108
-		if ( ! is_object( $post ) ) {
108
+		if ( ! is_object($post)) {
109 109
 			return $title;
110 110
 		}
111 111
 
112
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
112
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
113 113
 
114
-		if ( 'stripe' === $id && ! empty( $method_title ) ) {
114
+		if ('stripe' === $id && ! empty($method_title)) {
115 115
 			return $method_title;
116 116
 		}
117 117
 
@@ -125,44 +125,44 @@  discard block
 block discarded – undo
125 125
 	 * @version 3.1.4
126 126
 	 */
127 127
 	public function single_scripts() {
128
-		if ( ! is_single() ) {
128
+		if ( ! is_single()) {
129 129
 			return;
130 130
 		}
131 131
 
132 132
 		global $post;
133 133
 
134
-		$product = wc_get_product( $post->ID );
134
+		$product = wc_get_product($post->ID);
135 135
 
136
-		if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
136
+		if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
137 137
 			return;
138 138
 		}
139 139
 
140
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
140
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
141 141
 
142
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
142
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
143 143
 
144
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
145
-		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 );
144
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
145
+		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);
146 146
 
147 147
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
148 148
 
149 149
 		$stripe_params = array(
150 150
 			'key'                                           => $publishable_key,
151 151
 			'currency_code'                                 => get_woocommerce_currency(),
152
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
152
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
153 153
 			'label'                                         => $this->statement_descriptor,
154
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
155
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
156
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
157
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
158
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
154
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
155
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
156
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
157
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
158
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
159 159
 			'needs_shipping'                                => $product->needs_shipping() ? 'yes' : 'no',
160 160
 			'i18n'                                          => array(
161
-				'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ),
161
+				'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'),
162 162
 			),
163 163
 		);
164 164
 
165
-		wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) );
165
+		wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params));
166 166
 	}
167 167
 
168 168
 	/**
@@ -172,34 +172,34 @@  discard block
 block discarded – undo
172 172
 	 * @version 3.1.0
173 173
 	 */
174 174
 	public function cart_scripts() {
175
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
175
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
176 176
 			return;
177 177
 		}
178 178
 
179
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
179
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
180 180
 
181
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
181
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
182 182
 
183
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
184
-		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 );
183
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
184
+		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);
185 185
 
186 186
 		$publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key'];
187 187
 
188 188
 		$stripe_params = array(
189 189
 			'key'                                           => $publishable_key,
190 190
 			'currency_code'                                 => get_woocommerce_currency(),
191
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
191
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
192 192
 			'label'                                         => $this->statement_descriptor,
193
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
194
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
195
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
196
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
197
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
193
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
194
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
195
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
196
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
197
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
198 198
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
199 199
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
200 200
 		);
201 201
 
202
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
202
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
203 203
 	}
204 204
 
205 205
 	/**
@@ -228,26 +228,26 @@  discard block
 block discarded – undo
228 228
 		 */
229 229
 		if (
230 230
 			'yes' !== $this->_gateway_settings['apple_pay']
231
-			|| ! isset( $gateways['stripe'] )
231
+			|| ! isset($gateways['stripe'])
232 232
 		) {
233 233
 			return;
234 234
 		}
235 235
 
236
-		if ( is_single() ) {
236
+		if (is_single()) {
237 237
 			global $post;
238 238
 
239
-			$product = wc_get_product( $post->ID );
239
+			$product = wc_get_product($post->ID);
240 240
 
241
-			if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
241
+			if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
242 242
 				return;
243 243
 			}
244 244
 		}
245 245
 
246
-		$apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black';
247
-		$button_lang      = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en';
246
+		$apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black';
247
+		$button_lang      = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en';
248 248
 		?>
249 249
 		<div class="apple-pay-button-wrapper">
250
-			<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>
250
+			<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>
251 251
 		</div>
252 252
 		<?php
253 253
 	}
@@ -267,22 +267,22 @@  discard block
 block discarded – undo
267 267
 		 */
268 268
 		if (
269 269
 			'yes' !== $this->_gateway_settings['apple_pay']
270
-			|| ! isset( $gateways['stripe'] )
270
+			|| ! isset($gateways['stripe'])
271 271
 		) {
272 272
 			return;
273 273
 		}
274 274
 
275
-		if ( is_single() ) {
275
+		if (is_single()) {
276 276
 			global $post;
277 277
 
278
-			$product = wc_get_product( $post->ID );
278
+			$product = wc_get_product($post->ID);
279 279
 
280
-			if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
280
+			if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
281 281
 				return;
282 282
 			}
283 283
 		}
284 284
 		?>
285
-		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p>
285
+		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p>
286 286
 		<?php
287 287
 	}
288 288
 
@@ -293,51 +293,51 @@  discard block
 block discarded – undo
293 293
 	 * @version 3.1.0
294 294
 	 */
295 295
 	public function generate_apple_pay_single() {
296
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
297
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
296
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
297
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
298 298
 		}
299 299
 
300
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
301
-			define( 'WOOCOMMERCE_CART', true );
300
+		if ( ! defined('WOOCOMMERCE_CART')) {
301
+			define('WOOCOMMERCE_CART', true);
302 302
 		}
303 303
 
304 304
 		WC()->shipping->reset_shipping();
305 305
 
306 306
 		global $post;
307 307
 
308
-		$product = wc_get_product( $post->ID );
309
-		$qty     = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
308
+		$product = wc_get_product($post->ID);
309
+		$qty     = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
310 310
 
311 311
 		/**
312 312
 		 * If this page is single product page, we need to simulate
313 313
 		 * adding the product to the cart taken account if it is a
314 314
 		 * simple or variable product.
315 315
 		 */
316
-		if ( is_single() ) {
316
+		if (is_single()) {
317 317
 			// First empty the cart to prevent wrong calculation.
318 318
 			WC()->cart->empty_cart();
319 319
 
320
-			if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
321
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
320
+			if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
321
+				$attributes = array_map('wc_clean', $_POST['attributes']);
322 322
 
323
-				if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
324
-					$variation_id = $product->get_matching_variation( $attributes );
323
+				if (version_compare(WC_VERSION, '3.0.0', '<')) {
324
+					$variation_id = $product->get_matching_variation($attributes);
325 325
 				} else {
326
-					$data_store = WC_Data_Store::load( 'product' );
327
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
326
+					$data_store = WC_Data_Store::load('product');
327
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
328 328
 				}
329 329
 
330
-				WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
330
+				WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
331 331
 			}
332 332
 
333
-			if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
334
-				WC()->cart->add_to_cart( $product->get_id(), $qty );
333
+			if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) {
334
+				WC()->cart->add_to_cart($product->get_id(), $qty);
335 335
 			}
336 336
 		}
337 337
 
338 338
 		WC()->cart->calculate_totals();
339 339
 
340
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
340
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
341 341
 	}
342 342
 
343 343
 	/**
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
 	 * @version 3.1.0
348 348
 	 */
349 349
 	public function generate_apple_pay_cart() {
350
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
351
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
350
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
351
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
352 352
 		}
353 353
 
354
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
354
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
355 355
 	}
356 356
 
357 357
 	/**
@@ -372,29 +372,29 @@  discard block
 block discarded – undo
372 372
 	 * @version 3.1.0
373 373
 	 * @param array $address
374 374
 	 */
375
-	public function calculate_shipping( $address = array() ) {
376
-		$country  = strtoupper( $address['countryCode'] );
377
-		$state    = strtoupper( $address['administrativeArea'] );
375
+	public function calculate_shipping($address = array()) {
376
+		$country  = strtoupper($address['countryCode']);
377
+		$state    = strtoupper($address['administrativeArea']);
378 378
 		$postcode = $address['postalCode'];
379 379
 		$city     = $address['locality'];
380 380
 
381 381
 		WC()->shipping->reset_shipping();
382 382
 
383
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
384
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
385
-		} elseif ( $postcode ) {
386
-			$postcode = wc_format_postcode( $postcode, $country );
383
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
384
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
385
+		} elseif ($postcode) {
386
+			$postcode = wc_format_postcode($postcode, $country);
387 387
 		}
388 388
 
389
-		if ( $country ) {
390
-			WC()->customer->set_location( $country, $state, $postcode, $city );
391
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
389
+		if ($country) {
390
+			WC()->customer->set_location($country, $state, $postcode, $city);
391
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
392 392
 		} else {
393 393
 			WC()->customer->set_to_base();
394 394
 			WC()->customer->set_shipping_to_base();
395 395
 		}
396 396
 
397
-		WC()->customer->calculated_shipping( true );
397
+		WC()->customer->calculated_shipping(true);
398 398
 
399 399
 		/**
400 400
 		 * Set the shipping package.
@@ -416,17 +416,17 @@  discard block
 block discarded – undo
416 416
 		$packages[0]['destination']['postcode']  = $postcode;
417 417
 		$packages[0]['destination']['city']      = $city;
418 418
 
419
-		foreach ( WC()->cart->get_cart() as $item ) {
420
-			if ( $item['data']->needs_shipping() ) {
421
-				if ( isset( $item['line_total'] ) ) {
419
+		foreach (WC()->cart->get_cart() as $item) {
420
+			if ($item['data']->needs_shipping()) {
421
+				if (isset($item['line_total'])) {
422 422
 					$packages[0]['contents_cost'] += $item['line_total'];
423 423
 				}
424 424
 			}
425 425
 		}
426 426
 
427
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
427
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
428 428
 
429
-		WC()->shipping->calculate_shipping( $packages );
429
+		WC()->shipping->calculate_shipping($packages);
430 430
 	}
431 431
 
432 432
 	/**
@@ -436,18 +436,18 @@  discard block
 block discarded – undo
436 436
 	 * @version 3.1.0
437 437
 	 */
438 438
 	public function get_shipping_methods() {
439
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
440
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
439
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
440
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
441 441
 		}
442 442
 
443
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
444
-			define( 'WOOCOMMERCE_CART', true );
443
+		if ( ! defined('WOOCOMMERCE_CART')) {
444
+			define('WOOCOMMERCE_CART', true);
445 445
 		}
446 446
 
447 447
 		try {
448
-			$address = array_map( 'wc_clean', $_POST['address'] );
448
+			$address = array_map('wc_clean', $_POST['address']);
449 449
 
450
-			$this->calculate_shipping( $address );
450
+			$this->calculate_shipping($address);
451 451
 
452 452
 			// Set the shipping options.
453 453
 			$currency = get_woocommerce_currency();
@@ -455,13 +455,13 @@  discard block
 block discarded – undo
455 455
 
456 456
 			$packages = WC()->shipping->get_packages();
457 457
 
458
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
459
-				foreach ( $packages as $package_key => $package ) {
460
-					if ( empty( $package['rates'] ) ) {
461
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
458
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
459
+				foreach ($packages as $package_key => $package) {
460
+					if (empty($package['rates'])) {
461
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
462 462
 					}
463 463
 
464
-					foreach ( $package['rates'] as $key => $rate ) {
464
+					foreach ($package['rates'] as $key => $rate) {
465 465
 						$data[] = array(
466 466
 							'id'       => $rate->id,
467 467
 							'label'    => $rate->label,
@@ -475,16 +475,16 @@  discard block
 block discarded – undo
475 475
 				}
476 476
 
477 477
 				// Auto select the first shipping method.
478
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
478
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
479 479
 
480 480
 				WC()->cart->calculate_totals();
481 481
 
482
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
482
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
483 483
 			} else {
484
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
484
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
485 485
 			}
486
-		} catch ( Exception $e ) {
487
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
486
+		} catch (Exception $e) {
487
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
488 488
 		}
489 489
 	}
490 490
 
@@ -495,29 +495,29 @@  discard block
 block discarded – undo
495 495
 	 * @version 3.1.0
496 496
 	 */
497 497
 	public function update_shipping_method() {
498
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
499
-			define( 'WOOCOMMERCE_CART', true );
498
+		if ( ! defined('WOOCOMMERCE_CART')) {
499
+			define('WOOCOMMERCE_CART', true);
500 500
 		}
501 501
 
502
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
503
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
502
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
503
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
504 504
 		}
505 505
 
506
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
506
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
507 507
 
508
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
508
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
509 509
 
510 510
 		WC()->cart->calculate_totals();
511 511
 
512 512
 		// Send back the new cart total.
513 513
 		$currency  = get_woocommerce_currency();
514
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
514
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
515 515
 		$data      = array(
516 516
 			'total' => WC()->cart->total,
517 517
 		);
518 518
 
519 519
 		// Include fees and taxes as displayItems.
520
-		foreach ( WC()->cart->fees as $key => $fee ) {
520
+		foreach (WC()->cart->fees as $key => $fee) {
521 521
 			$data['items'][] = array(
522 522
 				'label'  => $fee->name,
523 523
 				'amount' => array(
@@ -526,9 +526,9 @@  discard block
 block discarded – undo
526 526
 				),
527 527
 			);
528 528
 		}
529
-		if ( 0 < $tax_total ) {
529
+		if (0 < $tax_total) {
530 530
 			$data['items'][] = array(
531
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
531
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
532 532
 				'amount' => array(
533 533
 					'currency' => $currency,
534 534
 					'value'    => $tax_total,
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 			);
537 537
 		}
538 538
 
539
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
539
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
540 540
 	}
541 541
 
542 542
 	/**
@@ -547,37 +547,37 @@  discard block
 block discarded – undo
547 547
 	 * @version 3.1.0
548 548
 	 */
549 549
 	public function process_apple_pay() {
550
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
551
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
550
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
551
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
552 552
 		}
553 553
 
554 554
 		try {
555
-			$result = array_map( 'wc_clean', $_POST['result'] );
555
+			$result = array_map('wc_clean', $_POST['result']);
556 556
 
557
-			$order = $this->create_order( $result );
557
+			$order = $this->create_order($result);
558 558
 
559
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
559
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
560 560
 
561 561
 			// Handle payment.
562
-			if ( $order->get_total() > 0 ) {
562
+			if ($order->get_total() > 0) {
563 563
 
564
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
565
-					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 ) ) );
564
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
565
+					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)));
566 566
 				}
567 567
 
568
-				WC_Stripe::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" );
568
+				WC_Stripe::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}");
569 569
 
570 570
 				// Make the request.
571
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
571
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
572 572
 
573
-				if ( is_wp_error( $response ) ) {
573
+				if (is_wp_error($response)) {
574 574
 					$localized_messages = $this->get_localized_messages();
575 575
 
576
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
576
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
577 577
 				}
578 578
 
579 579
 				// Process valid response.
580
-				$this->process_response( $response, $order );
580
+				$this->process_response($response, $order);
581 581
 			} else {
582 582
 				$order->payment_complete();
583 583
 			}
@@ -585,24 +585,24 @@  discard block
 block discarded – undo
585 585
 			// Remove cart.
586 586
 			WC()->cart->empty_cart();
587 587
 
588
-			update_post_meta( $order_id, '_customer_user', get_current_user_id() );
589
-			update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
588
+			update_post_meta($order_id, '_customer_user', get_current_user_id());
589
+			update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
590 590
 
591 591
 			// Return thank you page redirect.
592
-			wp_send_json( array(
592
+			wp_send_json(array(
593 593
 				'success'  => 'true',
594
-				'redirect' => $this->get_return_url( $order ),
595
-			) );
594
+				'redirect' => $this->get_return_url($order),
595
+			));
596 596
 
597
-		} catch ( Exception $e ) {
598
-			WC()->session->set( 'refresh_totals', true );
599
-			WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
597
+		} catch (Exception $e) {
598
+			WC()->session->set('refresh_totals', true);
599
+			WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
600 600
 
601
-			if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
602
-				$this->send_failed_order_email( $order_id );
601
+			if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) {
602
+				$this->send_failed_order_email($order_id);
603 603
 			}
604 604
 
605
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
605
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
606 606
 		}
607 607
 	}
608 608
 
@@ -612,16 +612,16 @@  discard block
 block discarded – undo
612 612
 	 * @param string $source token
613 613
 	 * @return array()
614 614
 	 */
615
-	protected function generate_payment_request( $order, $source ) {
615
+	protected function generate_payment_request($order, $source) {
616 616
 		$post_data                = array();
617
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
618
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
619
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
617
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
618
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
619
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
620 620
 		$post_data['capture']     = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false';
621 621
 
622
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
622
+		$billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
623 623
 
624
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
624
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
625 625
 			$post_data['receipt_email'] = $billing_email;
626 626
 		}
627 627
 
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 		 * @param WC_Order $order
637 637
 		 * @param object $source
638 638
 		 */
639
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
639
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
640 640
 	}
641 641
 
642 642
 	/**
@@ -645,14 +645,14 @@  discard block
 block discarded – undo
645 645
 	 * @since 3.1.0
646 646
 	 * @version 3.1.0
647 647
 	 */
648
-	public function build_shipping_methods( $shipping_methods ) {
649
-		if ( empty( $shipping_methods ) ) {
648
+	public function build_shipping_methods($shipping_methods) {
649
+		if (empty($shipping_methods)) {
650 650
 			return array();
651 651
 		}
652 652
 
653 653
 		$shipping = array();
654 654
 
655
-		foreach ( $shipping_methods as $method ) {
655
+		foreach ($shipping_methods as $method) {
656 656
 			$shipping[] = array(
657 657
 				'label'      => $method['label'],
658 658
 				'detail'     => '',
@@ -671,65 +671,65 @@  discard block
 block discarded – undo
671 671
 	 * @version 3.1.0
672 672
 	 */
673 673
 	public function build_line_items() {
674
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
675
-			define( 'WOOCOMMERCE_CART', true );
674
+		if ( ! defined('WOOCOMMERCE_CART')) {
675
+			define('WOOCOMMERCE_CART', true);
676 676
 		}
677 677
 
678
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
678
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
679 679
 		
680 680
 		$items    = array();
681 681
 		$subtotal = 0;
682 682
 
683
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
684
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
685
-			$subtotal       += $values['line_subtotal'];
683
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
684
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
685
+			$subtotal += $values['line_subtotal'];
686 686
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
687 687
 
688 688
 			$item = array(
689 689
 				'type'   => 'final',
690 690
 				'label'  => $values['data']->post->post_title . $quantity_label,
691
-				'amount' => wc_format_decimal( $amount, $decimals ),
691
+				'amount' => wc_format_decimal($amount, $decimals),
692 692
 			);
693 693
 
694 694
 			$items[] = $item;
695 695
 		}
696 696
 
697 697
 		// Default show only subtotal instead of itemization.
698
-		if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) {
698
+		if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) {
699 699
 			$items = array();
700 700
 			$items[] = array(
701 701
 				'type'   => 'final',
702
-				'label'  => __( 'Sub-Total', 'woocommerce-gateway-stripe' ),
703
-				'amount' => wc_format_decimal( $subtotal, $decimals ),
702
+				'label'  => __('Sub-Total', 'woocommerce-gateway-stripe'),
703
+				'amount' => wc_format_decimal($subtotal, $decimals),
704 704
 			);
705 705
 		}
706 706
 
707
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
708
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
709
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
710
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
711
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
707
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
708
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
709
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
710
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
711
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
712 712
 
713
-		if ( wc_tax_enabled() ) {
713
+		if (wc_tax_enabled()) {
714 714
 			$items[] = array(
715 715
 				'type'   => 'final',
716
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
716
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
717 717
 				'amount' => $tax,
718 718
 			);
719 719
 		}
720 720
 
721
-		if ( WC()->cart->needs_shipping() ) {
721
+		if (WC()->cart->needs_shipping()) {
722 722
 			$items[] = array(
723 723
 				'type'   => 'final',
724
-				'label'  => __( 'Shipping', 'woocommerce-gateway-stripe' ),
724
+				'label'  => __('Shipping', 'woocommerce-gateway-stripe'),
725 725
 				'amount' => $shipping,
726 726
 			);
727 727
 		}
728 728
 
729
-		if ( WC()->cart->has_discount() ) {
729
+		if (WC()->cart->has_discount()) {
730 730
 			$items[] = array(
731 731
 				'type'   => 'final',
732
-				'label'  => __( 'Discount', 'woocommerce-gateway-stripe' ),
732
+				'label'  => __('Discount', 'woocommerce-gateway-stripe'),
733 733
 				'amount' => '-' . $discounts,
734 734
 			);
735 735
 		}
@@ -745,24 +745,24 @@  discard block
 block discarded – undo
745 745
 	 * @param array $data
746 746
 	 * @return object $order
747 747
 	 */
748
-	public function create_order( $data = array() ) {
749
-		if ( empty( $data ) ) {
750
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
748
+	public function create_order($data = array()) {
749
+		if (empty($data)) {
750
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
751 751
 		}
752 752
 
753 753
 		$order = wc_create_order();
754
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
754
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
755 755
 
756
-		if ( is_wp_error( $order ) ) {
757
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
758
-		} elseif ( false === $order ) {
759
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
756
+		if (is_wp_error($order)) {
757
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
758
+		} elseif (false === $order) {
759
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
760 760
 		} else {
761
-			do_action( 'woocommerce_new_order', $order_id );
761
+			do_action('woocommerce_new_order', $order_id);
762 762
 		}
763 763
 
764 764
 		// Store the line items to the new/resumed order
765
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
765
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
766 766
 			$item_id = $order->add_product(
767 767
 				$values['data'],
768 768
 				$values['quantity'],
@@ -778,25 +778,25 @@  discard block
 block discarded – undo
778 778
 				)
779 779
 			);
780 780
 
781
-			if ( ! $item_id ) {
782
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
781
+			if ( ! $item_id) {
782
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
783 783
 			}
784 784
 
785 785
 			// Allow plugins to add order item meta
786
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
787
-				do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
786
+			if (version_compare(WC_VERSION, '3.0', '<')) {
787
+				do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
788 788
 			} else {
789
-				do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() );
789
+				do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id());
790 790
 			}
791 791
 		}
792 792
 
793 793
 		// Store fees
794
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
795
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
796
-				$item_id = $order->add_fee( $fee );
794
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
795
+			if (version_compare(WC_VERSION, '3.0', '<')) {
796
+				$item_id = $order->add_fee($fee);
797 797
 			} else {
798 798
 				$item = new WC_Order_Item_Fee();
799
-				$item->set_props( array(
799
+				$item->set_props(array(
800 800
 					'name'      => $fee->name,
801 801
 					'tax_class' => $fee->taxable ? $fee->tax_class : 0,
802 802
 					'total'     => $fee->amount,
@@ -805,79 +805,79 @@  discard block
 block discarded – undo
805 805
 						'total' => $fee->tax_data,
806 806
 					),
807 807
 					'order_id'  => $order->get_id(),
808
-				) );
808
+				));
809 809
 				$item_id = $item->save();
810
-				$order->add_item( $item );
810
+				$order->add_item($item);
811 811
 			}
812 812
 
813
-			if ( ! $item_id ) {
814
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
813
+			if ( ! $item_id) {
814
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
815 815
 			}
816 816
 
817 817
 			// Allow plugins to add order item meta to fees
818
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
819
-				do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
818
+			if (version_compare(WC_VERSION, '3.0', '<')) {
819
+				do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
820 820
 			} else {
821
-				do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() );
821
+				do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id());
822 822
 			}
823 823
 		}
824 824
 
825 825
 		// Store tax rows
826
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
827
-			$tax_amount = WC()->cart->get_tax_amount( $tax_rate_id );
828
-			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id );
826
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
827
+			$tax_amount = WC()->cart->get_tax_amount($tax_rate_id);
828
+			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id);
829 829
 
830
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
831
-				$item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount );
830
+			if (version_compare(WC_VERSION, '3.0', '<')) {
831
+				$item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount);
832 832
 			} else {
833 833
 				$item = new WC_Order_Item_Tax();
834
-				$item->set_props( array(
834
+				$item->set_props(array(
835 835
 					'rate_id'            => $tax_rate_id,
836 836
 					'tax_total'          => $tax_amount,
837 837
 					'shipping_tax_total' => $shipping_tax_amount,
838
-				) );
839
-				$item->set_rate( $tax_rate_id );
840
-				$item->set_order_id( $order->get_id() );
838
+				));
839
+				$item->set_rate($tax_rate_id);
840
+				$item->set_order_id($order->get_id());
841 841
 				$item_id = $item->save();
842
-				$order->add_item( $item );
842
+				$order->add_item($item);
843 843
 			}
844 844
 
845
-			if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
846
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
845
+			if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
846
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
847 847
 			}
848 848
 		}
849 849
 
850 850
 		// Store coupons
851
-		$discount = WC()->cart->get_coupon_discount_amount( $code );
852
-		$discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code );
851
+		$discount = WC()->cart->get_coupon_discount_amount($code);
852
+		$discount_tax = WC()->cart->get_coupon_discount_tax_amount($code);
853 853
 
854
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
855
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
856
-				$coupon_id = $order->add_coupon( $code, $discount, $discount_tax );
854
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
855
+			if (version_compare(WC_VERSION, '3.0', '<')) {
856
+				$coupon_id = $order->add_coupon($code, $discount, $discount_tax);
857 857
 			} else {
858 858
 				$item = new WC_Order_Item_Coupon();
859
-				$item->set_props( array(
859
+				$item->set_props(array(
860 860
 					'code'         => $code,
861 861
 					'discount'     => $discount,
862 862
 					'discount_tax' => $discount_tax,
863 863
 					'order_id'     => $order->get_id(),
864
-				) );
864
+				));
865 865
 				$coupon_id = $item->save();
866
-				$order->add_item( $item );
866
+				$order->add_item($item);
867 867
 			}
868 868
 
869
-			if ( ! $coupon_id ) {
870
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
869
+			if ( ! $coupon_id) {
870
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
871 871
 			}
872 872
 		}
873 873
 
874 874
 		// Billing address
875 875
 		$billing_address = array();
876
-		if ( ! empty( $data['token']['card'] ) ) {
876
+		if ( ! empty($data['token']['card'])) {
877 877
 			// Name from Stripe is a full name string.
878
-			$name                          = explode( ' ', $data['token']['card']['name'] );
879
-			$lastname                      = array_pop( $name );
880
-			$firstname                     = implode( ' ', $name );
878
+			$name                          = explode(' ', $data['token']['card']['name']);
879
+			$lastname                      = array_pop($name);
880
+			$firstname                     = implode(' ', $name);
881 881
 			$billing_address['first_name'] = $firstname;
882 882
 			$billing_address['last_name']  = $lastname;
883 883
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
 
893 893
 		// Shipping address.
894 894
 		$shipping_address = array();
895
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
895
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
896 896
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
897 897
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
898 898
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
 			$shipping_address['city']       = $data['shippingContact']['locality'];
904 904
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
905 905
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
906
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
906
+		} elseif ( ! empty($data['shippingContact'])) {
907 907
 			$shipping_address['first_name'] = $firstname;
908 908
 			$shipping_address['last_name']  = $lastname;
909 909
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -916,33 +916,33 @@  discard block
 block discarded – undo
916 916
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
917 917
 		}
918 918
 
919
-		$order->set_address( $billing_address, 'billing' );
920
-		$order->set_address( $shipping_address, 'shipping' );
919
+		$order->set_address($billing_address, 'billing');
920
+		$order->set_address($shipping_address, 'shipping');
921 921
 
922
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
922
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
923 923
 
924 924
 		// Get the rate object selected by user.
925
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
926
-			foreach ( $package['rates'] as $key => $rate ) {
925
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
926
+			foreach ($package['rates'] as $key => $rate) {
927 927
 				// Loop through user chosen shipping methods.
928
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
929
-					if ( $method === $key ) {
930
-						if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
931
-							$order->add_shipping( $rate );
928
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
929
+					if ($method === $key) {
930
+						if (version_compare(WC_VERSION, '3.0', '<')) {
931
+							$order->add_shipping($rate);
932 932
 						} else {
933 933
 							$item = new WC_Order_Item_Shipping();
934
-							$item->set_props( array(
934
+							$item->set_props(array(
935 935
 								'method_title' => $rate->label,
936 936
 								'method_id'    => $rate->id,
937
-								'total'        => wc_format_decimal( $rate->cost ),
937
+								'total'        => wc_format_decimal($rate->cost),
938 938
 								'taxes'        => $rate->taxes,
939 939
 								'order_id'     => $order->get_id(),
940
-							) );
941
-							foreach ( $rate->get_meta_data() as $key => $value ) {
942
-								$item->add_meta_data( $key, $value, true );
940
+							));
941
+							foreach ($rate->get_meta_data() as $key => $value) {
942
+								$item->add_meta_data($key, $value, true);
943 943
 							}
944 944
 							$item->save();
945
-							$order->add_item( $item );
945
+							$order->add_item($item);
946 946
 						}
947 947
 					}
948 948
 				}
@@ -950,16 +950,16 @@  discard block
 block discarded – undo
950 950
 		}
951 951
 
952 952
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
953
-		$order->set_payment_method( $available_gateways['stripe'] );
954
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
955
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
956
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
957
-		$order->set_total( WC()->cart->tax_total, 'tax' );
958
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
959
-		$order->set_total( WC()->cart->total );
953
+		$order->set_payment_method($available_gateways['stripe']);
954
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
955
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
956
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
957
+		$order->set_total(WC()->cart->tax_total, 'tax');
958
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
959
+		$order->set_total(WC()->cart->total);
960 960
 
961 961
 		// If we got here, the order was created without problems!
962
-		wc_transaction_query( 'commit' );
962
+		wc_transaction_query('commit');
963 963
 
964 964
 		return $order;
965 965
 	}
Please login to merge, or discard this patch.