Completed
Push — master ( 7e00cc...919814 )
by Roy
02:32
created
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +287 added lines, -287 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
 
@@ -89,27 +89,27 @@  discard block
 block discarded – undo
89 89
 	public function __construct() {
90 90
 		self::$_this = $this;
91 91
 
92
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
92
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
93 93
 
94
-		$this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
94
+		$this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
95 95
 
96 96
 		// If both site title and statement descriptor is not set. Fallback.
97
-		if ( empty( $this->statement_descriptor ) ) {
97
+		if (empty($this->statement_descriptor)) {
98 98
 			$this->statement_descriptor = $_SERVER['SERVER_NAME'];
99 99
 		}
100 100
 
101
-		$this->enabled               = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false;
102
-		$this->testmode              = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false;
103
-		$this->capture               = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false;
104
-		$this->saved_cards           = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false;
105
-		$this->apple_pay             = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false;
106
-		$this->apple_pay_button      = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black';
107
-		$this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en';
108
-		$this->logging               = ( ! empty( $gateway_settings['logging'] ) && 'yes' === $gateway_settings['logging'] ) ? true : false;
109
-		$this->publishable_key       = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : '';
110
-
111
-		if ( $this->testmode ) {
112
-			$this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : '';
101
+		$this->enabled               = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false;
102
+		$this->testmode              = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false;
103
+		$this->capture               = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false;
104
+		$this->saved_cards           = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false;
105
+		$this->apple_pay             = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false;
106
+		$this->apple_pay_button      = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black';
107
+		$this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en';
108
+		$this->logging               = ( ! empty($gateway_settings['logging']) && 'yes' === $gateway_settings['logging']) ? true : false;
109
+		$this->publishable_key       = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : '';
110
+
111
+		if ($this->testmode) {
112
+			$this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : '';
113 113
 		}
114 114
 
115 115
 		$this->init();
@@ -128,53 +128,53 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	public function init() {
130 130
 		// If Apple Pay is not enabled no need to proceed further.
131
-		if ( ! $this->apple_pay ) {
131
+		if ( ! $this->apple_pay) {
132 132
 			return;
133 133
 		}
134 134
 
135
-		add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) );
136
-		add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) );
135
+		add_action('wp_enqueue_scripts', array($this, 'cart_scripts'));
136
+		add_action('wp_enqueue_scripts', array($this, 'single_scripts'));
137 137
 
138 138
 		/**
139 139
 		 * In order to display the Apple Pay button in the correct position,
140 140
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
141 141
 		 * CSS is used to position the button.
142 142
 		 */
143
-		if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
144
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 );
143
+		if (version_compare(WC_VERSION, '3.0.0', '<')) {
144
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1);
145 145
 		} else {
146
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 );
146
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1);
147 147
 		}
148 148
 
149
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 );
150
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 );
151
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 );
152
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 );
153
-		add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) );
154
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
155
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
156
-		add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) );
157
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) );
158
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
159
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
160
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
161
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
149
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1);
150
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2);
151
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1);
152
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2);
153
+		add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors'));
154
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
155
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
156
+		add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart'));
157
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single'));
158
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
159
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
160
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
161
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
162 162
 	}
163 163
 
164 164
 	/**
165 165
 	 * Filters the gateway title to reflect Apple Pay.
166 166
 	 *
167 167
 	 */
