Completed
Push — master ( 898bb5...80fce1 )
by Roy
03:14
created
includes/class-wc-stripe-apple-pay.php 1 patch
Spacing   +281 added lines, -281 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
 
@@ -82,27 +82,27 @@  discard block
 block discarded – undo
82 82
 	public function __construct() {
83 83
 		self::$_this = $this;
84 84
 
85
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
85
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
86 86
 
87
-		$this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
87
+		$this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
88 88
 
89 89
 		// If both site title and statement descriptor is not set. Fallback.
90
-		if ( empty( $this->statement_descriptor ) ) {
90
+		if (empty($this->statement_descriptor)) {
91 91
 			$this->statement_descriptor = $_SERVER['SERVER_NAME'];
92 92
 		}
93 93
 
94
-		$this->enabled               = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false;
95
-		$this->testmode              = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false;
96
-		$this->capture               = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false;
97
-		$this->saved_cards           = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false;
98
-		$this->apple_pay             = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false;
99
-		$this->apple_pay_button      = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black';
100
-		$this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en';
101
-		$this->logging               = ( ! empty( $gateway_settings['logging'] ) && 'yes' === $gateway_settings['logging'] ) ? true : false;
102
-		$this->publishable_key       = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : '';
103
-
104
-		if ( $this->testmode ) {
105
-			$this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : '';
94
+		$this->enabled               = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false;
95
+		$this->testmode              = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false;
96
+		$this->capture               = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false;
97
+		$this->saved_cards           = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false;
98
+		$this->apple_pay             = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false;
99
+		$this->apple_pay_button      = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black';
100
+		$this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en';
101
+		$this->logging               = ( ! empty($gateway_settings['logging']) && 'yes' === $gateway_settings['logging']) ? true : false;
102
+		$this->publishable_key       = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : '';
103
+
104
+		if ($this->testmode) {
105
+			$this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : '';
106 106
 		}
107 107
 
108 108
 		$this->init();
@@ -121,53 +121,53 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function init() {
123 123
 		// If Apple Pay is not enabled no need to proceed further.
124
-		if ( ! $this->apple_pay ) {
124
+		if ( ! $this->apple_pay) {
125 125
 			return;
126 126
 		}
127 127
 
128
-		add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) );
129
-		add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) );
128
+		add_action('wp_enqueue_scripts', array($this, 'cart_scripts'));
129
+		add_action('wp_enqueue_scripts', array($this, 'single_scripts'));
130 130
 
131 131
 		/**
132 132
 		 * In order to display the Apple Pay button in the correct position,
133 133
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
134 134
 		 * CSS is used to position the button.
135 135
 		 */
136
-		if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
137
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 );
136
+		if (version_compare(WC_VERSION, '3.0.0', '<')) {
137
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1);
138 138
 		} else {
139
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 );
139
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1);
140 140
 		}
141 141
 
142
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 );
143
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 );
144
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 );
145
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 );
146
-		add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) );
147
-		add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) );
148
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) );
149
-		add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) );
150
-		add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) );
151
-		add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) );
152
-		add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) );
153
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
154
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
142
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1);
143
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2);
144
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1);
145
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2);
146
+		add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors'));
147
+		add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay'));
148
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart'));
149
+		add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart'));
150
+		add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single'));
151
+		add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods'));
152
+		add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method'));
153
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
154
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
155 155
 	}
156 156
 
157 157
 	/**
158 158
 	 * Filters the gateway title to reflect Apple Pay.
159 159
 	 *
160 160
 	 */
