Completed
Push — master ( e1a3fa...2c2d75 )
by Dwain
02:17 queued 12s
created
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +375 added lines, -376 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
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	public function display_admin_settings_webhook_description() {
23 23
 		/* translators: 1) webhook url */
24
-		return sprintf( __( 'You must add the following webhook endpoint <strong style="background-color:#ddd;">&nbsp;%s&nbsp;</strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::get_webhook_url() );
24
+		return sprintf(__('You must add the following webhook endpoint <strong style="background-color:#ddd;">&nbsp;%s&nbsp;</strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::get_webhook_url());
25 25
 	}
26 26
 
27 27
 	/**
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 				<input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
36 36
 				<label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label>
37 37
 			</p>',
38
-			esc_attr( $this->id ),
39
-			esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) )
38
+			esc_attr($this->id),
39
+			esc_html(apply_filters('wc_stripe_save_to_account_text', __('Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe')))
40 40
 		);
41 41
 	}
42 42
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @since 4.0.5
48 48
 	 * @param array $error
49 49
 	 */
50
-	public function is_retryable_error( $error ) {
50
+	public function is_retryable_error($error) {
51 51
 		return (
52 52
 			'invalid_request_error' === $error->type ||
53 53
 			'idempotency_error' === $error->type ||
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 	 * @since 4.1.0
65 65
 	 * @param array $error
66 66
 	 */
67
-	public function is_same_idempotency_error( $error ) {
67
+	public function is_same_idempotency_error($error) {
68 68
 		return (
69 69
 			$error &&
70 70
 			'idempotency_error' === $error->type &&
71
-			preg_match( '/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message )
71
+			preg_match('/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message)
72 72
 		);
73 73
 	}
74 74
 
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
 	 * @since 4.1.0
80 80
 	 * @param array $error
81 81
 	 */
82
-	public function is_no_such_customer_error( $error ) {
82
+	public function is_no_such_customer_error($error) {
83 83
 		return (
84 84
 			$error &&
85 85
 			'invalid_request_error' === $error->type &&
86
-			preg_match( '/No such customer/i', $error->message )
86
+			preg_match('/No such customer/i', $error->message)
87 87
 		);
88 88
 	}
89 89
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 	 * @since 4.1.0
95 95
 	 * @param array $error
96 96
 	 */
97
-	public function is_no_such_token_error( $error ) {
97
+	public function is_no_such_token_error($error) {
98 98
 		return (
99 99
 			$error &&
100 100
 			'invalid_request_error' === $error->type &&
101
-			preg_match( '/No such token/i', $error->message )
101
+			preg_match('/No such token/i', $error->message)
102 102
 		);
103 103
 	}
104 104
 
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 	 * @since 4.1.0
110 110
 	 * @param array $error
111 111
 	 */
112
-	public function is_no_such_source_error( $error ) {
112
+	public function is_no_such_source_error($error) {
113 113
 		return (
114 114
 			$error &&
115 115
 			'invalid_request_error' === $error->type &&
116
-			preg_match( '/No such source/i', $error->message )
116
+			preg_match('/No such source/i', $error->message)
117 117
 		);
118 118
 	}
119 119
 
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
 	 * @since 4.1.0
125 125
 	 * @param array $error
126 126
 	 */
127
-	public function is_no_linked_source_error( $error ) {
127
+	public function is_no_linked_source_error($error) {
128 128
 		return (
129 129
 			$error &&
130 130
 			'invalid_request_error' === $error->type &&
131
-			preg_match( '/does not have a linked source with ID/i', $error->message )
131
+			preg_match('/does not have a linked source with ID/i', $error->message)
132 132
 		);
133 133
 	}
134 134
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @param object $error
142 142
 	 * @return bool
143 143
 	 */
144
-	public function need_update_idempotency_key( $source_object, $error ) {
144
+	public function need_update_idempotency_key($source_object, $error) {
145 145
 		return (
146 146
 			$error &&
147 147
 			1 < $this->retry_interval &&
148
-			! empty( $source_object ) &&
148
+			! empty($source_object) &&
149 149
 			'chargeable' === $source_object->status &&
150
-			self::is_same_idempotency_error( $error )
150
+			self::is_same_idempotency_error($error)
151 151
 		);
152 152
 	}
153 153
 
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
 		// NOTE: updates to this function should be added to are_keys_set()
162 162
 		// in includes/payment-methods/class-wc-stripe-payment-request.php
163 163
 
164
-		if ( $this->testmode ) {
165
-			return preg_match( '/^pk_test_/', $this->publishable_key )
166
-				&& preg_match( '/^[rs]k_test_/', $this->secret_key );
164
+		if ($this->testmode) {
165
+			return preg_match('/^pk_test_/', $this->publishable_key)
166
+				&& preg_match('/^[rs]k_test_/', $this->secret_key);
167 167
 		} else {
168
-			return preg_match( '/^pk_live_/', $this->publishable_key )
169
-			    && preg_match( '/^[rs]k_live_/', $this->secret_key );
168
+			return preg_match('/^pk_live_/', $this->publishable_key)
169
+			    && preg_match('/^[rs]k_live_/', $this->secret_key);
170 170
 		}
171 171
 	}
172 172
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 * @since 4.1.3
177 177
 	 */
178 178
 	public function is_available() {
179
-		if ( 'yes' === $this->enabled ) {
179
+		if ('yes' === $this->enabled) {
180 180
 			return $this->are_keys_set();
181 181
 		}
182 182
 
@@ -191,12 +191,12 @@  discard block
 block discarded – undo
191 191
 	 * @param int $order_id
192 192
 	 * @return bool
193 193
 	 */
194
-	public function maybe_process_pre_orders( $order_id ) {
194
+	public function maybe_process_pre_orders($order_id) {
195 195
 		return (
196 196
 			WC_Stripe_Helper::is_pre_orders_exists() &&
197
-			$this->pre_orders->is_pre_order( $order_id ) &&
198
-			WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) &&
199
-			! is_wc_endpoint_url( 'order-pay' )
197
+			$this->pre_orders->is_pre_order($order_id) &&
198
+			WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) &&
199
+			! is_wc_endpoint_url('order-pay')
200 200
 		);
201 201
 	}
202 202
 
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 	 * @version 4.0.0
241 241
 	 * @param object $order
242 242
 	 */
243
-	public function validate_minimum_order_amount( $order ) {
244
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
243
+	public function validate_minimum_order_amount($order) {
244
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
245 245
 			/* translators: 1) dollar amount */
246
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
246
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
247 247
 		}
248 248
 	}
249 249
 
@@ -253,14 +253,14 @@  discard block
 block discarded – undo
253 253
 	 * @since 4.0.0
254 254
 	 * @version 4.0.0
255 255
 	 */
256
-	public function get_transaction_url( $order ) {
257
-		if ( $this->testmode ) {
256
+	public function get_transaction_url($order) {
257
+		if ($this->testmode) {
258 258
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
259 259
 		} else {
260 260
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
261 261
 		}
262 262
 
263
-		return parent::get_transaction_url( $order );
263
+		return parent::get_transaction_url($order);
264 264
 	}
265 265
 
266 266
 	/**
@@ -269,15 +269,15 @@  discard block
 block discarded – undo
269 269
 	 * @since 4.0.0
270 270
 	 * @version 4.0.0
271 271
 	 */
272
-	public function get_stripe_customer_id( $order ) {
273
-		$customer = get_user_option( '_stripe_customer_id', WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id() );
272
+	public function get_stripe_customer_id($order) {
273
+		$customer = get_user_option('_stripe_customer_id', WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id());
274 274
 
275
-		if ( empty( $customer ) ) {
275
+		if (empty($customer)) {
276 276
 			// Try to get it via the order.
277
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
278
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
277
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
278
+				return get_post_meta($order->id, '_stripe_customer_id', true);
279 279
 			} else {
280
-				return $order->get_meta( '_stripe_customer_id', true );
280
+				return $order->get_meta('_stripe_customer_id', true);
281 281
 			}
282 282
 		} else {
283 283
 			return $customer;
@@ -294,23 +294,23 @@  discard block
 block discarded – undo
294 294
 	 * @param object $order
295 295
 	 * @param int $id Stripe session id.
296 296
 	 */
297
-	public function get_stripe_return_url( $order = null, $id = null ) {
298
-		if ( is_object( $order ) ) {
299
-			if ( empty( $id ) ) {
297
+	public function get_stripe_return_url($order = null, $id = null) {
298
+		if (is_object($order)) {
299
+			if (empty($id)) {
300 300
 				$id = uniqid();
301 301
 			}
302 302
 
303
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
303
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
304 304
 
305 305
 			$args = array(
306 306
 				'utm_nooverride' => '1',
307 307
 				'order_id'       => $order_id,
308 308
 			);
309 309
 
310
-			return wp_sanitize_redirect( esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ) );
310
+			return wp_sanitize_redirect(esc_url_raw(add_query_arg($args, $this->get_return_url($order))));
311 311
 		}
312 312
 
313
-		return wp_sanitize_redirect( esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ) );
313
+		return wp_sanitize_redirect(esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())));
314 314
 	}
315 315
 
316 316
 	/**
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 	 * @param  int  $order_id
319 319
 	 * @return boolean
320 320
 	 */
321
-	public function has_subscription( $order_id ) {
322
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
321
+	public function has_subscription($order_id) {
322
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
323 323
 	}
324 324
 
325 325
 	/**
@@ -331,34 +331,33 @@  discard block
 block discarded – undo
331 331
 	 * @param  object $prepared_source
332 332
 	 * @return array()
333 333
 	 */
334
-	public function generate_payment_request( $order, $prepared_source ) {
335
-		$settings              = get_option( 'woocommerce_stripe_settings', array() );
336
-		$statement_descriptor  = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
337
-		$capture               = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
334
+	public function generate_payment_request($order, $prepared_source) {
335
+		$settings              = get_option('woocommerce_stripe_settings', array());
336
+		$statement_descriptor  = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
337
+		$capture               = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
338 338
 		$post_data             = array();
339
-		$post_data['currency'] = strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() );
340
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
339
+		$post_data['currency'] = strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency());
340
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
341 341
 		/* translators: 1) blog name 2) order number */
342
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
343
-		$billing_email            = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email();
344
-		$billing_first_name       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name();
345
-		$billing_last_name        = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name();
342
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
343
+		$billing_email            = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email();
344
+		$billing_first_name       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name();
345
+		$billing_last_name        = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name();
346 346
 
347
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
347
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
348 348
 			$post_data['receipt_email'] = $billing_email;
349 349
 		}
350 350
 
351
-		switch ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) {
352
-			case 'stripe':
353
-				if ( ! empty( $statement_descriptor ) ) {
354
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
351
+		switch (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method()) {
352
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
353
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
355 354
 				}
356 355
 
357 356
 				$post_data['capture'] = $capture ? 'true' : 'false';
358 357
 				break;
359 358
 			case 'stripe_sepa':
360
-				if ( ! empty( $statement_descriptor ) ) {
361
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
359
+				if ( ! empty($statement_descriptor)) {
360
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
362 361
 				}
363 362
 				break;
364 363
 		}
@@ -366,25 +365,25 @@  discard block
 block discarded – undo
366 365
 		$post_data['expand[]'] = 'balance_transaction';
367 366
 
368 367
 		$metadata = array(
369
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
370
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
368
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
369
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
371 370
 			'order_id' => $order->get_order_number(),
372 371
 		);
373 372
 
374
-		if ( $this->has_subscription( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id() ) ) {
373
+		if ($this->has_subscription(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id())) {
375 374
 			$metadata += array(
376 375
 				'payment_type' => 'recurring',
377
-				'site_url'     => esc_url( get_site_url() ),
376
+				'site_url'     => esc_url(get_site_url()),
378 377
 			);
379 378
 		}
380 379
 
381
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source );
380
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source);
382 381
 
383
-		if ( $prepared_source->customer ) {
382
+		if ($prepared_source->customer) {
384 383
 			$post_data['customer'] = $prepared_source->customer;
385 384
 		}
386 385
 
387
-		if ( $prepared_source->source ) {
386
+		if ($prepared_source->source) {
388 387
 			$post_data['source'] = $prepared_source->source;
389 388
 		}
390 389
 
@@ -396,72 +395,72 @@  discard block
 block discarded – undo
396 395
 		 * @param WC_Order $order
397 396
 		 * @param object $source
398 397
 		 */
399
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source );
398
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source);
400 399
 	}
401 400
 
402 401
 	/**
403 402
 	 * Store extra meta data for an order from a Stripe Response.
404 403
 	 */
405
-	public function process_response( $response, $order ) {
406
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
404
+	public function process_response($response, $order) {
405
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
407 406
 
408
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
409
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
407
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
408
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
410 409
 
411 410
 		// Store charge data.
412
-		WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
411
+		WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
413 412
 
414
-		if ( isset( $response->balance_transaction ) ) {
415
-			$this->update_fees( $order, is_string( $response->balance_transaction ) ? $response->balance_transaction : $response->balance_transaction->id );
413
+		if (isset($response->balance_transaction)) {
414
+			$this->update_fees($order, is_string($response->balance_transaction) ? $response->balance_transaction : $response->balance_transaction->id);
416 415
 		}
417 416
 
418
-		if ( 'yes' === $captured ) {
417
+		if ('yes' === $captured) {
419 418
 			/**
420 419
 			 * Charge can be captured but in a pending state. Payment methods
421 420
 			 * that are asynchronous may take couple days to clear. Webhook will
422 421
 			 * take care of the status changes.
423 422
 			 */
424
-			if ( 'pending' === $response->status ) {
425
-				$order_stock_reduced = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true );
423
+			if ('pending' === $response->status) {
424
+				$order_stock_reduced = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true);
426 425
 
427
-				if ( ! $order_stock_reduced ) {
428
-					WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
426
+				if ( ! $order_stock_reduced) {
427
+					WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
429 428
 				}
430 429
 
431
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
430
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
432 431
 				/* translators: transaction id */
433
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
432
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
434 433
 			}
435 434
 
436
-			if ( 'succeeded' === $response->status ) {
437
-				$order->payment_complete( $response->id );
435
+			if ('succeeded' === $response->status) {
436
+				$order->payment_complete($response->id);
438 437
 
439 438
 				/* translators: transaction id */
440
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
441
-				$order->add_order_note( $message );
439
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
440
+				$order->add_order_note($message);
442 441
 			}
443 442
 
444
-			if ( 'failed' === $response->status ) {
445
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
446
-				$order->add_order_note( $localized_message );
447
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
443
+			if ('failed' === $response->status) {
444
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
445
+				$order->add_order_note($localized_message);
446
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
448 447
 			}
449 448
 		} else {
450
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
449
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
451 450
 
452
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
453
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
451
+			if ($order->has_status(array('pending', 'failed'))) {
452
+				WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
454 453
 			}
455 454
 
456 455
 			/* translators: transaction id */
457
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
456
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
458 457
 		}
459 458
 
460
-		if ( is_callable( array( $order, 'save' ) ) ) {
459
+		if (is_callable(array($order, 'save'))) {
461 460
 			$order->save();
462 461
 		}
463 462
 
464
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
463
+		do_action('wc_gateway_stripe_process_response', $response, $order);
465 464
 
466 465
 		return $response;
467 466
 	}
@@ -474,10 +473,10 @@  discard block
 block discarded – undo
474 473
 	 * @param int $order_id
475 474
 	 * @return null
476 475
 	 */
477
-	public function send_failed_order_email( $order_id ) {
476
+	public function send_failed_order_email($order_id) {
478 477
 		$emails = WC()->mailer()->get_emails();
479
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
480
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
478
+		if ( ! empty($emails) && ! empty($order_id)) {
479
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
481 480
 		}
482 481
 	}
483 482
 
@@ -489,36 +488,36 @@  discard block
 block discarded – undo
489 488
 	 * @param object $order
490 489
 	 * @return object $details
491 490
 	 */
492
-	public function get_owner_details( $order ) {
493
-		$billing_first_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name();
494
-		$billing_last_name  = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name();
491
+	public function get_owner_details($order) {
492
+		$billing_first_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name();
493
+		$billing_last_name  = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name();
495 494
 
496 495
 		$details = array();
497 496
 
498 497
 		$name  = $billing_first_name . ' ' . $billing_last_name;
499
-		$email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email();
500
-		$phone = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_phone : $order->get_billing_phone();
498
+		$email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email();
499
+		$phone = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_phone : $order->get_billing_phone();
501 500
 
502
-		if ( ! empty( $phone ) ) {
501
+		if ( ! empty($phone)) {
503 502
 			$details['phone'] = $phone;
504 503
 		}
505 504
 
506
-		if ( ! empty( $name ) ) {
505
+		if ( ! empty($name)) {
507 506
 			$details['name'] = $name;
508 507
 		}
509 508
 
510
-		if ( ! empty( $email ) ) {
509
+		if ( ! empty($email)) {
511 510
 			$details['email'] = $email;
512 511
 		}
513 512
 
514
-		$details['address']['line1']       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_1 : $order->get_billing_address_1();
515
-		$details['address']['line2']       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_2 : $order->get_billing_address_2();
516
-		$details['address']['state']       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_state : $order->get_billing_state();
517
-		$details['address']['city']        = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_city : $order->get_billing_city();
518
-		$details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_postcode : $order->get_billing_postcode();
519
-		$details['address']['country']     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country();
513
+		$details['address']['line1']       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_1 : $order->get_billing_address_1();
514
+		$details['address']['line2']       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_2 : $order->get_billing_address_2();
515
+		$details['address']['state']       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_state : $order->get_billing_state();
516
+		$details['address']['city']        = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_city : $order->get_billing_city();
517
+		$details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_postcode : $order->get_billing_postcode();
518
+		$details['address']['country']     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country();
520 519
 
521
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
520
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
522 521
 	}
523 522
 
524 523
 	/**
@@ -527,15 +526,15 @@  discard block
 block discarded – undo
527 526
 	 * @since 4.0.3
528 527
 	 * @param string $source_id The source ID to get source object for.
529 528
 	 */
530
-	public function get_source_object( $source_id = '' ) {
531
-		if ( empty( $source_id ) ) {
529
+	public function get_source_object($source_id = '') {
530
+		if (empty($source_id)) {
532 531
 			return '';
533 532
 		}
534 533
 
535
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
534
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
536 535
 
537
-		if ( ! empty( $source_object->error ) ) {
538
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
536
+		if ( ! empty($source_object->error)) {
537
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
539 538
 		}
540 539
 
541 540
 		return $source_object;
@@ -548,10 +547,10 @@  discard block
 block discarded – undo
548 547
 	 * @param object $source_object
549 548
 	 * @return bool
550 549
 	 */
551
-	public function is_prepaid_card( $source_object ) {
550
+	public function is_prepaid_card($source_object) {
552 551
 		return (
553 552
 			$source_object
554
-			&& ( 'token' === $source_object->object || 'source' === $source_object->object )
553
+			&& ('token' === $source_object->object || 'source' === $source_object->object)
555 554
 			&& 'prepaid' === $source_object->card->funding
556 555
 		);
557 556
 	}
@@ -563,8 +562,8 @@  discard block
 block discarded – undo
563 562
 	 * @param string $source_id
564 563
 	 * @return bool
565 564
 	 */
566
-	public function is_type_legacy_card( $source_id ) {
567
-		return ( preg_match( '/^card_/', $source_id ) );
565
+	public function is_type_legacy_card($source_id) {
566
+		return (preg_match('/^card_/', $source_id));
568 567
 	}
569 568
 
570 569
 	/**
@@ -574,9 +573,9 @@  discard block
 block discarded – undo
574 573
 	 * @return bool
575 574
 	 */
576 575
 	public function is_using_saved_payment_method() {
577
-		$payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
576
+		$payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
578 577
 
579
-		return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
578
+		return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']);
580 579
 	}
581 580
 
582 581
 	/**
@@ -592,64 +591,64 @@  discard block
 block discarded – undo
592 591
 	 * @throws Exception When card was not added or for and invalid card.
593 592
 	 * @return object
594 593
 	 */
595
-	public function prepare_source( $user_id, $force_save_source = false, $existing_customer_id = null ) {
596
-		$customer = new WC_Stripe_Customer( $user_id );
597
-		if ( ! empty( $existing_customer_id ) ) {
598
-			$customer->set_id( $existing_customer_id );
594
+	public function prepare_source($user_id, $force_save_source = false, $existing_customer_id = null) {
595
+		$customer = new WC_Stripe_Customer($user_id);
596
+		if ( ! empty($existing_customer_id)) {
597
+			$customer->set_id($existing_customer_id);
599 598
 		}
600 599
 
601
-		$force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
600
+		$force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
602 601
 		$source_object     = '';
603 602
 		$source_id         = '';
604 603
 		$wc_token_id       = false;
605
-		$payment_method    = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
604
+		$payment_method    = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
606 605
 		$is_token          = false;
607 606
 
608 607
 		// New CC info was entered and we have a new source to process.
609
-		if ( ! empty( $_POST['stripe_source'] ) ) {
610
-			$source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) );
608
+		if ( ! empty($_POST['stripe_source'])) {
609
+			$source_object = self::get_source_object(wc_clean($_POST['stripe_source']));
611 610
 			$source_id     = $source_object->id;
612 611
 
613 612
 			// This checks to see if customer opted to save the payment method to file.
614
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
613
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
615 614
 
616 615
 			/**
617 616
 			 * This is true if the user wants to store the card to their account.
618 617
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
619 618
 			 * actually reusable. Either that or force_save_source is true.
620 619
 			 */
621
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
622
-				$response = $customer->add_source( $source_object->id );
620
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
621
+				$response = $customer->add_source($source_object->id);
623 622
 
624
-				if ( ! empty( $response->error ) ) {
625
-					throw new WC_Stripe_Exception( print_r( $response, true ), $this->get_localized_error_message_from_response( $response ) );
623
+				if ( ! empty($response->error)) {
624
+					throw new WC_Stripe_Exception(print_r($response, true), $this->get_localized_error_message_from_response($response));
626 625
 				}
627 626
 			}
628
-		} elseif ( $this->is_using_saved_payment_method() ) {
627
+		} elseif ($this->is_using_saved_payment_method()) {
629 628
 			// Use an existing token, and then process the payment.
630
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
631
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
629
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
630
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
632 631
 
633
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
634
-				WC()->session->set( 'refresh_totals', true );
635
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
632
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
633
+				WC()->session->set('refresh_totals', true);
634
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
636 635
 			}
637 636
 
638 637
 			$source_id = $wc_token->get_token();
639 638
 
640
-			if ( $this->is_type_legacy_card( $source_id ) ) {
639
+			if ($this->is_type_legacy_card($source_id)) {
641 640
 				$is_token = true;
642 641
 			}
643
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
644
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
645
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
642
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
643
+			$stripe_token     = wc_clean($_POST['stripe_token']);
644
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
646 645
 
647 646
 			// This is true if the user wants to store the card to their account.
648
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
649
-				$response = $customer->add_source( $stripe_token );
647
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
648
+				$response = $customer->add_source($stripe_token);
650 649
 
651
-				if ( ! empty( $response->error ) ) {
652
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
650
+				if ( ! empty($response->error)) {
651
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
653 652
 				}
654 653
 				$source_id    = $response;
655 654
 			} else {
@@ -659,15 +658,15 @@  discard block
 block discarded – undo
659 658
 		}
660 659
 
661 660
 		$customer_id = $customer->get_id();
662
-		if ( ! $customer_id ) {
663
-			$customer->set_id( $customer->create_customer() );
661
+		if ( ! $customer_id) {
662
+			$customer->set_id($customer->create_customer());
664 663
 			$customer_id = $customer->get_id();
665 664
 		} else {
666 665
 			$customer_id = $customer->update_customer();
667 666
 		}
668 667
 
669
-		if ( empty( $source_object ) && ! $is_token ) {
670
-			$source_object = self::get_source_object( $source_id );
668
+		if (empty($source_object) && ! $is_token) {
669
+			$source_object = self::get_source_object($source_id);
671 670
 		}
672 671
 
673 672
 		return (object) array(
@@ -691,39 +690,39 @@  discard block
 block discarded – undo
691 690
 	 * @param object $order
692 691
 	 * @return object
693 692
 	 */
694
-	public function prepare_order_source( $order = null ) {
693
+	public function prepare_order_source($order = null) {
695 694
 		$stripe_customer = new WC_Stripe_Customer();
696 695
 		$stripe_source   = false;
697 696
 		$token_id        = false;
698 697
 		$source_object   = false;
699 698
 
700
-		if ( $order ) {
701
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
699
+		if ($order) {
700
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
702 701
 
703
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
702
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
704 703
 
705
-			if ( $stripe_customer_id ) {
706
-				$stripe_customer->set_id( $stripe_customer_id );
704
+			if ($stripe_customer_id) {
705
+				$stripe_customer->set_id($stripe_customer_id);
707 706
 			}
708 707
 
709
-			$source_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
708
+			$source_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
710 709
 
711 710
 			// Since 4.0.0, we changed card to source so we need to account for that.
712
-			if ( empty( $source_id ) ) {
713
-				$source_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
711
+			if (empty($source_id)) {
712
+				$source_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
714 713
 
715 714
 				// Take this opportunity to update the key name.
716
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id );
715
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
717 716
 
718
-				if ( is_callable( array( $order, 'save' ) ) ) {
717
+				if (is_callable(array($order, 'save'))) {
719 718
 					$order->save();
720 719
 				}
721 720
 			}
722 721
 
723
-			if ( $source_id ) {
722
+			if ($source_id) {
724 723
 				$stripe_source = $source_id;
725
-				$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
726
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
724
+				$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
725
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
727 726
 				/*
728 727
 				 * We can attempt to charge the customer's default source
729 728
 				 * by sending empty source id.
@@ -748,27 +747,27 @@  discard block
 block discarded – undo
748 747
 	 * @param WC_Order $order For to which the source applies.
749 748
 	 * @param stdClass $source Source information.
750 749
 	 */
751
-	public function save_source_to_order( $order, $source ) {
752
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
750
+	public function save_source_to_order($order, $source) {
751
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
753 752
 
754 753
 		// Store source in the order.
755
-		if ( $source->customer ) {
756
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
757
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
754
+		if ($source->customer) {
755
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
756
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
758 757
 			} else {
759
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
758
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
760 759
 			}
761 760
 		}
762 761
 
763
-		if ( $source->source ) {
764
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
765
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
762
+		if ($source->source) {
763
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
764
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
766 765
 			} else {
767
-				$order->update_meta_data( '_stripe_source_id', $source->source );
766
+				$order->update_meta_data('_stripe_source_id', $source->source);
768 767
 			}
769 768
 		}
770 769
 
771
-		if ( is_callable( array( $order, 'save' ) ) ) {
770
+		if (is_callable(array($order, 'save'))) {
772 771
 			$order->save();
773 772
 		}
774 773
 	}
@@ -782,38 +781,38 @@  discard block
 block discarded – undo
782 781
 	 * @param object $order The order object
783 782
 	 * @param int $balance_transaction_id
784 783
 	 */
785
-	public function update_fees( $order, $balance_transaction_id ) {
786
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
784
+	public function update_fees($order, $balance_transaction_id) {
785
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
787 786
 
788
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
787
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
789 788
 
790
-		if ( empty( $balance_transaction->error ) ) {
791
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
789
+		if (empty($balance_transaction->error)) {
790
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
792 791
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
793 792
 				// values are in the local currency of the Stripe account, not from WC.
794
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
795
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
793
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
794
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
796 795
 
797 796
 				// Current data fee & net.
798
-				$fee_current = WC_Stripe_Helper::get_stripe_fee( $order );
799
-				$net_current = WC_Stripe_Helper::get_stripe_net( $order );
797
+				$fee_current = WC_Stripe_Helper::get_stripe_fee($order);
798
+				$net_current = WC_Stripe_Helper::get_stripe_net($order);
800 799
 
801 800
 				// Calculation.
802 801
 				$fee = (float) $fee_current + (float) $fee_refund;
803 802
 				$net = (float) $net_current + (float) $net_refund;
804 803
 
805
-				WC_Stripe_Helper::update_stripe_fee( $order, $fee );
806
-				WC_Stripe_Helper::update_stripe_net( $order, $net );
804
+				WC_Stripe_Helper::update_stripe_fee($order, $fee);
805
+				WC_Stripe_Helper::update_stripe_net($order, $net);
807 806
 
808
-				$currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null;
809
-				WC_Stripe_Helper::update_stripe_currency( $order, $currency );
807
+				$currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null;
808
+				WC_Stripe_Helper::update_stripe_currency($order, $currency);
810 809
 
811
-				if ( is_callable( array( $order, 'save' ) ) ) {
810
+				if (is_callable(array($order, 'save'))) {
812 811
 					$order->save();
813 812
 				}
814 813
 			}
815 814
 		} else {
816
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
815
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
817 816
 		}
818 817
 	}
819 818
 
@@ -826,99 +825,99 @@  discard block
 block discarded – undo
826 825
 	 * @param  float $amount
827 826
 	 * @return bool
828 827
 	 */
829
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
830
-		$order = wc_get_order( $order_id );
828
+	public function process_refund($order_id, $amount = null, $reason = '') {
829
+		$order = wc_get_order($order_id);
831 830
 
832
-		if ( ! $order ) {
831
+		if ( ! $order) {
833 832
 			return false;
834 833
 		}
835 834
 
836 835
 		$request = array();
837 836
 
838
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
839
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
840
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
841
-			$charge_id      = get_post_meta( $order_id, '_transaction_id', true );
837
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
838
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
839
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
840
+			$charge_id      = get_post_meta($order_id, '_transaction_id', true);
842 841
 		} else {
843 842
 			$order_currency = $order->get_currency();
844
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
843
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
845 844
 			$charge_id      = $order->get_transaction_id();
846 845
 		}
847 846
 
848
-		if ( ! $charge_id ) {
847
+		if ( ! $charge_id) {
849 848
 			return false;
850 849
 		}
851 850
 
852
-		if ( ! is_null( $amount ) ) {
853
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
851
+		if ( ! is_null($amount)) {
852
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
854 853
 		}
855 854
 
856 855
 		// If order is only authorized, don't pass amount.
857
-		if ( 'yes' !== $captured ) {
858
-			unset( $request['amount'] );
856
+		if ('yes' !== $captured) {
857
+			unset($request['amount']);
859 858
 		}
860 859
 
861
-		if ( $reason ) {
860
+		if ($reason) {
862 861
 			$request['metadata'] = array(
863 862
 				'reason' => $reason,
864 863
 			);
865 864
 		}
866 865
 
867 866
 		$request['charge'] = $charge_id;
868
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$charge_id} for the amount of {$amount}" );
867
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$charge_id} for the amount of {$amount}");
869 868
 
870
-		$request = apply_filters( 'wc_stripe_refund_request', $request, $order );
869
+		$request = apply_filters('wc_stripe_refund_request', $request, $order);
871 870
 
872
-		$intent = $this->get_intent_from_order( $order );
871
+		$intent = $this->get_intent_from_order($order);
873 872
 		$intent_cancelled = false;
874
-		if ( $intent ) {
873
+		if ($intent) {
875 874
 			// If the order has a Payment Intent pending capture, then the Intent itself must be refunded (cancelled), not the Charge
876
-			if ( ! empty( $intent->error ) ) {
875
+			if ( ! empty($intent->error)) {
877 876
 				$response = $intent;
878 877
 				$intent_cancelled = true;
879
-			} elseif ( 'requires_capture' === $intent->status ) {
878
+			} elseif ('requires_capture' === $intent->status) {
880 879
 				$result = WC_Stripe_API::request(
881 880
 					array(),
882 881
 					'payment_intents/' . $intent->id . '/cancel'
883 882
 				);
884 883
 				$intent_cancelled = true;
885 884
 
886
-				if ( ! empty( $result->error ) ) {
885
+				if ( ! empty($result->error)) {
887 886
 					$response = $result;
888 887
 				} else {
889
-					$charge = end( $result->charges->data );
890
-					$response = end( $charge->refunds->data );
888
+					$charge = end($result->charges->data);
889
+					$response = end($charge->refunds->data);
891 890
 				}
892 891
 			}
893 892
 		}
894 893
 
895
-		if ( ! $intent_cancelled ) {
896
-			$response = WC_Stripe_API::request( $request, 'refunds' );
894
+		if ( ! $intent_cancelled) {
895
+			$response = WC_Stripe_API::request($request, 'refunds');
897 896
 		}
898 897
 
899
-		if ( ! empty( $response->error ) ) {
900
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
898
+		if ( ! empty($response->error)) {
899
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
901 900
 
902 901
 			return $response;
903 902
 
904
-		} elseif ( ! empty( $response->id ) ) {
905
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id );
903
+		} elseif ( ! empty($response->id)) {
904
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id);
906 905
 
907
-			$amount = wc_price( $response->amount / 100 );
906
+			$amount = wc_price($response->amount / 100);
908 907
 
909
-			if ( in_array( strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
910
-				$amount = wc_price( $response->amount );
908
+			if (in_array(strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
909
+				$amount = wc_price($response->amount);
911 910
 			}
912 911
 
913
-			if ( isset( $response->balance_transaction ) ) {
914
-				$this->update_fees( $order, $response->balance_transaction );
912
+			if (isset($response->balance_transaction)) {
913
+				$this->update_fees($order, $response->balance_transaction);
915 914
 			}
916 915
 
917 916
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
918
-			$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' );
917
+			$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe');
919 918
 
920
-			$order->add_order_note( $refund_message );
921
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) );
919
+			$order->add_order_note($refund_message);
920
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message)));
922 921
 
923 922
 			return true;
924 923
 		}
@@ -933,46 +932,46 @@  discard block
 block discarded – undo
933 932
 	 */
934 933
 	public function add_payment_method() {
935 934
 		$error     = false;
936
-		$error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' );
935
+		$error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe');
937 936
 		$source_id = '';
938 937
 
939
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
938
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
940 939
 			$error = true;
941 940
 		}
942 941
 
943
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
942
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
944 943
 
945
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
944
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
946 945
 
947
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
946
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
948 947
 
949
-		if ( isset( $source_object ) ) {
950
-			if ( ! empty( $source_object->error ) ) {
948
+		if (isset($source_object)) {
949
+			if ( ! empty($source_object->error)) {
951 950
 				$error = true;
952 951
 			}
953 952
 
954 953
 			$source_id = $source_object->id;
955
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
956
-			$source_id = wc_clean( $_POST['stripe_token'] );
954
+		} elseif (isset($_POST['stripe_token'])) {
955
+			$source_id = wc_clean($_POST['stripe_token']);
957 956
 		}
958 957
 
959
-		$response = $stripe_customer->add_source( $source_id );
958
+		$response = $stripe_customer->add_source($source_id);
960 959
 
961
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
960
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
962 961
 			$error = true;
963 962
 		}
964 963
 
965
-		if ( $error ) {
966
-			wc_add_notice( $error_msg, 'error' );
967
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
964
+		if ($error) {
965
+			wc_add_notice($error_msg, 'error');
966
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
968 967
 			return;
969 968
 		}
970 969
 
971
-		do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object );
970
+		do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object);
972 971
 
973 972
 		return array(
974 973
 			'result'   => 'success',
975
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
974
+			'redirect' => wc_get_endpoint_url('payment-methods'),
976 975
 		);
977 976
 	}
978 977
 
@@ -989,10 +988,10 @@  discard block
 block discarded – undo
989 988
 		 * Stripe expects Norwegian to only be passed NO.
990 989
 		 * But WP has different dialects.
991 990
 		 */
992
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
991
+		if ('NO' === substr($locale, 3, 2)) {
993 992
 			$locale = 'no';
994 993
 		} else {
995
-			$locale = substr( get_locale(), 0, 2 );
994
+			$locale = substr(get_locale(), 0, 2);
996 995
 		}
997 996
 
998 997
 		return $locale;
@@ -1006,9 +1005,9 @@  discard block
 block discarded – undo
1006 1005
 	 * @param string $idempotency_key
1007 1006
 	 * @param array $request
1008 1007
 	 */
1009
-	public function change_idempotency_key( $idempotency_key, $request ) {
1010
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
1011
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
1008
+	public function change_idempotency_key($idempotency_key, $request) {
1009
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
1010
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
1012 1011
 		$count    = $this->retry_interval;
1013 1012
 
1014 1013
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
@@ -1022,8 +1021,8 @@  discard block
 block discarded – undo
1022 1021
 	 * @since 4.0.6
1023 1022
 	 * @param array $headers
1024 1023
 	 */
1025
-	public function is_original_request( $headers ) {
1026
-		if ( $headers['original-request'] === $headers['request-id'] ) {
1024
+	public function is_original_request($headers) {
1025
+		if ($headers['original-request'] === $headers['request-id']) {
1027 1026
 			return true;
1028 1027
 		}
1029 1028
 
@@ -1037,27 +1036,27 @@  discard block
 block discarded – undo
1037 1036
 	 * @param object   $prepared_source The source that is used for the payment.
1038 1037
 	 * @return array                    The arguments for the request.
1039 1038
 	 */
1040
-	public function generate_create_intent_request( $order, $prepared_source ) {
1039
+	public function generate_create_intent_request($order, $prepared_source) {
1041 1040
 		// The request for a charge contains metadata for the intent.
1042
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1041
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1043 1042
 
1044 1043
 		$request = array(
1045 1044
 			'source'               => $prepared_source->source,
1046
-			'amount'               => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
1047
-			'currency'             => strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ),
1045
+			'amount'               => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
1046
+			'currency'             => strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()),
1048 1047
 			'description'          => $full_request['description'],
1049 1048
 			'metadata'             => $full_request['metadata'],
1050
-			'capture_method'       => ( 'true' === $full_request['capture'] ) ? 'automatic' : 'manual',
1049
+			'capture_method'       => ('true' === $full_request['capture']) ? 'automatic' : 'manual',
1051 1050
 			'payment_method_types' => array(
1052 1051
 				'card',
1053 1052
 			),
1054 1053
 		);
1055 1054
 
1056
-		if ( $prepared_source->customer ) {
1055
+		if ($prepared_source->customer) {
1057 1056
 			$request['customer'] = $prepared_source->customer;
1058 1057
 		}
1059 1058
 
1060
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1059
+		if (isset($full_request['statement_descriptor'])) {
1061 1060
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1062 1061
 		}
1063 1062
 
@@ -1069,7 +1068,7 @@  discard block
 block discarded – undo
1069 1068
 		 * @param WC_Order $order
1070 1069
 		 * @param object $source
1071 1070
 		 */
1072
-		return apply_filters( 'wc_stripe_generate_create_intent_request', $request, $order, $prepared_source );
1071
+		return apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source);
1073 1072
 	}
1074 1073
 
1075 1074
 	/**
@@ -1078,27 +1077,27 @@  discard block
 block discarded – undo
1078 1077
 	 * @param WC_Order $order The order that is being paid for.
1079 1078
 	 * @return array          The level 3 data to send to Stripe.
1080 1079
 	 */
1081
-	public function get_level3_data_from_order( $order ) {
1080
+	public function get_level3_data_from_order($order) {
1082 1081
 		// WC Versions before 3.0 don't support postcodes and are
1083 1082
 		// incompatible with level3 data.
1084
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1083
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1085 1084
 			return array();
1086 1085
 		}
1087 1086
 
1088 1087
 		// Get the order items. Don't need their keys, only their values.
1089 1088
 		// Order item IDs are used as keys in the original order items array.
1090
-		$order_items = array_values( $order->get_items() );
1089
+		$order_items = array_values($order->get_items());
1091 1090
 		$currency    = $order->get_currency();
1092 1091
 
1093
-		$stripe_line_items = array_map(function( $item ) use ( $currency ) {
1092
+		$stripe_line_items = array_map(function($item) use ($currency) {
1094 1093
 			$product_id          = $item->get_variation_id()
1095 1094
 				? $item->get_variation_id()
1096 1095
 				: $item->get_product_id();
1097
-			$product_description = substr( $item->get_name(), 0, 26 );
1096
+			$product_description = substr($item->get_name(), 0, 26);
1098 1097
 			$quantity            = $item->get_quantity();
1099
-			$unit_cost           = WC_Stripe_Helper::get_stripe_amount( ( $item->get_subtotal() / $quantity ), $currency );
1100
-			$tax_amount          = WC_Stripe_Helper::get_stripe_amount( $item->get_total_tax(), $currency );
1101
-			$discount_amount     = WC_Stripe_Helper::get_stripe_amount( $item->get_subtotal() - $item->get_total(), $currency );
1098
+			$unit_cost           = WC_Stripe_Helper::get_stripe_amount(($item->get_subtotal() / $quantity), $currency);
1099
+			$tax_amount          = WC_Stripe_Helper::get_stripe_amount($item->get_total_tax(), $currency);
1100
+			$discount_amount     = WC_Stripe_Helper::get_stripe_amount($item->get_subtotal() - $item->get_total(), $currency);
1102 1101
 
1103 1102
 			return (object) array(
1104 1103
 				'product_code'        => (string) $product_id, // Up to 12 characters that uniquely identify the product.
@@ -1113,19 +1112,19 @@  discard block
 block discarded – undo
1113 1112
 		$level3_data = array(
1114 1113
 			'merchant_reference'   => $order->get_id(), // An alphanumeric string of up to  characters in length. This unique value is assigned by the merchant to identify the order. Also known as an “Order ID”.
1115 1114
 
1116
-			'shipping_amount'      => WC_Stripe_Helper::get_stripe_amount( $order->get_shipping_total() + $order->get_shipping_tax(), $currency), // The shipping cost, in cents, as a non-negative integer.
1115
+			'shipping_amount'      => WC_Stripe_Helper::get_stripe_amount($order->get_shipping_total() + $order->get_shipping_tax(), $currency), // The shipping cost, in cents, as a non-negative integer.
1117 1116
 			'line_items'           => $stripe_line_items,
1118 1117
 		);
1119 1118
 
1120 1119
 		// The customer’s U.S. shipping ZIP code.
1121 1120
 		$shipping_address_zip = $order->get_shipping_postcode();
1122
-		if ( $this->is_valid_us_zip_code( $shipping_address_zip ) ) {
1121
+		if ($this->is_valid_us_zip_code($shipping_address_zip)) {
1123 1122
 			$level3_data['shipping_address_zip'] = $shipping_address_zip;
1124 1123
 		}
1125 1124
 
1126 1125
 		// The merchant’s U.S. shipping ZIP code.
1127
-		$store_postcode = get_option( 'woocommerce_store_postcode' );
1128
-		if ( $this->is_valid_us_zip_code( $store_postcode ) ) {
1126
+		$store_postcode = get_option('woocommerce_store_postcode');
1127
+		if ($this->is_valid_us_zip_code($store_postcode)) {
1129 1128
 			$level3_data['shipping_from_zip'] = $store_postcode;
1130 1129
 		}
1131 1130
 
@@ -1139,20 +1138,20 @@  discard block
 block discarded – undo
1139 1138
 	 * @param object   $prepared_source The source that is used for the payment.
1140 1139
 	 * @return object                   An intent or an error.
1141 1140
 	 */
1142
-	public function create_intent( $order, $prepared_source ) {
1143
-		$request = $this->generate_create_intent_request( $order, $prepared_source );
1141
+	public function create_intent($order, $prepared_source) {
1142
+		$request = $this->generate_create_intent_request($order, $prepared_source);
1144 1143
 
1145 1144
 		// Create an intent that awaits an action.
1146
-		$intent = WC_Stripe_API::request( $request, 'payment_intents' );
1147
-		if ( ! empty( $intent->error ) ) {
1145
+		$intent = WC_Stripe_API::request($request, 'payment_intents');
1146
+		if ( ! empty($intent->error)) {
1148 1147
 			return $intent;
1149 1148
 		}
1150 1149
 
1151
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1152
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id initiated for order $order_id" );
1150
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1151
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id initiated for order $order_id");
1153 1152
 
1154 1153
 		// Save the intent ID to the order.
1155
-		$this->save_intent_to_order( $order, $intent );
1154
+		$this->save_intent_to_order($order, $intent);
1156 1155
 
1157 1156
 		return $intent;
1158 1157
 	}
@@ -1165,27 +1164,27 @@  discard block
 block discarded – undo
1165 1164
 	 * @param object   $prepared_source Currently selected source.
1166 1165
 	 * @return object                   An updated intent.
1167 1166
 	 */
1168
-	public function update_existing_intent( $intent, $order, $prepared_source ) {
1167
+	public function update_existing_intent($intent, $order, $prepared_source) {
1169 1168
 		$request = array();
1170 1169
 
1171
-		if ( $prepared_source->source !== $intent->source ) {
1170
+		if ($prepared_source->source !== $intent->source) {
1172 1171
 			$request['source'] = $prepared_source->source;
1173 1172
 		}
1174 1173
 
1175
-		$new_amount = WC_Stripe_Helper::get_stripe_amount( $order->get_total() );
1176
-		if ( $intent->amount !== $new_amount ) {
1174
+		$new_amount = WC_Stripe_Helper::get_stripe_amount($order->get_total());
1175
+		if ($intent->amount !== $new_amount) {
1177 1176
 			$request['amount'] = $new_amount;
1178 1177
 		}
1179 1178
 
1180
-		if ( $prepared_source->customer && $intent->customer !== $prepared_source->customer ) {
1179
+		if ($prepared_source->customer && $intent->customer !== $prepared_source->customer) {
1181 1180
 			$request['customer'] = $prepared_source->customer;
1182 1181
 		}
1183 1182
 
1184
-		if ( empty( $request ) ) {
1183
+		if (empty($request)) {
1185 1184
 			return $intent;
1186 1185
 		}
1187 1186
 
1188
-		$level3_data = $this->get_level3_data_from_order( $order );
1187
+		$level3_data = $this->get_level3_data_from_order($order);
1189 1188
 		return WC_Stripe_API::request_with_level3_data(
1190 1189
 			$request,
1191 1190
 			"payment_intents/$intent->id",
@@ -1203,8 +1202,8 @@  discard block
 block discarded – undo
1203 1202
 	 * @param object   $prepared_source The source that is being charged.
1204 1203
 	 * @return object                   Either an error or the updated intent.
1205 1204
 	 */
1206
-	public function confirm_intent( $intent, $order, $prepared_source ) {
1207
-		if ( 'requires_confirmation' !== $intent->status ) {
1205
+	public function confirm_intent($intent, $order, $prepared_source) {
1206
+		if ('requires_confirmation' !== $intent->status) {
1208 1207
 			return $intent;
1209 1208
 		}
1210 1209
 
@@ -1213,7 +1212,7 @@  discard block
 block discarded – undo
1213 1212
 			'source' => $prepared_source->source,
1214 1213
 		);
1215 1214
 
1216
-		$level3_data = $this->get_level3_data_from_order( $order );
1215
+		$level3_data = $this->get_level3_data_from_order($order);
1217 1216
 		$confirmed_intent = WC_Stripe_API::request_with_level3_data(
1218 1217
 			$confirm_request,
1219 1218
 			"payment_intents/$intent->id/confirm",
@@ -1221,16 +1220,16 @@  discard block
 block discarded – undo
1221 1220
 			$order
1222 1221
 		);
1223 1222
 
1224
-		if ( ! empty( $confirmed_intent->error ) ) {
1223
+		if ( ! empty($confirmed_intent->error)) {
1225 1224
 			return $confirmed_intent;
1226 1225
 		}
1227 1226
 
1228 1227
 		// Save a note about the status of the intent.
1229
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1230
-		if ( 'succeeded' === $confirmed_intent->status ) {
1231
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
1232
-		} elseif ( 'requires_action' === $confirmed_intent->status ) {
1233
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id requires authentication for order $order_id" );
1228
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1229
+		if ('succeeded' === $confirmed_intent->status) {
1230
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
1231
+		} elseif ('requires_action' === $confirmed_intent->status) {
1232
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id requires authentication for order $order_id");
1234 1233
 		}
1235 1234
 
1236 1235
 		return $confirmed_intent;
@@ -1243,16 +1242,16 @@  discard block
 block discarded – undo
1243 1242
 	 * @param WC_Order $order For to which the source applies.
1244 1243
 	 * @param stdClass $intent Payment intent information.
1245 1244
 	 */
1246
-	public function save_intent_to_order( $order, $intent ) {
1247
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1245
+	public function save_intent_to_order($order, $intent) {
1246
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1248 1247
 
1249
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1250
-			update_post_meta( $order_id, '_stripe_intent_id', $intent->id );
1248
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1249
+			update_post_meta($order_id, '_stripe_intent_id', $intent->id);
1251 1250
 		} else {
1252
-			$order->update_meta_data( '_stripe_intent_id', $intent->id );
1251
+			$order->update_meta_data('_stripe_intent_id', $intent->id);
1253 1252
 		}
1254 1253
 
1255
-		if ( is_callable( array( $order, 'save' ) ) ) {
1254
+		if (is_callable(array($order, 'save'))) {
1256 1255
 			$order->save();
1257 1256
 		}
1258 1257
 	}
@@ -1264,23 +1263,23 @@  discard block
 block discarded – undo
1264 1263
 	 * @param WC_Order $order The order to retrieve an intent for.
1265 1264
 	 * @return obect|bool     Either the intent object or `false`.
1266 1265
 	 */
1267
-	public function get_intent_from_order( $order ) {
1268
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1269
-			return $this->pre_3_0_get_intent_from_order( $order );
1266
+	public function get_intent_from_order($order) {
1267
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1268
+			return $this->pre_3_0_get_intent_from_order($order);
1270 1269
 		}
1271 1270
 
1272 1271
 		$order_id  = $order->get_id();
1273
-		$intent_id = $order->get_meta( '_stripe_intent_id' );
1272
+		$intent_id = $order->get_meta('_stripe_intent_id');
1274 1273
 
1275
-		if ( $intent_id ) {
1276
-			return $this->get_intent( 'payment_intents', $intent_id );
1274
+		if ($intent_id) {
1275
+			return $this->get_intent('payment_intents', $intent_id);
1277 1276
 		}
1278 1277
 
1279 1278
 		// The order doesn't have a payment intent, but it may have a setup intent.
1280
-		$intent_id = $order->get_meta( '_stripe_setup_intent' );
1279
+		$intent_id = $order->get_meta('_stripe_setup_intent');
1281 1280
 
1282
-		if ( $intent_id ) {
1283
-			return $this->get_intent( 'setup_intents', $intent_id );
1281
+		if ($intent_id) {
1282
+			return $this->get_intent('setup_intents', $intent_id);
1284 1283
 		}
1285 1284
 
1286 1285
 		return false;
@@ -1292,19 +1291,19 @@  discard block
 block discarded – undo
1292 1291
 	 * @param WC_Order $order The order to retrieve an intent for.
1293 1292
 	 * @return obect|bool     Either the intent object or `false`.
1294 1293
 	 */
1295
-	private function pre_3_0_get_intent_from_order( $order ) {
1294
+	private function pre_3_0_get_intent_from_order($order) {
1296 1295
 		$order_id  = $order->id;
1297
-		$intent_id = get_post_meta( $order_id, '_stripe_intent_id', true );
1296
+		$intent_id = get_post_meta($order_id, '_stripe_intent_id', true);
1298 1297
 
1299
-		if ( $intent_id ) {
1300
-			return $this->get_intent( 'payment_intents', $intent_id );
1298
+		if ($intent_id) {
1299
+			return $this->get_intent('payment_intents', $intent_id);
1301 1300
 		}
1302 1301
 
1303 1302
 		// The order doesn't have a payment intent, but it may have a setup intent.
1304
-		$intent_id = get_post_meta( $order_id, '_stripe_setup_intent', true );
1303
+		$intent_id = get_post_meta($order_id, '_stripe_setup_intent', true);
1305 1304
 
1306
-		if ( $intent_id ) {
1307
-			return $this->get_intent( 'setup_intents', $intent_id );
1305
+		if ($intent_id) {
1306
+			return $this->get_intent('setup_intents', $intent_id);
1308 1307
 		}
1309 1308
 
1310 1309
 		return false;
@@ -1318,15 +1317,15 @@  discard block
 block discarded – undo
1318 1317
 	 * @return object|bool 			Either the intent object or `false`.
1319 1318
 	 * @throws Exception 			Throws exception for unknown $intent_type.
1320 1319
 	 */
1321
-	private function get_intent( $intent_type, $intent_id ) {
1322
-		if ( ! in_array( $intent_type, [ 'payment_intents', 'setup_intents' ] ) ) {
1323
-			throw new Exception( "Failed to get intent of type $intent_type. Type is not allowed" );
1320
+	private function get_intent($intent_type, $intent_id) {
1321
+		if ( ! in_array($intent_type, ['payment_intents', 'setup_intents'])) {
1322
+			throw new Exception("Failed to get intent of type $intent_type. Type is not allowed");
1324 1323
 		}
1325 1324
 
1326
-		$response = WC_Stripe_API::request( array(), "$intent_type/$intent_id", 'GET' );
1325
+		$response = WC_Stripe_API::request(array(), "$intent_type/$intent_id", 'GET');
1327 1326
 
1328
-		if ( $response && isset( $response->{ 'error' } ) ) {
1329
-			$error_response_message = print_r( $response, true );
1327
+		if ($response && isset($response->{ 'error' } )) {
1328
+			$error_response_message = print_r($response, true);
1330 1329
 			WC_Stripe_Logger::log("Failed to get Stripe intent $intent_type/$intent_id.");
1331 1330
 			WC_Stripe_Logger::log("Response: $error_response_message");
1332 1331
 			return false;
@@ -1343,18 +1342,18 @@  discard block
 block discarded – undo
1343 1342
 	 * @param stdClass $intent The intent that is being processed.
1344 1343
 	 * @return bool            A flag that indicates whether the order is already locked.
1345 1344
 	 */
1346
-	public function lock_order_payment( $order, $intent = null ) {
1347
-		$order_id       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1345
+	public function lock_order_payment($order, $intent = null) {
1346
+		$order_id       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1348 1347
 		$transient_name = 'wc_stripe_processing_intent_' . $order_id;
1349
-		$processing     = get_transient( $transient_name );
1348
+		$processing     = get_transient($transient_name);
1350 1349
 
1351 1350
 		// Block the process if the same intent is already being handled.
1352
-		if ( "-1" === $processing || ( isset( $intent->id ) && $processing === $intent->id ) ) {
1351
+		if ("-1" === $processing || (isset($intent->id) && $processing === $intent->id)) {
1353 1352
 			return true;
1354 1353
 		}
1355 1354
 
1356 1355
 		// Save the new intent as a transient, eventually overwriting another one.
1357
-		set_transient( $transient_name, empty( $intent ) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS );
1356
+		set_transient($transient_name, empty($intent) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS);
1358 1357
 
1359 1358
 		return false;
1360 1359
 	}
@@ -1365,9 +1364,9 @@  discard block
 block discarded – undo
1365 1364
 	 * @since 4.2
1366 1365
 	 * @param WC_Order $order The order that is being unlocked.
1367 1366
 	 */
1368
-	public function unlock_order_payment( $order ) {
1369
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1370
-		delete_transient( 'wc_stripe_processing_intent_' . $order_id );
1367
+	public function unlock_order_payment($order) {
1368
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1369
+		delete_transient('wc_stripe_processing_intent_' . $order_id);
1371 1370
 	}
1372 1371
 
1373 1372
 	/**
@@ -1377,9 +1376,9 @@  discard block
 block discarded – undo
1377 1376
 	 * @param object $response The response from Stripe.
1378 1377
 	 * @return boolean Whether or not it's a 'authentication_required' error
1379 1378
 	 */
1380
-	public function is_authentication_required_for_payment( $response ) {
1381
-		return ( ! empty( $response->error ) && 'authentication_required' === $response->error->code )
1382
-			|| ( ! empty( $response->last_payment_error ) && 'authentication_required' === $response->last_payment_error->code );
1379
+	public function is_authentication_required_for_payment($response) {
1380
+		return ( ! empty($response->error) && 'authentication_required' === $response->error->code)
1381
+			|| ( ! empty($response->last_payment_error) && 'authentication_required' === $response->last_payment_error->code);
1383 1382
 	}
1384 1383
 
1385 1384
 	/**
@@ -1389,21 +1388,21 @@  discard block
 block discarded – undo
1389 1388
 	 * @param object   $prepared_source The source, entered/chosen by the customer.
1390 1389
 	 * @return string                   The client secret of the intent, used for confirmation in JS.
1391 1390
 	 */
1392
-	public function setup_intent( $order, $prepared_source ) {
1393
-		$order_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1394
-		$setup_intent = WC_Stripe_API::request( array(
1391
+	public function setup_intent($order, $prepared_source) {
1392
+		$order_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1393
+		$setup_intent = WC_Stripe_API::request(array(
1395 1394
 			'payment_method' => $prepared_source->source,
1396 1395
 			'customer'       => $prepared_source->customer,
1397 1396
 			'confirm'        => 'true',
1398
-		), 'setup_intents' );
1397
+		), 'setup_intents');
1399 1398
 
1400
-		if ( is_wp_error( $setup_intent ) ) {
1401
-			WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) );
1402
-		} elseif ( 'requires_action' === $setup_intent->status ) {
1403
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1404
-				update_post_meta( $order_id, '_stripe_setup_intent', $setup_intent->id );
1399
+		if (is_wp_error($setup_intent)) {
1400
+			WC_Stripe_Logger::log("Unable to create SetupIntent for Order #$order_id: " . print_r($setup_intent, true));
1401
+		} elseif ('requires_action' === $setup_intent->status) {
1402
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1403
+				update_post_meta($order_id, '_stripe_setup_intent', $setup_intent->id);
1405 1404
 			} else {
1406
-				$order->update_meta_data( '_stripe_setup_intent', $setup_intent->id );
1405
+				$order->update_meta_data('_stripe_setup_intent', $setup_intent->id);
1407 1406
 				$order->save();
1408 1407
 			}
1409 1408
 
@@ -1419,12 +1418,12 @@  discard block
 block discarded – undo
1419 1418
 	 * @param float    $amount          The amount to charge. If not specified, it will be read from the order.
1420 1419
 	 * @return object                   An intent or an error.
1421 1420
 	 */
1422
-	public function create_and_confirm_intent_for_off_session( $order, $prepared_source, $amount = NULL ) {
1421
+	public function create_and_confirm_intent_for_off_session($order, $prepared_source, $amount = NULL) {
1423 1422
 		// The request for a charge contains metadata for the intent.
1424
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1423
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1425 1424
 
1426 1425
 		$request = array(
1427
-			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount( $amount, $full_request['currency'] ) : $full_request['amount'],
1426
+			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount($amount, $full_request['currency']) : $full_request['amount'],
1428 1427
 			'currency'             => $full_request['currency'],
1429 1428
 			'description'          => $full_request['description'],
1430 1429
 			'metadata'             => $full_request['metadata'],
@@ -1436,44 +1435,44 @@  discard block
 block discarded – undo
1436 1435
 			'confirmation_method'  => 'automatic',
1437 1436
 		);
1438 1437
 
1439
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1438
+		if (isset($full_request['statement_descriptor'])) {
1440 1439
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1441 1440
 		}
1442 1441
 
1443
-		if ( isset( $full_request['customer'] ) ) {
1442
+		if (isset($full_request['customer'])) {
1444 1443
 			$request['customer'] = $full_request['customer'];
1445 1444
 		}
1446 1445
 
1447
-		if ( isset( $full_request['source'] ) ) {
1446
+		if (isset($full_request['source'])) {
1448 1447
 			$request['source'] = $full_request['source'];
1449 1448
 		}
1450 1449
 
1451
-		$level3_data = $this->get_level3_data_from_order( $order );
1450
+		$level3_data = $this->get_level3_data_from_order($order);
1452 1451
 		$intent = WC_Stripe_API::request_with_level3_data(
1453 1452
 			$request,
1454 1453
 			'payment_intents',
1455 1454
 			$level3_data,
1456 1455
 			$order
1457 1456
 		);
1458
-		$is_authentication_required = $this->is_authentication_required_for_payment( $intent );
1457
+		$is_authentication_required = $this->is_authentication_required_for_payment($intent);
1459 1458
 
1460
-		if ( ! empty( $intent->error ) && ! $is_authentication_required ) {
1459
+		if ( ! empty($intent->error) && ! $is_authentication_required) {
1461 1460
 			return $intent;
1462 1461
 		}
1463 1462
 
1464
-		$intent_id      = ( ! empty( $intent->error )
1463
+		$intent_id = ( ! empty($intent->error)
1465 1464
 			? $intent->error->payment_intent->id
1466 1465
 			: $intent->id
1467 1466
 		);
1468
-		$payment_intent = ( ! empty( $intent->error )
1467
+		$payment_intent = ( ! empty($intent->error)
1469 1468
 			? $intent->error->payment_intent
1470 1469
 			: $intent
1471 1470
 		);
1472
-		$order_id       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1473
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent_id initiated for order $order_id" );
1471
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1472
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent_id initiated for order $order_id");
1474 1473
 
1475 1474
 		// Save the intent ID to the order.
1476
-		$this->save_intent_to_order( $order, $payment_intent );
1475
+		$this->save_intent_to_order($order, $payment_intent);
1477 1476
 
1478 1477
 		return $intent;
1479 1478
 	}
@@ -1484,13 +1483,13 @@  discard block
 block discarded – undo
1484 1483
 	 * Fix renewal for existing subscriptions affected by https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1072.
1485 1484
 	 * @param int $order_id subscription renewal order id.
1486 1485
 	 */
1487
-	public function ensure_subscription_has_customer_id( $order_id ) {
1488
-		$subscriptions_ids = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'any' ) );
1489
-		foreach( $subscriptions_ids as $subscription_id => $subscription ) {
1490
-			if ( ! metadata_exists( 'post', $subscription_id, '_stripe_customer_id' ) ) {
1491
-				$stripe_customer = new WC_Stripe_Customer( $subscription->get_user_id() );
1492
-				update_post_meta( $subscription_id, '_stripe_customer_id', $stripe_customer->get_id() );
1493
-				update_post_meta( $order_id, '_stripe_customer_id', $stripe_customer->get_id() );
1486
+	public function ensure_subscription_has_customer_id($order_id) {
1487
+		$subscriptions_ids = wcs_get_subscriptions_for_order($order_id, array('order_type' => 'any'));
1488
+		foreach ($subscriptions_ids as $subscription_id => $subscription) {
1489
+			if ( ! metadata_exists('post', $subscription_id, '_stripe_customer_id')) {
1490
+				$stripe_customer = new WC_Stripe_Customer($subscription->get_user_id());
1491
+				update_post_meta($subscription_id, '_stripe_customer_id', $stripe_customer->get_id());
1492
+				update_post_meta($order_id, '_stripe_customer_id', $stripe_customer->get_id());
1494 1493
 			}
1495 1494
 		}
1496 1495
 	}
@@ -1500,7 +1499,7 @@  discard block
 block discarded – undo
1500 1499
 	 * @param string $zip The ZIP code to verify.
1501 1500
 	 * @return boolean
1502 1501
 	 */
1503
-	public function is_valid_us_zip_code( $zip ) {
1504
-		return ! empty( $zip ) && preg_match( '/^\d{5,5}(-\d{4,4})?$/', $zip );
1502
+	public function is_valid_us_zip_code($zip) {
1503
+		return ! empty($zip) && preg_match('/^\d{5,5}(-\d{4,4})?$/', $zip);
1505 1504
 	}
1506 1505
 }
Please login to merge, or discard this patch.