168
-	public function filter_gateway_title( $title, $id ) {
168
+	public function filter_gateway_title($title, $id) {
169 169
 		global $post;
170 170
 
171
-		if ( ! is_object( $post ) ) {
171
+		if ( ! is_object($post)) {
172 172
 			return $title;
173 173
 		}
174 174
 
175
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
175
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
176 176
 
177
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
177
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
178 178
 			return $method_title;
179 179
 		}
180 180
 
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
 	 * @version 3.1.4
189 189
 	 */
190 190
 	public function log_apple_pay_errors() {
191
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
192
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
191
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
192
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
193 193
 		}
194 194
 
195
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
195
+		$errors = wc_clean(stripslashes($_POST['errors']));
196 196
 
197
-		$this->log( $errors );
197
+		$this->log($errors);
198 198
 
199 199
 		exit;
200 200
 	}
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
 	 * @since 3.1.4
206 206
 	 * @version 3.1.4
207 207
 	 */
208
-	public function postal_code_validation( $valid, $postcode, $country ) {
208
+	public function postal_code_validation($valid, $postcode, $country) {
209 209
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
210 210
 
211
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
211
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
212 212
 			return $valid;
213 213
 		}
214 214
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 		 * when passing it back from the shippingcontactselected object. This causes WC to invalidate
218 218
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
219 219
 		 */
220
-		if ( 'GB' === $country || 'CA' === $country ) {
220
+		if ('GB' === $country || 'CA' === $country) {
221 221
 			return true;
222 222
 		}
223 223
 
@@ -231,42 +231,42 @@  discard block
 block discarded – undo
231 231
 	 * @version 3.1.4
232 232
 	 */
233 233
 	public function single_scripts() {
234
-		if ( ! is_single() ) {
234
+		if ( ! is_single()) {
235 235
 			return;
236 236
 		}
237 237
 
238 238
 		global $post;
239 239
 
240
-		$product = wc_get_product( $post->ID );
240
+		$product = wc_get_product($post->ID);
241 241
 
242
-		if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
242
+		if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
243 243
 			return;
244 244
 		}
245 245
 
246
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
246
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
247 247
 
248
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
248
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
249 249
 
250
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
251
-		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 );
250
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
251
+		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);
252 252
 
253 253
 		$stripe_params = array(
254 254
 			'key'                                           => $this->publishable_key,
255 255
 			'currency_code'                                 => get_woocommerce_currency(),
256
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
256
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
257 257
 			'label'                                         => $this->statement_descriptor,
258
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
259
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
260
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
261
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
262
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
258
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
259
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
260
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
261
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
262
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
263 263
 			'needs_shipping'                                => $product->needs_shipping() ? 'yes' : 'no',
264 264
 			'i18n'                                          => array(
265
-				'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ),
265
+				'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'),
266 266
 			),
267 267
 		);
268 268
 
269
-		wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) );
269
+		wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params));
270 270
 	}
271 271
 
272 272
 	/**
@@ -276,32 +276,32 @@  discard block
 block discarded – undo
276 276
 	 * @version 3.1.0
277 277
 	 */
278 278
 	public function cart_scripts() {
279
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
279
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
280 280
 			return;
281 281
 		}
282 282
 
283
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
283
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
284 284
 
285
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
285
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
286 286
 
287
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
288
-		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 );
287
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
288
+		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);
289 289
 
290 290
 		$stripe_params = array(
291 291
 			'key'                                           => $this->publishable_key,
292 292
 			'currency_code'                                 => get_woocommerce_currency(),
293
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
293
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
294 294
 			'label'                                         => $this->statement_descriptor,
295
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
296
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
297
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
298
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
299
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
295
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
296
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
297
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
298
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
299
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
300 300
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
301 301
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
302 302
 		);
303 303
 
304
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
304
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
305 305
 	}
306 306
 
307 307
 	/**
@@ -327,10 +327,10 @@  discard block
 block discarded – undo
327 327
 	 * @return bool
328 328
 	 */
329 329
 	public function allowed_items_in_cart() {
330
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
331
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
330
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
331
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
332 332
 
333
-			if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
333
+			if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
334 334
 				return false;
335 335
 			}
336 336
 		}
@@ -351,29 +351,29 @@  discard block
 block discarded – undo
351 351
 		 * In order for the Apple Pay button to show on product detail page,
352 352
 		 * Apple Pay must be enabled and Stripe gateway must be enabled.
353 353
 		 */
354
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
355
-			$this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' );
354
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
355
+			$this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )');
356 356
 			return;
357 357
 		}
358 358
 
359
-		if ( is_single() ) {
359
+		if (is_single()) {
360 360
 			global $post;
361 361
 
362
-			$product = wc_get_product( $post->ID );
362
+			$product = wc_get_product($post->ID);
363 363
 
364
-			if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
364
+			if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
365 365
 				return;
366 366
 			}
367 367
 		} else {
368
-			if ( ! $this->allowed_items_in_cart() ) {
369
-				$this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' );
368
+			if ( ! $this->allowed_items_in_cart()) {
369
+				$this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )');
370 370
 				return;
371 371
 			}
372 372
 		}
373 373
 
374 374
 		?>
375 375
 		<div class="apple-pay-button-wrapper">
376
-			<button class="apple-pay-button" lang="<?php echo esc_attr( $this->apple_pay_button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $this->apple_pay_button ); ?>;"></button>
376
+			<button class="apple-pay-button" lang="<?php echo esc_attr($this->apple_pay_button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($this->apple_pay_button); ?>;"></button>
377 377
 		</div>
378 378
 		<?php
379 379
 	}
@@ -391,17 +391,17 @@  discard block
 block discarded – undo