161
-	public function filter_gateway_title( $title, $id ) {
161
+	public function filter_gateway_title($title, $id) {
162 162
 		global $post;
163 163
 
164
-		if ( ! is_object( $post ) ) {
164
+		if ( ! is_object($post)) {
165 165
 			return $title;
166 166
 		}
167 167
 
168
-		$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
168
+		$method_title = get_post_meta($post->ID, '_payment_method_title', true);
169 169
 
170
-		if ( 'stripe' === $id && ! empty( $method_title ) ) {
170
+		if ('stripe' === $id && ! empty($method_title)) {
171 171
 			return $method_title;
172 172
 		}
173 173
 
@@ -181,13 +181,13 @@  discard block
 block discarded – undo
181 181
 	 * @version 3.1.4
182 182
 	 */
183 183
 	public function log_apple_pay_errors() {
184
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
185
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
184
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
185
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
186 186
 		}
187 187
 
188
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
188
+		$errors = wc_clean(stripslashes($_POST['errors']));
189 189
 
190
-		$this->log( 'Apple Pay: ' . $errors );
190
+		$this->log('Apple Pay: ' . $errors);
191 191
 
192 192
 		exit;
193 193
 	}
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
 	 * @since 3.1.4
199 199
 	 * @version 3.1.4
200 200
 	 */
201
-	public function postal_code_validation( $valid, $postcode, $country ) {
201
+	public function postal_code_validation($valid, $postcode, $country) {
202 202
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
203 203
 
204
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
204
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
205 205
 			return $valid;
206 206
 		}
207 207
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		 * when passing it back from the shippingcontactselected object. This causes WC to invalidate
211 211
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
212 212
 		 */
213
-		if ( 'GB' === $country || 'CA' === $country ) {
213
+		if ('GB' === $country || 'CA' === $country) {
214 214
 			return true;
215 215
 		}
216 216
 
@@ -224,42 +224,42 @@  discard block
 block discarded – undo
224 224
 	 * @version 3.1.4
225 225
 	 */
226 226
 	public function single_scripts() {
227
-		if ( ! is_single() ) {
227
+		if ( ! is_single()) {
228 228
 			return;
229 229
 		}
230 230
 
231 231
 		global $post;
232 232
 
233
-		$product = wc_get_product( $post->ID );
233
+		$product = wc_get_product($post->ID);
234 234
 
235
-		if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
235
+		if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
236 236
 			return;
237 237
 		}
238 238
 
239
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
239
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
240 240
 
241
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
241
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
242 242
 
243
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
244
-		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 );
243
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
244
+		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);
245 245
 
246 246
 		$stripe_params = array(
247 247
 			'key'                                           => $this->publishable_key,
248 248
 			'currency_code'                                 => get_woocommerce_currency(),
249
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
249
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
250 250
 			'label'                                         => $this->statement_descriptor,
251
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
252
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
253
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
254
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
255
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
251
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
252
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
253
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
254
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
255
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
256 256
 			'needs_shipping'                                => $product->needs_shipping() ? 'yes' : 'no',
257 257
 			'i18n'                                          => array(
258
-				'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ),
258
+				'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'),
259 259
 			),
260 260
 		);
261 261
 
262
-		wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) );
262
+		wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params));
263 263
 	}
264 264
 
265 265
 	/**
@@ -269,32 +269,32 @@  discard block
 block discarded – undo
269 269
 	 * @version 3.1.0
270 270
 	 */
271 271
 	public function cart_scripts() {
272
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
272
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
273 273
 			return;
274 274
 		}
275 275
 
276
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
276
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
277 277
 
278
-		wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION );
278
+		wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION);
279 279
 
280
-		wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
281
-		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 );
280
+		wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
281
+		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);
282 282
 
283 283
 		$stripe_params = array(
284 284
 			'key'                                           => $this->publishable_key,
285 285
 			'currency_code'                                 => get_woocommerce_currency(),
286
-			'country_code'                                  => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
286
+			'country_code'                                  => substr(get_option('woocommerce_default_country'), 0, 2),
287 287
 			'label'                                         => $this->statement_descriptor,
288
-			'ajaxurl'                                       => WC_AJAX::get_endpoint( '%%endpoint%%' ),
289
-			'stripe_apple_pay_nonce'                        => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ),
290
-			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ),
291
-			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ),
292
-			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ),
288
+			'ajaxurl'                                       => WC_AJAX::get_endpoint('%%endpoint%%'),
289
+			'stripe_apple_pay_nonce'                        => wp_create_nonce('_wc_stripe_apple_pay_nonce'),
290
+			'stripe_apple_pay_cart_nonce'                   => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'),
291
+			'stripe_apple_pay_get_shipping_methods_nonce'   => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'),
292
+			'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'),
293 293
 			'needs_shipping'                                => WC()->cart->needs_shipping() ? 'yes' : 'no',
294 294
 			'is_cart_page'                                  => is_cart() ? 'yes' : 'no',
295 295
 		);
296 296
 
297
-		wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) );
297
+		wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params));
298 298
 	}
299 299
 
300 300
 	/**
@@ -321,23 +321,23 @@  discard block
 block discarded – undo
321 321
 		 * In order for the Apple Pay button to show on product detail page,
322 322
 		 * Apple Pay must be enabled and Stripe gateway must be enabled.
323 323
 		 */
324
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
324
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
325 325
 			return;
326 326
 		}
327 327
 
328
-		if ( is_single() ) {
328
+		if (is_single()) {
329 329
 			global $post;
330 330
 
331
-			$product = wc_get_product( $post->ID );
331
+			$product = wc_get_product($post->ID);
332 332
 
333
-			if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
333
+			if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
334 334
 				return;
335 335
 			}
336 336
 		}
337 337
 
338 338
 		?>
339 339
 		<div class="apple-pay-button-wrapper">
340
-			<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>
340
+			<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>
341 341
 		</div>
342 342
 		<?php
343 343
 	}
@@ -355,21 +355,21 @@  discard block
 block discarded – undo
355 355
 		 * In order for the Apple Pay button to show on cart page,