391 391
 		 * In order for the Apple Pay button to show on cart page,
392 392
 		 * Apple Pay must be enabled and Stripe gateway must be enabled.
393 393
 		 */
394
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
395
-			$this->log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' );
394
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
395
+			$this->log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )');
396 396
 			return;
397 397
 		}
398 398
 
399
-		if ( ! $this->allowed_items_in_cart() ) {
400
-			$this->log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' );
399
+		if ( ! $this->allowed_items_in_cart()) {
400
+			$this->log('Items in the cart has unsupported product type ( Apple Pay button disabled )');
401 401
 			return;
402 402
 		}
403 403
 		?>
404
-		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p>
404
+		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p>
405 405
 		<?php
406 406
 	}
407 407
 
@@ -412,51 +412,51 @@  discard block
 block discarded – undo
412 412
 	 * @version 3.1.0
413 413
 	 */
414 414
 	public function generate_apple_pay_single() {
415
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
416
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
415
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
416
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
417 417
 		}
418 418
 
419
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
420
-			define( 'WOOCOMMERCE_CART', true );
419
+		if ( ! defined('WOOCOMMERCE_CART')) {
420
+			define('WOOCOMMERCE_CART', true);
421 421
 		}
422 422
 
423 423
 		WC()->shipping->reset_shipping();
424 424
 
425 425
 		global $post;
426 426
 
427
-		$product = wc_get_product( $post->ID );
428
-		$qty     = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
427
+		$product = wc_get_product($post->ID);
428
+		$qty     = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
429 429
 
430 430
 		/**
431 431
 		 * If this page is single product page, we need to simulate
432 432
 		 * adding the product to the cart taken account if it is a
433 433
 		 * simple or variable product.
434 434
 		 */
435
-		if ( is_single() ) {
435
+		if (is_single()) {
436 436
 			// First empty the cart to prevent wrong calculation.
437 437
 			WC()->cart->empty_cart();
438 438
 
439
-			if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
440
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
439
+			if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
440
+				$attributes = array_map('wc_clean', $_POST['attributes']);
441 441
 
442
-				if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
443
-					$variation_id = $product->get_matching_variation( $attributes );
442
+				if (version_compare(WC_VERSION, '3.0.0', '<')) {
443
+					$variation_id = $product->get_matching_variation($attributes);
444 444
 				} else {
445
-					$data_store = WC_Data_Store::load( 'product' );
446
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
445
+					$data_store = WC_Data_Store::load('product');
446
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
447 447
 				}
448 448
 
449
-				WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
449
+				WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
450 450
 			}
451 451
 
452
-			if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
453
-				WC()->cart->add_to_cart( $product->get_id(), $qty );
452
+			if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) {
453
+				WC()->cart->add_to_cart($product->get_id(), $qty);
454 454
 			}
455 455
 		}
456 456
 
457 457
 		WC()->cart->calculate_totals();
458 458
 
459
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
459
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
460 460
 	}
461 461
 
462 462
 	/**
@@ -466,11 +466,11 @@  discard block
 block discarded – undo
466 466
 	 * @version 3.1.0
467 467
 	 */
468 468
 	public function generate_apple_pay_cart() {
469
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
470
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
469
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
470
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
471 471
 		}
472 472
 
473
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
473
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
474 474
 	}
475 475
 
476 476
 	/**
@@ -491,29 +491,29 @@  discard block
 block discarded – undo
491 491
 	 * @version 3.1.0
492 492
 	 * @param array $address
493 493
 	 */
494
-	public function calculate_shipping( $address = array() ) {
495
-		$country  = strtoupper( $address['countryCode'] );
496
-		$state    = strtoupper( $address['administrativeArea'] );
494
+	public function calculate_shipping($address = array()) {
495
+		$country  = strtoupper($address['countryCode']);
496
+		$state    = strtoupper($address['administrativeArea']);
497 497
 		$postcode = $address['postalCode'];
498 498
 		$city     = $address['locality'];
499 499
 
500 500
 		WC()->shipping->reset_shipping();
501 501
 
502
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
503
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
504
-		} elseif ( $postcode ) {
505
-			$postcode = wc_format_postcode( $postcode, $country );
502
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
503
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
504
+		} elseif ($postcode) {
505
+			$postcode = wc_format_postcode($postcode, $country);
506 506
 		}
507 507
 
508
-		if ( $country ) {
509
-			WC()->customer->set_location( $country, $state, $postcode, $city );
510
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
508
+		if ($country) {
509
+			WC()->customer->set_location($country, $state, $postcode, $city);
510
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
511 511
 		} else {
512 512
 			WC()->customer->set_to_base();
513 513
 			WC()->customer->set_shipping_to_base();
514 514
 		}
515 515
 
516
-		WC()->customer->calculated_shipping( true );
516
+		WC()->customer->calculated_shipping(true);
517 517
 
518 518
 		/**
519 519
 		 * Set the shipping package.
@@ -535,17 +535,17 @@  discard block
 block discarded – undo
535 535
 		$packages[0]['destination']['postcode']  = $postcode;
536 536
 		$packages[0]['destination']['city']      = $city;
537 537
 
538
-		foreach ( WC()->cart->get_cart() as $item ) {
539
-			if ( $item['data']->needs_shipping() ) {
540
-				if ( isset( $item['line_total'] ) ) {
538
+		foreach (WC()->cart->get_cart() as $item) {
539
+			if ($item['data']->needs_shipping()) {
540
+				if (isset($item['line_total'])) {
541 541
 					$packages[0]['contents_cost'] += $item['line_total'];
542 542
 				}
543 543
 			}
544 544
 		}
545 545
 
546
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
546
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
547 547
 
548
-		WC()->shipping->calculate_shipping( $packages );
548
+		WC()->shipping->calculate_shipping($packages);
549 549
 	}
550 550
 
551 551
 	/**
@@ -555,18 +555,18 @@  discard block
 block discarded – undo
555 555
 	 * @version 3.1.0
556 556
 	 */
557 557
 	public function get_shipping_methods() {
558
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
559
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
558
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
559
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
560 560
 		}
561 561
 
562
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
563
-			define( 'WOOCOMMERCE_CART', true );
562
+		if ( ! defined('WOOCOMMERCE_CART')) {
563
+			define('WOOCOMMERCE_CART', true);
564 564
 		}
565 565
 
566 566
 		try {
567
-			$address = array_map( 'wc_clean', $_POST['address'] );
567
+			$address = array_map('wc_clean', $_POST['address']);
568 568
 
569
-			$this->calculate_shipping( $address );
569
+			$this->calculate_shipping($address);
570 570
 
571 571
 			// Set the shipping options.
572 572
 			$currency = get_woocommerce_currency();
@@ -574,13 +574,13 @@  discard block
 block discarded – undo
574 574
 
575 575
 			$packages = WC()->shipping->get_packages();
576 576
 
577
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
578
-				foreach ( $packages as $package_key => $package ) {
579
-					if ( empty( $package['rates'] ) ) {
580
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
577
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
578
+				foreach ($packages as $package_key => $package) {
579
+					if (empty($package['rates'])) {
580
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
581 581
 					}
582 582
 
583
-					foreach ( $package['rates'] as $key => $rate ) {
583
+					foreach ($package['rates'] as $key => $rate) {
584 584
 						$data[] = array(
585 585
 							'id'       => $rate->id,
586 586
 							'label'    => $rate->label,
@@ -594,16 +594,16 @@  discard block
 block discarded – undo
594 594
 				}
595 595
 
596 596
 				// Auto select the first shipping method.
597
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
597
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
598 598
 
599 599
 				WC()->cart->calculate_totals();
600 600
 
601
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
601
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
602 602
 			} else {
603
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
603
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
604 604
 			}
605
-		} catch ( Exception $e ) {
606
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
605
+		} catch (Exception $e) {
606
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
607 607
 		}
608 608
 	}
609 609
 
@@ -614,29 +614,29 @@  discard block
 block discarded – undo
614 614
 	 * @version 3.1.0
615 615
 	 */
616 616
 	public function update_shipping_method() {
617
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
618
-			define( 'WOOCOMMERCE_CART', true );
617
+		if ( ! defined('WOOCOMMERCE_CART')) {
618
+			define('WOOCOMMERCE_CART', true);
619 619
 		}
620 620
 
621
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
622
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
621
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
622
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
623 623
 		}
624 624
 
625
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
625
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
626 626
 
627
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
627
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
628 628
 
629 629
 		WC()->cart->calculate_totals();
630 630
 
631 631
 		// Send back the new cart total.
632 632
 		$currency  = get_woocommerce_currency();
633
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
633
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
634 634
 		$data      = array(
635 635
 			'total' => WC()->cart->total,
636 636
 		);
637 637
 
638 638
 		// Include fees and taxes as displayItems.
639
-		foreach ( WC()->cart->fees as $key => $fee ) {
639
+		foreach (WC()->cart->fees as $key => $fee) {
640 640
 			$data['items'][] = array(
641 641
 				'label'  => $fee->name,
642 642
 				'amount' => array(
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
 				),
646 646
 			);
647 647
 		}
648
-		if ( 0 < $tax_total ) {
648
+		if (0 < $tax_total) {
649 649
 			$data['items'][] = array(
650
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
650
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
651 651
 				'amount' => array(
652 652
 					'currency' => $currency,
653 653
 					'value'    => $tax_total,
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 			);
656 656
 		}
657 657
 
658
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
658
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
659 659
 	}
660 660
 
661 661
 	/**
@@ -666,37 +666,37 @@  discard block
 block discarded – undo
666 666
 	 * @version 3.1.0
667 667
 	 */
668 668
 	public function process_apple_pay() {
669
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
670
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
669
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
670
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
671 671
 		}
672 672
 
673 673
 		try {
674
-			$result = array_map( 'wc_clean', $_POST['result'] );
674
+			$result = array_map('wc_clean', $_POST['result']);
675 675
 
676
-			$order = $this->create_order( $result );
676
+			$order = $this->create_order($result);
677 677
 
678
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
678
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
679 679
 
680 680
 			// Handle payment.
681
-			if ( $order->get_total() > 0 ) {
681
+			if ($order->get_total() > 0) {
682 682
 
683
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
684
-					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 ) ) );
683
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
684
+					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)));
685 685
 				}
686 686
 
687
-				$this->log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" );
687
+				$this->log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}");
688 688
 
689 689
 				// Make the request.
690
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
690
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
691 691
 
692
-				if ( is_wp_error( $response ) ) {
692
+				if (is_wp_error($response)) {
693 693
 					$localized_messages = $this->get_localized_messages();
694 694
 
695
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
695
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
696 696
 				}
697 697
 
698 698
 				// Process valid response.
699
-				$this->process_response( $response, $order );
699
+				$this->process_response($response, $order);
700 700
 			} else {
701 701
 				$order->payment_complete();
702 702
 			}
@@ -704,24 +704,24 @@  discard block
 block discarded – undo
704 704
 			// Remove cart.
705 705
 			WC()->cart->empty_cart();
706 706
 
707
-			update_post_meta( $order_id, '_customer_user', get_current_user_id() );
708
-			update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
707
+			update_post_meta($order_id, '_customer_user', get_current_user_id());
708
+			update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
709 709
 
710 710
 			// Return thank you page redirect.
711
-			wp_send_json( array(
711
+			wp_send_json(array(
712 712
 				'success'  => 'true',
713
-				'redirect' => $this->get_return_url( $order ),
714
-			) );
713
+				'redirect' => $this->get_return_url($order),
714
+			));
715 715
 
716
-		} catch ( Exception $e ) {
717
-			WC()->session->set( 'refresh_totals', true );
718
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
716
+		} catch (Exception $e) {
717
+			WC()->session->set('refresh_totals', true);
718
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
719 719
 
720
-			if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
721
-				$this->send_failed_order_email( $order_id );
720
+			if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) {
721
+				$this->send_failed_order_email($order_id);
722 722
 			}
723 723
 
724
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
724
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
725 725
 		}