356 356
 		 * Apple Pay must be enabled and Stripe gateway must be enabled.
357 357
 		 */
358
-		if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) {
358
+		if ( ! $this->apple_pay || ! isset($gateways['stripe'])) {
359 359
 			return;
360 360
 		}
361 361
 
362
-		if ( is_single() ) {
362
+		if (is_single()) {
363 363
 			global $post;
364 364
 
365
-			$product = wc_get_product( $post->ID );
365
+			$product = wc_get_product($post->ID);
366 366
 
367
-			if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
367
+			if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
368 368
 				return;
369 369
 			}
370 370
 		}
371 371
 		?>
372
-		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p>
372
+		<p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p>
373 373
 		<?php
374 374
 	}
375 375
 
@@ -380,51 +380,51 @@  discard block
 block discarded – undo
380 380
 	 * @version 3.1.0
381 381
 	 */
382 382
 	public function generate_apple_pay_single() {
383
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
384
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
383
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
384
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
385 385
 		}
386 386
 
387
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
388
-			define( 'WOOCOMMERCE_CART', true );
387
+		if ( ! defined('WOOCOMMERCE_CART')) {
388
+			define('WOOCOMMERCE_CART', true);
389 389
 		}
390 390
 
391 391
 		WC()->shipping->reset_shipping();
392 392
 
393 393
 		global $post;
394 394
 
395
-		$product = wc_get_product( $post->ID );
396
-		$qty     = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
395
+		$product = wc_get_product($post->ID);
396
+		$qty     = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
397 397
 
398 398
 		/**
399 399
 		 * If this page is single product page, we need to simulate
400 400
 		 * adding the product to the cart taken account if it is a
401 401
 		 * simple or variable product.
402 402
 		 */
403
-		if ( is_single() ) {
403
+		if (is_single()) {
404 404
 			// First empty the cart to prevent wrong calculation.
405 405
 			WC()->cart->empty_cart();
406 406
 
407
-			if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
408
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
407
+			if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
408
+				$attributes = array_map('wc_clean', $_POST['attributes']);
409 409
 
410
-				if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) {
411
-					$variation_id = $product->get_matching_variation( $attributes );
410
+				if (version_compare(WC_VERSION, '3.0.0', '<')) {
411
+					$variation_id = $product->get_matching_variation($attributes);
412 412
 				} else {
413
-					$data_store = WC_Data_Store::load( 'product' );
414
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
413
+					$data_store = WC_Data_Store::load('product');
414
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
415 415
 				}
416 416
 
417
-				WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
417
+				WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
418 418
 			}
419 419
 
420
-			if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) {
421
-				WC()->cart->add_to_cart( $product->get_id(), $qty );
420
+			if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) {
421
+				WC()->cart->add_to_cart($product->get_id(), $qty);
422 422
 			}
423 423
 		}
424 424
 
425 425
 		WC()->cart->calculate_totals();
426 426
 
427
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
427
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
428 428
 	}
429 429
 
430 430
 	/**
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
 	 * @version 3.1.0
435 435
 	 */
436 436
 	public function generate_apple_pay_cart() {
437
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) {
438
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
437
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) {
438
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
439 439
 		}
440 440
 
441
-		wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
441
+		wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
442 442
 	}
443 443
 
444 444
 	/**
@@ -459,29 +459,29 @@  discard block
 block discarded – undo
459 459
 	 * @version 3.1.0
460 460
 	 * @param array $address
461 461
 	 */
462
-	public function calculate_shipping( $address = array() ) {
463
-		$country  = strtoupper( $address['countryCode'] );
464
-		$state    = strtoupper( $address['administrativeArea'] );
462
+	public function calculate_shipping($address = array()) {
463
+		$country  = strtoupper($address['countryCode']);
464
+		$state    = strtoupper($address['administrativeArea']);
465 465
 		$postcode = $address['postalCode'];
466 466
 		$city     = $address['locality'];
467 467
 
468 468
 		WC()->shipping->reset_shipping();
469 469
 
470
-		if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) {
471
-			throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) );
472
-		} elseif ( $postcode ) {
473
-			$postcode = wc_format_postcode( $postcode, $country );
470
+		if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) {
471
+			throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe'));
472
+		} elseif ($postcode) {
473
+			$postcode = wc_format_postcode($postcode, $country);
474 474
 		}
475 475
 