726 726
 	}
727 727
 
@@ -731,16 +731,16 @@  discard block
 block discarded – undo
731 731
 	 * @param string $source token
732 732
 	 * @return array()
733 733
 	 */
734
-	protected function generate_payment_request( $order, $source ) {
734
+	protected function generate_payment_request($order, $source) {
735 735
 		$post_data                = array();
736
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
737
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
738
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
736
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
737
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
738
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
739 739
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
740 740
 
741
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
741
+		$billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
742 742
 
743
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
743
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
744 744
 			$post_data['receipt_email'] = $billing_email;
745 745
 		}
746 746
 
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 		 * @param WC_Order $order
756 756
 		 * @param object $source
757 757
 		 */
758
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
758
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
759 759
 	}
760 760
 
761 761
 	/**
@@ -764,14 +764,14 @@  discard block
 block discarded – undo
764 764
 	 * @since 3.1.0
765 765
 	 * @version 3.1.0
766 766
 	 */
767
-	public function build_shipping_methods( $shipping_methods ) {
768
-		if ( empty( $shipping_methods ) ) {
767
+	public function build_shipping_methods($shipping_methods) {
768
+		if (empty($shipping_methods)) {
769 769
 			return array();
770 770
 		}
771 771
 
772 772
 		$shipping = array();
773 773
 
774
-		foreach ( $shipping_methods as $method ) {
774
+		foreach ($shipping_methods as $method) {
775 775
 			$shipping[] = array(
776 776
 				'label'      => $method['label'],
777 777
 				'detail'     => '',
@@ -790,65 +790,65 @@  discard block
 block discarded – undo
790 790
 	 * @version 3.1.0
791 791
 	 */
792 792
 	public function build_line_items() {
793
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
794
-			define( 'WOOCOMMERCE_CART', true );
793
+		if ( ! defined('WOOCOMMERCE_CART')) {
794
+			define('WOOCOMMERCE_CART', true);
795 795
 		}
796 796
 
797
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
797
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
798 798
 		
799 799
 		$items    = array();
800 800
 		$subtotal = 0;
801 801
 
802
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
803
-			$amount         = wc_format_decimal( $cart_item['line_subtotal'], $decimals );
804
-			$subtotal       += $cart_item['line_subtotal'];
802
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
803
+			$amount         = wc_format_decimal($cart_item['line_subtotal'], $decimals);
804
+			$subtotal += $cart_item['line_subtotal'];
805 805
 			$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
806 806
 
807 807
 			$item = array(
808 808
 				'type'   => 'final',
809 809
 				'label'  => $cart_item['data']->post->post_title . $quantity_label,
810
-				'amount' => wc_format_decimal( $amount, $decimals ),
810
+				'amount' => wc_format_decimal($amount, $decimals),
811 811
 			);
812 812
 
813 813
 			$items[] = $item;
814 814
 		}
815 815
 
816 816
 		// Default show only subtotal instead of itemization.
817
-		if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) {
817
+		if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) {
818 818
 			$items = array();
819 819
 			$items[] = array(
820 820
 				'type'   => 'final',
821
-				'label'  => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ),
822
-				'amount' => wc_format_decimal( $subtotal, $decimals ),
821
+				'label'  => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')),
822
+				'amount' => wc_format_decimal($subtotal, $decimals),
823 823
 			);
824 824
 		}
825 825
 
826
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
827
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
828
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
829
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
830
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
826
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
827
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
828
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
829
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
830
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
831 831
 
832
-		if ( wc_tax_enabled() ) {
832
+		if (wc_tax_enabled()) {
833 833
 			$items[] = array(
834 834
 				'type'   => 'final',
835
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
835
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
836 836
 				'amount' => $tax,
837 837
 			);
838 838
 		}
839 839
 
840
-		if ( WC()->cart->needs_shipping() ) {
840
+		if (WC()->cart->needs_shipping()) {
841 841
 			$items[] = array(
842 842
 				'type'   => 'final',
843
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
843
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
844 844
 				'amount' => $shipping,
845 845
 			);
846 846
 		}
847 847
 
848
-		if ( WC()->cart->has_discount() ) {
848
+		if (WC()->cart->has_discount()) {
849 849
 			$items[] = array(
850 850
 				'type'   => 'final',
851
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
851
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
852 852
 				'amount' => '-' . $discounts,
853 853
 			);
854 854
 		}
@@ -864,24 +864,24 @@  discard block
 block discarded – undo
864 864
 	 * @param array $data
865 865
 	 * @return object $order
866 866
 	 */
867
-	public function create_order( $data = array() ) {
868
-		if ( empty( $data ) ) {
869
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
867
+	public function create_order($data = array()) {
868
+		if (empty($data)) {
869
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
870 870
 		}
871 871
 
872 872
 		$order = wc_create_order();
873
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
873
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
874 874
 
875
-		if ( is_wp_error( $order ) ) {
876
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
877
-		} elseif ( false === $order ) {
878
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
875
+		if (is_wp_error($order)) {
876
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
877
+		} elseif (false === $order) {
878
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
879 879
 		} else {
880
-			do_action( 'woocommerce_new_order', $order_id );
880
+			do_action('woocommerce_new_order', $order_id);
881 881
 		}
882 882
 
883 883
 		// Store the line items to the new/resumed order
884
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
884
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
885 885
 			$item_id = $order->add_product(
886 886
 				$values['data'],
887 887
 				$values['quantity'],
@@ -897,25 +897,25 @@  discard block
 block discarded – undo
897 897
 				)
898 898
 			);
899 899
 
900
-			if ( ! $item_id ) {
901
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
900
+			if ( ! $item_id) {
901
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
902 902
 			}
903 903
 
904 904
 			// Allow plugins to add order item meta
905
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
906
-				do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
905
+			if (version_compare(WC_VERSION, '3.0', '<')) {
906
+				do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
907 907
 			} else {
908
-				do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() );
908
+				do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id());
909 909
 			}
910 910
 		}
911 911
 
912 912
 		// Store fees
913
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
914
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
915
-				$item_id = $order->add_fee( $fee );
913
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
914
+			if (version_compare(WC_VERSION, '3.0', '<')) {
915
+				$item_id = $order->add_fee($fee);
916 916
 			} else {
917 917
 				$item = new WC_Order_Item_Fee();
918
-				$item->set_props( array(
918
+				$item->set_props(array(
919 919
 					'name'      => $fee->name,
920 920
 					'tax_class' => $fee->taxable ? $fee->tax_class : 0,
921 921
 					'total'     => $fee->amount,
@@ -924,79 +924,79 @@  discard block
 block discarded – undo
924 924
 						'total' => $fee->tax_data,
925 925
 					),
926 926
 					'order_id'  => $order->get_id(),
927
-				) );
927
+				));
928 928
 				$item_id = $item->save();
929
-				$order->add_item( $item );
929
+				$order->add_item($item);
930 930
 			}
931 931
 
932
-			if ( ! $item_id ) {
933
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) );
932
+			if ( ! $item_id) {
933
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
934 934
 			}
935 935
 
936 936
 			// Allow plugins to add order item meta to fees
937
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
938
-				do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
937
+			if (version_compare(WC_VERSION, '3.0', '<')) {
938
+				do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
939 939
 			} else {
940
-				do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() );
940
+				do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id());
941 941
 			}
942 942
 		}
943 943
 
944 944
 		// Store tax rows
945
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
946
-			$tax_amount = WC()->cart->get_tax_amount( $tax_rate_id );
947
-			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id );
945
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
946
+			$tax_amount = WC()->cart->get_tax_amount($tax_rate_id);
947
+			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id);
948 948
 
949
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
950
-				$item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount );
949
+			if (version_compare(WC_VERSION, '3.0', '<')) {
950
+				$item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount);
951 951
 			} else {
952 952
 				$item = new WC_Order_Item_Tax();
953
-				$item->set_props( array(
953
+				$item->set_props(array(
954 954
 					'rate_id'            => $tax_rate_id,
955 955
 					'tax_total'          => $tax_amount,
956 956
 					'shipping_tax_total' => $shipping_tax_amount,
957
-				) );
958
-				$item->set_rate( $tax_rate_id );
959
-				$item->set_order_id( $order->get_id() );
957
+				));
958
+				$item->set_rate($tax_rate_id);
959
+				$item->set_order_id($order->get_id());
960 960
 				$item_id = $item->save();
961
-				$order->add_item( $item );
961
+				$order->add_item($item);
962 962
 			}