476
-		if ( $country ) {
477
-			WC()->customer->set_location( $country, $state, $postcode, $city );
478
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
476
+		if ($country) {
477
+			WC()->customer->set_location($country, $state, $postcode, $city);
478
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
479 479
 		} else {
480 480
 			WC()->customer->set_to_base();
481 481
 			WC()->customer->set_shipping_to_base();
482 482
 		}
483 483
 
484
-		WC()->customer->calculated_shipping( true );
484
+		WC()->customer->calculated_shipping(true);
485 485
 
486 486
 		/**
487 487
 		 * Set the shipping package.
@@ -503,17 +503,17 @@  discard block
 block discarded – undo
503 503
 		$packages[0]['destination']['postcode']  = $postcode;
504 504
 		$packages[0]['destination']['city']      = $city;
505 505
 
506
-		foreach ( WC()->cart->get_cart() as $item ) {
507
-			if ( $item['data']->needs_shipping() ) {
508
-				if ( isset( $item['line_total'] ) ) {
506
+		foreach (WC()->cart->get_cart() as $item) {
507
+			if ($item['data']->needs_shipping()) {
508
+				if (isset($item['line_total'])) {
509 509
 					$packages[0]['contents_cost'] += $item['line_total'];
510 510
 				}
511 511
 			}
512 512
 		}
513 513
 
514
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
514
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
515 515
 
516
-		WC()->shipping->calculate_shipping( $packages );
516
+		WC()->shipping->calculate_shipping($packages);
517 517
 	}
518 518
 
519 519
 	/**
@@ -523,18 +523,18 @@  discard block
 block discarded – undo
523 523
 	 * @version 3.1.0
524 524
 	 */
525 525
 	public function get_shipping_methods() {
526
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) {
527
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
526
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) {
527
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
528 528
 		}
529 529
 
530
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
531
-			define( 'WOOCOMMERCE_CART', true );
530
+		if ( ! defined('WOOCOMMERCE_CART')) {
531
+			define('WOOCOMMERCE_CART', true);
532 532
 		}
533 533
 
534 534
 		try {
535
-			$address = array_map( 'wc_clean', $_POST['address'] );
535
+			$address = array_map('wc_clean', $_POST['address']);
536 536
 
537
-			$this->calculate_shipping( $address );
537
+			$this->calculate_shipping($address);
538 538
 
539 539
 			// Set the shipping options.
540 540
 			$currency = get_woocommerce_currency();
@@ -542,13 +542,13 @@  discard block
 block discarded – undo
542 542
 
543 543
 			$packages = WC()->shipping->get_packages();
544 544
 
545
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
546
-				foreach ( $packages as $package_key => $package ) {
547
-					if ( empty( $package['rates'] ) ) {
548
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
545
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
546
+				foreach ($packages as $package_key => $package) {
547
+					if (empty($package['rates'])) {
548
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
549 549
 					}
550 550
 
551
-					foreach ( $package['rates'] as $key => $rate ) {
551
+					foreach ($package['rates'] as $key => $rate) {
552 552
 						$data[] = array(
553 553
 							'id'       => $rate->id,
554 554
 							'label'    => $rate->label,
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
 				}
563 563
 
564 564
 				// Auto select the first shipping method.
565
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
565
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
566 566
 
567 567
 				WC()->cart->calculate_totals();
568 568
 
569
-				wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
569
+				wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
570 570
 			} else {
571
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
571
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
572 572
 			}
573
-		} catch ( Exception $e ) {
574
-			wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
573
+		} catch (Exception $e) {
574
+			wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
575 575
 		}
576 576
 	}
577 577
 
@@ -582,29 +582,29 @@  discard block
 block discarded – undo
582 582
 	 * @version 3.1.0
583 583
 	 */
584 584
 	public function update_shipping_method() {
585
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
586
-			define( 'WOOCOMMERCE_CART', true );
585
+		if ( ! defined('WOOCOMMERCE_CART')) {
586
+			define('WOOCOMMERCE_CART', true);
587 587
 		}
588 588
 
589
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) {
590
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
589
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) {
590
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
591 591
 		}
592 592
 
593
-		$selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] );
593
+		$selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']);
594 594
 
595
-		WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) );
595
+		WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier']));
596 596
 
597 597
 		WC()->cart->calculate_totals();
598 598
 
599 599
 		// Send back the new cart total.
600 600
 		$currency  = get_woocommerce_currency();
601
-		$tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) );
601
+		$tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp));
602 602
 		$data      = array(
603 603
 			'total' => WC()->cart->total,
604 604
 		);
605 605
 
606 606
 		// Include fees and taxes as displayItems.
607
-		foreach ( WC()->cart->fees as $key => $fee ) {
607
+		foreach (WC()->cart->fees as $key => $fee) {
608 608
 			$data['items'][] = array(
609 609
 				'label'  => $fee->name,
610 610
 				'amount' => array(
@@ -613,9 +613,9 @@  discard block
 block discarded – undo
613 613
 				),
614 614
 			);
615 615
 		}
616
-		if ( 0 < $tax_total ) {
616
+		if (0 < $tax_total) {
617 617
 			$data['items'][] = array(
618
-				'label'  => __( 'Tax', 'woocommerce-gateway-stripe' ),
618
+				'label'  => __('Tax', 'woocommerce-gateway-stripe'),
619 619
 				'amount' => array(
620 620
 					'currency' => $currency,
621 621
 					'value'    => $tax_total,
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 			);
624 624
 		}
625 625
 
626
-		wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) );
626
+		wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total));
627 627
 	}
628 628
 
629 629
 	/**
@@ -634,37 +634,37 @@  discard block
 block discarded – undo
634 634
 	 * @version 3.1.0
635 635
 	 */
636 636
 	public function process_apple_pay() {
637
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) {
638
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
637
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) {
638
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
639 639
 		}
640 640
 
641 641
 		try {
642
-			$result = array_map( 'wc_clean', $_POST['result'] );
642
+			$result = array_map('wc_clean', $_POST['result']);
643 643
 
644
-			$order = $this->create_order( $result );
644
+			$order = $this->create_order($result);
645 645
 
646
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
646
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
647 647
 
648 648
 			// Handle payment.
649
-			if ( $order->get_total() > 0 ) {
649
+			if ($order->get_total() > 0) {
650 650
 
651
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
652
-					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 ) ) );
651
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
652
+					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)));
653 653
 				}
654 654
 
655
-				$this->log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" );
655
+				$this->log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}");
656 656
 
657 657
 				// Make the request.
658
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) );
658
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id']));
659 659
 
660
-				if ( is_wp_error( $response ) ) {
660
+				if (is_wp_error($response)) {
661 661
 					$localized_messages = $this->get_localized_messages();
662 662
 
663
-					throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) );
663
+					throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message()));
664 664
 				}
665 665
 
666 666
 				// Process valid response.
667
-				$this->process_response( $response, $order );
667
+				$this->process_response($response, $order);
668 668
 			} else {
669 669
 				$order->payment_complete();
670 670
 			}
@@ -672,24 +672,24 @@  discard block
 block discarded – undo
672 672
 			// Remove cart.
673 673
 			WC()->cart->empty_cart();
674 674
 
675
-			update_post_meta( $order_id, '_customer_user', get_current_user_id() );
676
-			update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) );
675
+			update_post_meta($order_id, '_customer_user', get_current_user_id());
676
+			update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe'));
677 677
 
678 678
 			// Return thank you page redirect.
679
-			wp_send_json( array(
679
+			wp_send_json(array(
680 680
 				'success'  => 'true',
681
-				'redirect' => $this->get_return_url( $order ),
682
-			) );
681
+				'redirect' => $this->get_return_url($order),
682
+			));
683 683
 
684
-		} catch ( Exception $e ) {
685
-			WC()->session->set( 'refresh_totals', true );
686
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
684
+		} catch (Exception $e) {
685
+			WC()->session->set('refresh_totals', true);
686
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
687 687
 
688
-			if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
689
-				$this->send_failed_order_email( $order_id );
688
+			if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) {
689
+				$this->send_failed_order_email($order_id);
690 690
 			}
691 691
 
692
-			wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) );
692
+			wp_send_json(array('success' => 'false', 'msg' => $e->getMessage()));
693 693
 		}
694 694
 	}
695 695
 
@@ -699,16 +699,16 @@  discard block
 block discarded – undo
699 699
 	 * @param string $source token
700 700
 	 * @return array()
701 701
 	 */
702
-	protected function generate_payment_request( $order, $source ) {
702
+	protected function generate_payment_request($order, $source) {
703 703
 		$post_data                = array();
704
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
705
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
706
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
704
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
705
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
706
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
707 707
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
708 708
 
709
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
709
+		$billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
710 710
 
711
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
711
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
712 712
 			$post_data['receipt_email'] = $billing_email;
713 713
 		}
714 714
 
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 		 * @param WC_Order $order
724 724
 		 * @param object $source
725 725
 		 */
726
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order );
726
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order);
727 727
 	}
728 728
 
729 729
 	/**
@@ -732,14 +732,14 @@  discard block
 block discarded – undo
732 732
 	 * @since 3.1.0
733 733
 	 * @version 3.1.0
734 734
 	 */