963 963
 
964
-			if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
965
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
964
+			if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
965
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
966 966
 			}
967 967
 		}
968 968
 
969 969
 		// Store coupons
970
-		$discount = WC()->cart->get_coupon_discount_amount( $code );
971
-		$discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code );
970
+		$discount = WC()->cart->get_coupon_discount_amount($code);
971
+		$discount_tax = WC()->cart->get_coupon_discount_tax_amount($code);
972 972
 
973
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
974
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
975
-				$coupon_id = $order->add_coupon( $code, $discount, $discount_tax );
973
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
974
+			if (version_compare(WC_VERSION, '3.0', '<')) {
975
+				$coupon_id = $order->add_coupon($code, $discount, $discount_tax);
976 976
 			} else {
977 977
 				$item = new WC_Order_Item_Coupon();
978
-				$item->set_props( array(
978
+				$item->set_props(array(
979 979
 					'code'         => $code,
980 980
 					'discount'     => $discount,
981 981
 					'discount_tax' => $discount_tax,
982 982
 					'order_id'     => $order->get_id(),
983
-				) );
983
+				));
984 984
 				$coupon_id = $item->save();
985
-				$order->add_item( $item );
985
+				$order->add_item($item);
986 986
 			}
987 987
 
988
-			if ( ! $coupon_id ) {
989
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
988
+			if ( ! $coupon_id) {
989
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
990 990
 			}
991 991
 		}
992 992
 
993 993
 		// Billing address
994 994
 		$billing_address = array();
995
-		if ( ! empty( $data['token']['card'] ) ) {
995
+		if ( ! empty($data['token']['card'])) {
996 996
 			// Name from Stripe is a full name string.
997
-			$name                          = explode( ' ', $data['token']['card']['name'] );
998
-			$lastname                      = array_pop( $name );
999
-			$firstname                     = implode( ' ', $name );
997
+			$name                          = explode(' ', $data['token']['card']['name']);
998
+			$lastname                      = array_pop($name);
999
+			$firstname                     = implode(' ', $name);
1000 1000
 			$billing_address['first_name'] = $firstname;
1001 1001
 			$billing_address['last_name']  = $lastname;
1002 1002
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
 
1012 1012
 		// Shipping address.
1013 1013
 		$shipping_address = array();
1014
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
1014
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
1015 1015
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
1016 1016
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
1017 1017
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
 			$shipping_address['city']       = $data['shippingContact']['locality'];
1023 1023
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
1024 1024
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
1025
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
1025
+		} elseif ( ! empty($data['shippingContact'])) {
1026 1026
 			$shipping_address['first_name'] = $firstname;
1027 1027
 			$shipping_address['last_name']  = $lastname;
1028 1028
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -1035,33 +1035,33 @@  discard block
 block discarded – undo
1035 1035
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
1036 1036
 		}
1037 1037
 
1038
-		$order->set_address( $billing_address, 'billing' );
1039
-		$order->set_address( $shipping_address, 'shipping' );
1038
+		$order->set_address($billing_address, 'billing');
1039
+		$order->set_address($shipping_address, 'shipping');
1040 1040
 
1041
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
1041
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
1042 1042
 
1043 1043
 		// Get the rate object selected by user.
1044
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
1045
-			foreach ( $package['rates'] as $key => $rate ) {
1044
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
1045
+			foreach ($package['rates'] as $key => $rate) {
1046 1046
 				// Loop through user chosen shipping methods.
1047
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
1048
-					if ( $method === $key ) {
1049
-						if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1050
-							$order->add_shipping( $rate );
1047
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
1048
+					if ($method === $key) {
1049
+						if (version_compare(WC_VERSION, '3.0', '<')) {
1050
+							$order->add_shipping($rate);
1051 1051
 						} else {
1052 1052
 							$item = new WC_Order_Item_Shipping();
1053
-							$item->set_props( array(
1053
+							$item->set_props(array(
1054 1054
 								'method_title' => $rate->label,
1055 1055
 								'method_id'    => $rate->id,
1056
-								'total'        => wc_format_decimal( $rate->cost ),
1056
+								'total'        => wc_format_decimal($rate->cost),
1057 1057
 								'taxes'        => $rate->taxes,
1058 1058
 								'order_id'     => $order->get_id(),
1059
-							) );
1060
-							foreach ( $rate->get_meta_data() as $key => $value ) {
1061
-								$item->add_meta_data( $key, $value, true );
1059
+							));
1060
+							foreach ($rate->get_meta_data() as $key => $value) {
1061
+								$item->add_meta_data($key, $value, true);
1062 1062
 							}
1063 1063
 							$item->save();
1064
-							$order->add_item( $item );
1064
+							$order->add_item($item);
1065 1065
 						}
1066 1066
 					}
1067 1067
 				}
@@ -1069,16 +1069,16 @@  discard block
 block discarded – undo
1069 1069
 		}
1070 1070
 
1071 1071
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
1072
-		$order->set_payment_method( $available_gateways['stripe'] );
1073
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
1074
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
1075
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
1076
-		$order->set_total( WC()->cart->tax_total, 'tax' );
1077
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
1078
-		$order->set_total( WC()->cart->total );
1072
+		$order->set_payment_method($available_gateways['stripe']);
1073
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
1074
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
1075
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
1076
+		$order->set_total(WC()->cart->tax_total, 'tax');
1077
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
1078
+		$order->set_total(WC()->cart->total);
1079 1079
 
1080 1080
 		// If we got here, the order was created without problems!
1081
-		wc_transaction_query( 'commit' );
1081
+		wc_transaction_query('commit');
1082 1082
 
1083 1083
 		return $order;
1084 1084
 	}
@@ -1091,9 +1091,9 @@  discard block
 block discarded – undo
1091 1091
 	 *
1092 1092
 	 * @param string $message
1093 1093
 	 */
1094
-	public function log( $message ) {
1095
-		if ( $this->logging ) {
1096
-			WC_Stripe::log( 'Apple Pay: ' . $message );
1094
+	public function log($message) {
1095
+		if ($this->logging) {
1096
+			WC_Stripe::log('Apple Pay: ' . $message);
1097 1097
 		}
1098 1098
 	}
1099 1099
 }
Please login to merge, or discard this patch.