735
-	public function build_shipping_methods( $shipping_methods ) {
736
-		if ( empty( $shipping_methods ) ) {
735
+	public function build_shipping_methods($shipping_methods) {
736
+		if (empty($shipping_methods)) {
737 737
 			return array();
738 738
 		}
739 739
 
740 740
 		$shipping = array();
741 741
 
742
-		foreach ( $shipping_methods as $method ) {
742
+		foreach ($shipping_methods as $method) {
743 743
 			$shipping[] = array(
744 744
 				'label'      => $method['label'],
745 745
 				'detail'     => '',
@@ -758,65 +758,65 @@  discard block
 block discarded – undo
758 758
 	 * @version 3.1.0
759 759
 	 */
760 760
 	public function build_line_items() {
761
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
762
-			define( 'WOOCOMMERCE_CART', true );
761
+		if ( ! defined('WOOCOMMERCE_CART')) {
762
+			define('WOOCOMMERCE_CART', true);
763 763
 		}
764 764
 
765
-		$decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 );
765
+		$decimals = apply_filters('wc_stripe_apple_pay_decimals', 2);
766 766
 		
767 767
 		$items    = array();
768 768
 		$subtotal = 0;
769 769
 
770
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
771
-			$amount         = wc_format_decimal( $values['line_subtotal'], $decimals );
772
-			$subtotal       += $values['line_subtotal'];
770
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
771
+			$amount         = wc_format_decimal($values['line_subtotal'], $decimals);
772
+			$subtotal += $values['line_subtotal'];
773 773
 			$quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : '';
774 774
 
775 775
 			$item = array(
776 776
 				'type'   => 'final',
777 777
 				'label'  => $values['data']->post->post_title . $quantity_label,
778
-				'amount' => wc_format_decimal( $amount, $decimals ),
778
+				'amount' => wc_format_decimal($amount, $decimals),
779 779
 			);
780 780
 
781 781
 			$items[] = $item;
782 782
 		}
783 783
 
784 784
 		// Default show only subtotal instead of itemization.
785
-		if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) {
785
+		if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) {
786 786
 			$items = array();
787 787
 			$items[] = array(
788 788
 				'type'   => 'final',
789
-				'label'  => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ),
790
-				'amount' => wc_format_decimal( $subtotal, $decimals ),
789
+				'label'  => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')),
790
+				'amount' => wc_format_decimal($subtotal, $decimals),
791 791
 			);
792 792
 		}
793 793
 
794
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals );
795
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals );
796
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, $decimals );
797
-		$item_total  = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts;
798
-		$order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals );
794
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals);
795
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals);
796
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, $decimals);
797
+		$item_total  = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts;
798
+		$order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals);
799 799
 
800
-		if ( wc_tax_enabled() ) {
800
+		if (wc_tax_enabled()) {
801 801
 			$items[] = array(
802 802
 				'type'   => 'final',
803
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
803
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
804 804
 				'amount' => $tax,
805 805
 			);
806 806
 		}
807 807
 
808
-		if ( WC()->cart->needs_shipping() ) {
808
+		if (WC()->cart->needs_shipping()) {
809 809
 			$items[] = array(
810 810
 				'type'   => 'final',
811
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
811
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
812 812
 				'amount' => $shipping,
813 813
 			);
814 814
 		}
815 815
 
816
-		if ( WC()->cart->has_discount() ) {
816
+		if (WC()->cart->has_discount()) {
817 817
 			$items[] = array(
818 818
 				'type'   => 'final',
819
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
819
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
820 820
 				'amount' => '-' . $discounts,
821 821
 			);
822 822
 		}
@@ -832,24 +832,24 @@  discard block
 block discarded – undo
832 832
 	 * @param array $data
833 833
 	 * @return object $order
834 834
 	 */
835
-	public function create_order( $data = array() ) {
836
-		if ( empty( $data ) ) {
837
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
835
+	public function create_order($data = array()) {
836
+		if (empty($data)) {
837
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
838 838
 		}
839 839
 
840 840
 		$order = wc_create_order();
841
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
841
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
842 842
 
843
-		if ( is_wp_error( $order ) ) {
844
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) );
845
-		} elseif ( false === $order ) {
846
-			throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) );
843
+		if (is_wp_error($order)) {
844
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520));
845
+		} elseif (false === $order) {
846
+			throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521));
847 847
 		} else {
848
-			do_action( 'woocommerce_new_order', $order_id );
848
+			do_action('woocommerce_new_order', $order_id);
849 849
 		}
850 850
 
851 851
 		// Store the line items to the new/resumed order
852
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
852
+		foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
853 853
 			$item_id = $order->add_product(
854 854
 				$values['data'],
855 855
 				$values['quantity'],
@@ -865,25 +865,25 @@  discard block
 block discarded – undo
865 865
 				)
866 866
 			);
867 867
 
868
-			if ( ! $item_id ) {
869
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) );
868
+			if ( ! $item_id) {
869
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525));
870 870
 			}
871 871
 
872 872
 			// Allow plugins to add order item meta
873
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
874
-				do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
873
+			if (version_compare(WC_VERSION, '3.0', '<')) {
874
+				do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key);
875 875
 			} else {
876
-				do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() );
876
+				do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id());
877 877
 			}
878 878
 		}
879 879
 
880 880
 		// Store fees
881
-		foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
882
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
883
-				$item_id = $order->add_fee( $fee );
881
+		foreach (WC()->cart->get_fees() as $fee_key => $fee) {
882
+			if (version_compare(WC_VERSION, '3.0', '<')) {
883
+				$item_id = $order->add_fee($fee);
884 884
 			} else {
885 885
 				$item = new WC_Order_Item_Fee();
886
-				$item->set_props( array(
886
+				$item->set_props(array(
887 887
 					'name'      => $fee->name,
888 888
 					'tax_class' => $fee->taxable ? $fee->tax_class : 0,
889 889
 					'total'     => $fee->amount,
@@ -892,79 +892,79 @@  discard block
 block discarded – undo
892 892
 						'total' => $fee->tax_data,
893 893
 					),
894 894
 					'order_id'  => $order->get_id(),
895
-				) );
895
+				));
896 896
 				$item_id = $item->save();
897
-				$order->add_item( $item );
897
+				$order->add_item($item);
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' ), 526 ) );
900
+			if ( ! $item_id) {
901
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526));
902 902
 			}
903 903
 
904 904
 			// Allow plugins to add order item meta to fees
905
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
906
-				do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
905
+			if (version_compare(WC_VERSION, '3.0', '<')) {
906
+				do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key);
907 907
 			} else {
908
-				do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() );
908
+				do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id());
909 909
 			}
910 910
 		}
911 911
 
912 912
 		// Store tax rows
913
-		foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
914
-			$tax_amount = WC()->cart->get_tax_amount( $tax_rate_id );
915
-			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id );
913
+		foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) {
914
+			$tax_amount = WC()->cart->get_tax_amount($tax_rate_id);
915
+			$shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id);
916 916
 
917
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
918
-				$item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount );
917
+			if (version_compare(WC_VERSION, '3.0', '<')) {
918
+				$item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount);
919 919
 			} else {
920 920
 				$item = new WC_Order_Item_Tax();
921
-				$item->set_props( array(
921
+				$item->set_props(array(
922 922
 					'rate_id'            => $tax_rate_id,
923 923
 					'tax_total'          => $tax_amount,
924 924
 					'shipping_tax_total' => $shipping_tax_amount,
925
-				) );
926
-				$item->set_rate( $tax_rate_id );
927
-				$item->set_order_id( $order->get_id() );
925
+				));
926
+				$item->set_rate($tax_rate_id);
927
+				$item->set_order_id($order->get_id());
928 928
 				$item_id = $item->save();
929
-				$order->add_item( $item );
929
+				$order->add_item($item);
930 930
 			}
931 931
 
932
-			if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
933
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) );
932
+			if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) {
933
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528));
934 934
 			}
935 935
 		}
936 936
 
937 937
 		// Store coupons
938
-		$discount = WC()->cart->get_coupon_discount_amount( $code );
939
-		$discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code );
938
+		$discount = WC()->cart->get_coupon_discount_amount($code);
939
+		$discount_tax = WC()->cart->get_coupon_discount_tax_amount($code);
940 940
 
941
-		foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
942
-			if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
943
-				$coupon_id = $order->add_coupon( $code, $discount, $discount_tax );
941
+		foreach (WC()->cart->get_coupons() as $code => $coupon) {
942
+			if (version_compare(WC_VERSION, '3.0', '<')) {
943
+				$coupon_id = $order->add_coupon($code, $discount, $discount_tax);
944 944
 			} else {
945 945
 				$item = new WC_Order_Item_Coupon();
946
-				$item->set_props( array(
946
+				$item->set_props(array(
947 947
 					'code'         => $code,
948 948
 					'discount'     => $discount,
949 949
 					'discount_tax' => $discount_tax,
950 950
 					'order_id'     => $order->get_id(),
951
-				) );
951
+				));
952 952
 				$coupon_id = $item->save();
953
-				$order->add_item( $item );
953
+				$order->add_item($item);
954 954
 			}
955 955
 
956
-			if ( ! $coupon_id ) {
957
-				throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) );
956
+			if ( ! $coupon_id) {
957
+				throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529));
958 958
 			}
959 959
 		}
960 960
 
961 961
 		// Billing address
962 962
 		$billing_address = array();
963
-		if ( ! empty( $data['token']['card'] ) ) {
963
+		if ( ! empty($data['token']['card'])) {
964 964
 			// Name from Stripe is a full name string.
965
-			$name                          = explode( ' ', $data['token']['card']['name'] );
966
-			$lastname                      = array_pop( $name );
967
-			$firstname                     = implode( ' ', $name );
965
+			$name                          = explode(' ', $data['token']['card']['name']);
966
+			$lastname                      = array_pop($name);
967
+			$firstname                     = implode(' ', $name);
968 968
 			$billing_address['first_name'] = $firstname;
969 969
 			$billing_address['last_name']  = $lastname;
970 970
 			$billing_address['email']      = $data['shippingContact']['emailAddress'];
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 
980 980
 		// Shipping address.
981 981
 		$shipping_address = array();
982
-		if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) {
982
+		if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) {
983 983
 			$shipping_address['first_name'] = $data['shippingContact']['givenName'];
984 984
 			$shipping_address['last_name']  = $data['shippingContact']['familyName'];
985 985
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
 			$shipping_address['city']       = $data['shippingContact']['locality'];
991 991
 			$shipping_address['state']      = $data['shippingContact']['administrativeArea'];
992 992
 			$shipping_address['postcode']   = $data['shippingContact']['postalCode'];
993
-		} elseif ( ! empty( $data['shippingContact'] ) ) {
993
+		} elseif ( ! empty($data['shippingContact'])) {
994 994
 			$shipping_address['first_name'] = $firstname;
995 995
 			$shipping_address['last_name']  = $lastname;
996 996
 			$shipping_address['email']      = $data['shippingContact']['emailAddress'];
@@ -1003,33 +1003,33 @@  discard block
 block discarded – undo
1003 1003
 			$shipping_address['postcode']   = $data['token']['card']['address_zip'];
1004 1004
 		}
1005 1005
 
1006
-		$order->set_address( $billing_address, 'billing' );
1007
-		$order->set_address( $shipping_address, 'shipping' );
1006
+		$order->set_address($billing_address, 'billing');
1007
+		$order->set_address($shipping_address, 'shipping');
1008 1008
 
1009
-		WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() );
1009
+		WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages());
1010 1010
 
1011 1011
 		// Get the rate object selected by user.
1012
-		foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
1013
-			foreach ( $package['rates'] as $key => $rate ) {
1012
+		foreach (WC()->shipping->get_packages() as $package_key => $package) {
1013
+			foreach ($package['rates'] as $key => $rate) {
1014 1014
 				// Loop through user chosen shipping methods.
1015
-				foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) {
1016
-					if ( $method === $key ) {
1017
-						if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1018
-							$order->add_shipping( $rate );
1015
+				foreach (WC()->session->get('chosen_shipping_methods') as $method) {
1016
+					if ($method === $key) {
1017
+						if (version_compare(WC_VERSION, '3.0', '<')) {
1018
+							$order->add_shipping($rate);
1019 1019
 						} else {
1020 1020
 							$item = new WC_Order_Item_Shipping();
1021
-							$item->set_props( array(
1021
+							$item->set_props(array(
1022 1022
 								'method_title' => $rate->label,
1023 1023
 								'method_id'    => $rate->id,
1024
-								'total'        => wc_format_decimal( $rate->cost ),
1024
+								'total'        => wc_format_decimal($rate->cost),
1025 1025
 								'taxes'        => $rate->taxes,
1026 1026
 								'order_id'     => $order->get_id(),
1027
-							) );
1028
-							foreach ( $rate->get_meta_data() as $key => $value ) {
1029
-								$item->add_meta_data( $key, $value, true );
1027
+							));
1028
+							foreach ($rate->get_meta_data() as $key => $value) {
1029
+								$item->add_meta_data($key, $value, true);
1030 1030
 							}
1031 1031
 							$item->save();
1032
-							$order->add_item( $item );
1032
+							$order->add_item($item);
1033 1033
 						}
1034 1034
 					}
1035 1035
 				}
@@ -1037,16 +1037,16 @@  discard block
 block discarded – undo
1037 1037
 		}
1038 1038
 
1039 1039
 		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
1040
-		$order->set_payment_method( $available_gateways['stripe'] );
1041
-		$order->set_total( WC()->cart->shipping_total, 'shipping' );
1042
-		$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
1043
-		$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
1044
-		$order->set_total( WC()->cart->tax_total, 'tax' );
1045
-		$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
1046
-		$order->set_total( WC()->cart->total );
1040
+		$order->set_payment_method($available_gateways['stripe']);
1041
+		$order->set_total(WC()->cart->shipping_total, 'shipping');
1042
+		$order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
1043
+		$order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
1044
+		$order->set_total(WC()->cart->tax_total, 'tax');
1045
+		$order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
1046
+		$order->set_total(WC()->cart->total);
1047 1047
 
1048 1048
 		// If we got here, the order was created without problems!
1049
-		wc_transaction_query( 'commit' );
1049
+		wc_transaction_query('commit');
1050 1050
 
1051 1051
 		return $order;
1052 1052
 	}
@@ -1059,9 +1059,9 @@  discard block
 block discarded – undo
1059 1059
 	 *
1060 1060
 	 * @param string $message
1061 1061
 	 */
1062
-	public function log( $message ) {
1063
-		if ( $this->logging ) {
1064
-			WC_Stripe::log( $message );
1062
+	public function log($message) {
1063
+		if ($this->logging) {
1064
+			WC_Stripe::log($message);
1065 1065
 		}
1066 1066
 	}
1067 1067
 }
Please login to merge, or discard this patch.