Completed
Pull Request — master (#1100)
by Marcin
02:05
created
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +340 added lines, -341 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
 
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 * @since 4.1.3
158 158
 	 */
159 159
 	public function is_available() {
160
-		if ( 'yes' === $this->enabled ) {
161
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
160
+		if ('yes' === $this->enabled) {
161
+			if ( ! $this->secret_key || ! $this->publishable_key) {
162 162
 				return false;
163 163
 			}
164 164
 			return true;
@@ -175,12 +175,12 @@  discard block
 block discarded – undo
175 175
 	 * @param int $order_id
176 176
 	 * @return bool
177 177
 	 */
178
-	public function maybe_process_pre_orders( $order_id ) {
178
+	public function maybe_process_pre_orders($order_id) {
179 179
 		return (
180 180
 			WC_Stripe_Helper::is_pre_orders_exists() &&
181
-			$this->pre_orders->is_pre_order( $order_id ) &&
182
-			WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) &&
183
-			! is_wc_endpoint_url( 'order-pay' )
181
+			$this->pre_orders->is_pre_order($order_id) &&
182
+			WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) &&
183
+			! is_wc_endpoint_url('order-pay')
184 184
 		);
185 185
 	}
186 186
 
@@ -224,10 +224,10 @@  discard block
 block discarded – undo
224 224
 	 * @version 4.0.0
225 225
 	 * @param object $order
226 226
 	 */
227
-	public function validate_minimum_order_amount( $order ) {
228
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
227
+	public function validate_minimum_order_amount($order) {
228
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
229 229
 			/* translators: 1) dollar amount */
230
-			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 ) ) );
230
+			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)));
231 231
 		}
232 232
 	}
233 233
 
@@ -237,14 +237,14 @@  discard block
 block discarded – undo
237 237
 	 * @since 4.0.0
238 238
 	 * @version 4.0.0
239 239
 	 */
240
-	public function get_transaction_url( $order ) {
241
-		if ( $this->testmode ) {
240
+	public function get_transaction_url($order) {
241
+		if ($this->testmode) {
242 242
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
243 243
 		} else {
244 244
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
245 245
 		}
246 246
 
247
-		return parent::get_transaction_url( $order );
247
+		return parent::get_transaction_url($order);
248 248
 	}
249 249
 
250 250
 	/**
@@ -253,15 +253,15 @@  discard block
 block discarded – undo
253 253
 	 * @since 4.0.0
254 254
 	 * @version 4.0.0
255 255
 	 */
256
-	public function get_stripe_customer_id( $order ) {
257
-		$customer = get_user_meta( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
256
+	public function get_stripe_customer_id($order) {
257
+		$customer = get_user_meta(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
258 258
 
259
-		if ( empty( $customer ) ) {
259
+		if (empty($customer)) {
260 260
 			// Try to get it via the order.
261
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
262
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
261
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
262
+				return get_post_meta($order->id, '_stripe_customer_id', true);
263 263
 			} else {
264
-				return $order->get_meta( '_stripe_customer_id', true );
264
+				return $order->get_meta('_stripe_customer_id', true);
265 265
 			}
266 266
 		} else {
267 267
 			return $customer;
@@ -278,23 +278,23 @@  discard block
 block discarded – undo
278 278
 	 * @param object $order
279 279
 	 * @param int $id Stripe session id.
280 280
 	 */
281
-	public function get_stripe_return_url( $order = null, $id = null ) {
282
-		if ( is_object( $order ) ) {
283
-			if ( empty( $id ) ) {
281
+	public function get_stripe_return_url($order = null, $id = null) {
282
+		if (is_object($order)) {
283
+			if (empty($id)) {
284 284
 				$id = uniqid();
285 285
 			}
286 286
 
287
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
287
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
288 288
 
289 289
 			$args = array(
290 290
 				'utm_nooverride' => '1',
291 291
 				'order_id'       => $order_id,
292 292
 			);
293 293
 
294
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
294
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
295 295
 		}
296 296
 
297
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
297
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
298 298
 	}
299 299
 
300 300
 	/**
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 * @param  int  $order_id
303 303
 	 * @return boolean
304 304
 	 */
305
-	public function has_subscription( $order_id ) {
306
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
305
+	public function has_subscription($order_id) {
306
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
307 307
 	}
308 308
 
309 309
 	/**
@@ -315,34 +315,33 @@  discard block
 block discarded – undo
315 315
 	 * @param  object $prepared_source
316 316
 	 * @return array()
317 317
 	 */
318
-	public function generate_payment_request( $order, $prepared_source ) {
319
-		$settings              = get_option( 'woocommerce_stripe_settings', array() );
320
-		$statement_descriptor  = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
321
-		$capture               = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
318
+	public function generate_payment_request($order, $prepared_source) {
319
+		$settings              = get_option('woocommerce_stripe_settings', array());
320
+		$statement_descriptor  = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
321
+		$capture               = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
322 322
 		$post_data             = array();
323
-		$post_data['currency'] = strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() );
324
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
323
+		$post_data['currency'] = strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency());
324
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
325 325
 		/* translators: 1) blog name 2) order number */
326
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
327
-		$billing_email            = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email();
328
-		$billing_first_name       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name();
329
-		$billing_last_name        = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name();
326
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
327
+		$billing_email            = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email();
328
+		$billing_first_name       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name();
329
+		$billing_last_name        = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name();
330 330
 
331
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
331
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
332 332
 			$post_data['receipt_email'] = $billing_email;
333 333
 		}
334 334
 
335
-		switch ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) {
336
-			case 'stripe':
337
-				if ( ! empty( $statement_descriptor ) ) {
338
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
335
+		switch (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method()) {
336
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
337
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
339 338
 				}
340 339
 
341 340
 				$post_data['capture'] = $capture ? 'true' : 'false';
342 341
 				break;
343 342
 			case 'stripe_sepa':
344
-				if ( ! empty( $statement_descriptor ) ) {
345
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
343
+				if ( ! empty($statement_descriptor)) {
344
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
346 345
 				}
347 346
 				break;
348 347
 		}
@@ -350,25 +349,25 @@  discard block
 block discarded – undo
350 349
 		$post_data['expand[]'] = 'balance_transaction';
351 350
 
352 351
 		$metadata = array(
353
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
354
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
352
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
353
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
355 354
 			'order_id' => $order->get_order_number(),
356 355
 		);
357 356
 
358
-		if ( $this->has_subscription( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id() ) ) {
357
+		if ($this->has_subscription(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id())) {
359 358
 			$metadata += array(
360 359
 				'payment_type' => 'recurring',
361
-				'site_url'     => esc_url( get_site_url() ),
360
+				'site_url'     => esc_url(get_site_url()),
362 361
 			);
363 362
 		}
364 363
 
365
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source );
364
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source);
366 365
 
367
-		if ( $prepared_source->customer ) {
366
+		if ($prepared_source->customer) {
368 367
 			$post_data['customer'] = $prepared_source->customer;
369 368
 		}
370 369
 
371
-		if ( $prepared_source->source ) {
370
+		if ($prepared_source->source) {
372 371
 			$post_data['source'] = $prepared_source->source;
373 372
 		}
374 373
 
@@ -380,72 +379,72 @@  discard block
 block discarded – undo
380 379
 		 * @param WC_Order $order
381 380
 		 * @param object $source
382 381
 		 */
383
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source );
382
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source);
384 383
 	}
385 384
 
386 385
 	/**
387 386
 	 * Store extra meta data for an order from a Stripe Response.
388 387
 	 */
389
-	public function process_response( $response, $order ) {
390
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
388
+	public function process_response($response, $order) {
389
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
391 390
 
392
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
393
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
391
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
392
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
394 393
 
395 394
 		// Store charge data.
396
-		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 );
395
+		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);
397 396
 
398
-		if ( isset( $response->balance_transaction ) ) {
399
-			$this->update_fees( $order, is_string( $response->balance_transaction ) ? $response->balance_transaction : $response->balance_transaction->id );
397
+		if (isset($response->balance_transaction)) {
398
+			$this->update_fees($order, is_string($response->balance_transaction) ? $response->balance_transaction : $response->balance_transaction->id);
400 399
 		}
401 400
 
402
-		if ( 'yes' === $captured ) {
401
+		if ('yes' === $captured) {
403 402
 			/**
404 403
 			 * Charge can be captured but in a pending state. Payment methods
405 404
 			 * that are asynchronous may take couple days to clear. Webhook will
406 405
 			 * take care of the status changes.
407 406
 			 */
408
-			if ( 'pending' === $response->status ) {
409
-				$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 );
407
+			if ('pending' === $response->status) {
408
+				$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);
410 409
 
411
-				if ( ! $order_stock_reduced ) {
412
-					WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
410
+				if ( ! $order_stock_reduced) {
411
+					WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
413 412
 				}
414 413
 
415
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
414
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
416 415
 				/* translators: transaction id */
417
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
416
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
418 417
 			}
419 418
 
420
-			if ( 'succeeded' === $response->status ) {
421
-				$order->payment_complete( $response->id );
419
+			if ('succeeded' === $response->status) {
420
+				$order->payment_complete($response->id);
422 421
 
423 422
 				/* translators: transaction id */
424
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
425
-				$order->add_order_note( $message );
423
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
424
+				$order->add_order_note($message);
426 425
 			}
427 426
 
428
-			if ( 'failed' === $response->status ) {
429
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
430
-				$order->add_order_note( $localized_message );
431
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
427
+			if ('failed' === $response->status) {
428
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
429
+				$order->add_order_note($localized_message);
430
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
432 431
 			}
433 432
 		} else {
434
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
433
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
435 434
 
436
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
437
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
435
+			if ($order->has_status(array('pending', 'failed'))) {
436
+				WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
438 437
 			}
439 438
 
440 439
 			/* translators: transaction id */
441
-			$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 ) );
440
+			$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));
442 441
 		}
443 442
 
444
-		if ( is_callable( array( $order, 'save' ) ) ) {
443
+		if (is_callable(array($order, 'save'))) {
445 444
 			$order->save();
446 445
 		}
447 446
 
448
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
447
+		do_action('wc_gateway_stripe_process_response', $response, $order);
449 448
 
450 449
 		return $response;
451 450
 	}
@@ -458,10 +457,10 @@  discard block
 block discarded – undo
458 457
 	 * @param int $order_id
459 458
 	 * @return null
460 459
 	 */
461
-	public function send_failed_order_email( $order_id ) {
460
+	public function send_failed_order_email($order_id) {
462 461
 		$emails = WC()->mailer()->get_emails();
463
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
464
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
462
+		if ( ! empty($emails) && ! empty($order_id)) {
463
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
465 464
 		}
466 465
 	}
467 466
 
@@ -473,36 +472,36 @@  discard block
 block discarded – undo
473 472
 	 * @param object $order
474 473
 	 * @return object $details
475 474
 	 */
476
-	public function get_owner_details( $order ) {
477
-		$billing_first_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name();
478
-		$billing_last_name  = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name();
475
+	public function get_owner_details($order) {
476
+		$billing_first_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name();
477
+		$billing_last_name  = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name();
479 478
 
480 479
 		$details = array();
481 480
 
482 481
 		$name  = $billing_first_name . ' ' . $billing_last_name;
483
-		$email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email();
484
-		$phone = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_phone : $order->get_billing_phone();
482
+		$email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email();
483
+		$phone = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_phone : $order->get_billing_phone();
485 484
 
486
-		if ( ! empty( $phone ) ) {
485
+		if ( ! empty($phone)) {
487 486
 			$details['phone'] = $phone;
488 487
 		}
489 488
 
490
-		if ( ! empty( $name ) ) {
489
+		if ( ! empty($name)) {
491 490
 			$details['name'] = $name;
492 491
 		}
493 492
 
494
-		if ( ! empty( $email ) ) {
493
+		if ( ! empty($email)) {
495 494
 			$details['email'] = $email;
496 495
 		}
497 496
 
498
-		$details['address']['line1']       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_1 : $order->get_billing_address_1();
499
-		$details['address']['line2']       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_2 : $order->get_billing_address_2();
500
-		$details['address']['state']       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_state : $order->get_billing_state();
501
-		$details['address']['city']        = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_city : $order->get_billing_city();
502
-		$details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_postcode : $order->get_billing_postcode();
503
-		$details['address']['country']     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country();
497
+		$details['address']['line1']       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_1 : $order->get_billing_address_1();
498
+		$details['address']['line2']       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_2 : $order->get_billing_address_2();
499
+		$details['address']['state']       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_state : $order->get_billing_state();
500
+		$details['address']['city']        = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_city : $order->get_billing_city();
501
+		$details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_postcode : $order->get_billing_postcode();
502
+		$details['address']['country']     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country();
504 503
 
505
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
504
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
506 505
 	}
507 506
 
508 507
 	/**
@@ -511,15 +510,15 @@  discard block
 block discarded – undo
511 510
 	 * @since 4.0.3
512 511
 	 * @param string $source_id The source ID to get source object for.
513 512
 	 */
514
-	public function get_source_object( $source_id = '' ) {
515
-		if ( empty( $source_id ) ) {
513
+	public function get_source_object($source_id = '') {
514
+		if (empty($source_id)) {
516 515
 			return '';
517 516
 		}
518 517
 
519
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
518
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
520 519
 
521
-		if ( ! empty( $source_object->error ) ) {
522
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
520
+		if ( ! empty($source_object->error)) {
521
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
523 522
 		}
524 523
 
525 524
 		return $source_object;
@@ -532,10 +531,10 @@  discard block
 block discarded – undo
532 531
 	 * @param object $source_object
533 532
 	 * @return bool
534 533
 	 */
535
-	public function is_prepaid_card( $source_object ) {
534
+	public function is_prepaid_card($source_object) {
536 535
 		return (
537 536
 			$source_object
538
-			&& ( 'token' === $source_object->object || 'source' === $source_object->object )
537
+			&& ('token' === $source_object->object || 'source' === $source_object->object)
539 538
 			&& 'prepaid' === $source_object->card->funding
540 539
 		);
541 540
 	}
@@ -547,8 +546,8 @@  discard block
 block discarded – undo
547 546
 	 * @param string $source_id
548 547
 	 * @return bool
549 548
 	 */
550
-	public function is_type_legacy_card( $source_id ) {
551
-		return ( preg_match( '/^card_/', $source_id ) );
549
+	public function is_type_legacy_card($source_id) {
550
+		return (preg_match('/^card_/', $source_id));
552 551
 	}
553 552
 
554 553
 	/**
@@ -558,9 +557,9 @@  discard block
 block discarded – undo
558 557
 	 * @return bool
559 558
 	 */
560 559
 	public function is_using_saved_payment_method() {
561
-		$payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
560
+		$payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
562 561
 
563
-		return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
562
+		return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']);
564 563
 	}
565 564
 
566 565
 	/**
@@ -576,64 +575,64 @@  discard block
 block discarded – undo
576 575
 	 * @throws Exception When card was not added or for and invalid card.
577 576
 	 * @return object
578 577
 	 */
579
-	public function prepare_source( $user_id, $force_save_source = false, $existing_customer_id = null ) {
580
-		$customer = new WC_Stripe_Customer( $user_id );
581
-		if ( ! empty( $existing_customer_id ) ) {
582
-			$customer->set_id( $existing_customer_id );
578
+	public function prepare_source($user_id, $force_save_source = false, $existing_customer_id = null) {
579
+		$customer = new WC_Stripe_Customer($user_id);
580
+		if ( ! empty($existing_customer_id)) {
581
+			$customer->set_id($existing_customer_id);
583 582
 		}
584 583
 
585
-		$force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
584
+		$force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
586 585
 		$source_object     = '';
587 586
 		$source_id         = '';
588 587
 		$wc_token_id       = false;
589
-		$payment_method    = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
588
+		$payment_method    = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
590 589
 		$is_token          = false;
591 590
 
592 591
 		// New CC info was entered and we have a new source to process.
593
-		if ( ! empty( $_POST['stripe_source'] ) ) {
594
-			$source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) );
592
+		if ( ! empty($_POST['stripe_source'])) {
593
+			$source_object = self::get_source_object(wc_clean($_POST['stripe_source']));
595 594
 			$source_id     = $source_object->id;
596 595
 
597 596
 			// This checks to see if customer opted to save the payment method to file.
598
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
597
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
599 598
 
600 599
 			/**
601 600
 			 * This is true if the user wants to store the card to their account.
602 601
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
603 602
 			 * actually reusable. Either that or force_save_source is true.
604 603
 			 */
605
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
606
-				$response = $customer->add_source( $source_object->id );
604
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
605
+				$response = $customer->add_source($source_object->id);
607 606
 
608
-				if ( ! empty( $response->error ) ) {
609
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
607
+				if ( ! empty($response->error)) {
608
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
610 609
 				}
611 610
 			}
612
-		} elseif ( $this->is_using_saved_payment_method() ) {
611
+		} elseif ($this->is_using_saved_payment_method()) {
613 612
 			// Use an existing token, and then process the payment.
614
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
615
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
613
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
614
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
616 615
 
617
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
618
-				WC()->session->set( 'refresh_totals', true );
619
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
616
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
617
+				WC()->session->set('refresh_totals', true);
618
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
620 619
 			}
621 620
 
622 621
 			$source_id = $wc_token->get_token();
623 622
 
624
-			if ( $this->is_type_legacy_card( $source_id ) ) {
623
+			if ($this->is_type_legacy_card($source_id)) {
625 624
 				$is_token = true;
626 625
 			}
627
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
628
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
629
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
626
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
627
+			$stripe_token     = wc_clean($_POST['stripe_token']);
628
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
630 629
 
631 630
 			// This is true if the user wants to store the card to their account.
632
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
633
-				$response = $customer->add_source( $stripe_token );
631
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
632
+				$response = $customer->add_source($stripe_token);
634 633
 
635
-				if ( ! empty( $response->error ) ) {
636
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
634
+				if ( ! empty($response->error)) {
635
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
637 636
 				}
638 637
 			} else {
639 638
 				$source_id    = $stripe_token;
@@ -642,15 +641,15 @@  discard block
 block discarded – undo
642 641
 		}
643 642
 
644 643
 		$customer_id = $customer->get_id();
645
-		if ( ! $customer_id ) {
646
-			$customer->set_id( $customer->create_customer() );
644
+		if ( ! $customer_id) {
645
+			$customer->set_id($customer->create_customer());
647 646
 			$customer_id = $customer->get_id();
648 647
 		} else {
649 648
 			$customer->update_customer();
650 649
 		}
651 650
 
652
-		if ( empty( $source_object ) && ! $is_token ) {
653
-			$source_object = self::get_source_object( $source_id );
651
+		if (empty($source_object) && ! $is_token) {
652
+			$source_object = self::get_source_object($source_id);
654 653
 		}
655 654
 
656 655
 		return (object) array(
@@ -674,39 +673,39 @@  discard block
 block discarded – undo
674 673
 	 * @param object $order
675 674
 	 * @return object
676 675
 	 */
677
-	public function prepare_order_source( $order = null ) {
676
+	public function prepare_order_source($order = null) {
678 677
 		$stripe_customer = new WC_Stripe_Customer();
679 678
 		$stripe_source   = false;
680 679
 		$token_id        = false;
681 680
 		$source_object   = false;
682 681
 
683
-		if ( $order ) {
684
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
682
+		if ($order) {
683
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
685 684
 
686
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
685
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
687 686
 
688
-			if ( $stripe_customer_id ) {
689
-				$stripe_customer->set_id( $stripe_customer_id );
687
+			if ($stripe_customer_id) {
688
+				$stripe_customer->set_id($stripe_customer_id);
690 689
 			}
691 690
 
692
-			$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 );
691
+			$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);
693 692
 
694 693
 			// Since 4.0.0, we changed card to source so we need to account for that.
695
-			if ( empty( $source_id ) ) {
696
-				$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 );
694
+			if (empty($source_id)) {
695
+				$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);
697 696
 
698 697
 				// Take this opportunity to update the key name.
699
-				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 );
698
+				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);
700 699
 
701
-				if ( is_callable( array( $order, 'save' ) ) ) {
700
+				if (is_callable(array($order, 'save'))) {
702 701
 					$order->save();
703 702
 				}
704 703
 			}
705 704
 
706
-			if ( $source_id ) {
705
+			if ($source_id) {
707 706
 				$stripe_source = $source_id;
708
-				$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
709
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
707
+				$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
708
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
710 709
 				/*
711 710
 				 * We can attempt to charge the customer's default source
712 711
 				 * by sending empty source id.
@@ -731,27 +730,27 @@  discard block
 block discarded – undo
731 730
 	 * @param WC_Order $order For to which the source applies.
732 731
 	 * @param stdClass $source Source information.
733 732
 	 */
734
-	public function save_source_to_order( $order, $source ) {
735
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
733
+	public function save_source_to_order($order, $source) {
734
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
736 735
 
737 736
 		// Store source in the order.
738
-		if ( $source->customer ) {
739
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
740
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
737
+		if ($source->customer) {
738
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
739
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
741 740
 			} else {
742
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
741
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
743 742
 			}
744 743
 		}
745 744
 
746
-		if ( $source->source ) {
747
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
748
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
745
+		if ($source->source) {
746
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
747
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
749 748
 			} else {
750
-				$order->update_meta_data( '_stripe_source_id', $source->source );
749
+				$order->update_meta_data('_stripe_source_id', $source->source);
751 750
 			}
752 751
 		}
753 752
 
754
-		if ( is_callable( array( $order, 'save' ) ) ) {
753
+		if (is_callable(array($order, 'save'))) {
755 754
 			$order->save();
756 755
 		}
757 756
 	}
@@ -765,38 +764,38 @@  discard block
 block discarded – undo
765 764
 	 * @param object $order The order object
766 765
 	 * @param int $balance_transaction_id
767 766
 	 */
768
-	public function update_fees( $order, $balance_transaction_id ) {
769
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
767
+	public function update_fees($order, $balance_transaction_id) {
768
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
770 769
 
771
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
770
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
772 771
 
773
-		if ( empty( $balance_transaction->error ) ) {
774
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
772
+		if (empty($balance_transaction->error)) {
773
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
775 774
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
776 775
 				// values are in the local currency of the Stripe account, not from WC.
777
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
778
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
776
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
777
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
779 778
 
780 779
 				// Current data fee & net.
781
-				$fee_current = WC_Stripe_Helper::get_stripe_fee( $order );
782
-				$net_current = WC_Stripe_Helper::get_stripe_net( $order );
780
+				$fee_current = WC_Stripe_Helper::get_stripe_fee($order);
781
+				$net_current = WC_Stripe_Helper::get_stripe_net($order);
783 782
 
784 783
 				// Calculation.
785 784
 				$fee = (float) $fee_current + (float) $fee_refund;
786 785
 				$net = (float) $net_current + (float) $net_refund;
787 786
 
788
-				WC_Stripe_Helper::update_stripe_fee( $order, $fee );
789
-				WC_Stripe_Helper::update_stripe_net( $order, $net );
787
+				WC_Stripe_Helper::update_stripe_fee($order, $fee);
788
+				WC_Stripe_Helper::update_stripe_net($order, $net);
790 789
 
791
-				$currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null;
792
-				WC_Stripe_Helper::update_stripe_currency( $order, $currency );
790
+				$currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null;
791
+				WC_Stripe_Helper::update_stripe_currency($order, $currency);
793 792
 
794
-				if ( is_callable( array( $order, 'save' ) ) ) {
793
+				if (is_callable(array($order, 'save'))) {
795 794
 					$order->save();
796 795
 				}
797 796
 			}
798 797
 		} else {
799
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
798
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
800 799
 		}
801 800
 	}
802 801
 
@@ -809,99 +808,99 @@  discard block
 block discarded – undo
809 808
 	 * @param  float $amount
810 809
 	 * @return bool
811 810
 	 */
812
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
813
-		$order = wc_get_order( $order_id );
811
+	public function process_refund($order_id, $amount = null, $reason = '') {
812
+		$order = wc_get_order($order_id);
814 813
 
815
-		if ( ! $order ) {
814
+		if ( ! $order) {
816 815
 			return false;
817 816
 		}
818 817
 
819 818
 		$request = array();
820 819
 
821
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
822
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
823
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
824
-			$charge_id      = get_post_meta( $order_id, '_transaction_id', true );
820
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
821
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
822
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
823
+			$charge_id      = get_post_meta($order_id, '_transaction_id', true);
825 824
 		} else {
826 825
 			$order_currency = $order->get_currency();
827
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
826
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
828 827
 			$charge_id      = $order->get_transaction_id();
829 828
 		}
830 829
 
831
-		if ( ! $charge_id ) {
830
+		if ( ! $charge_id) {
832 831
 			return false;
833 832
 		}
834 833
 
835
-		if ( ! is_null( $amount ) ) {
836
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
834
+		if ( ! is_null($amount)) {
835
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
837 836
 		}
838 837
 
839 838
 		// If order is only authorized, don't pass amount.
840
-		if ( 'yes' !== $captured ) {
841
-			unset( $request['amount'] );
839
+		if ('yes' !== $captured) {
840
+			unset($request['amount']);
842 841
 		}
843 842
 
844
-		if ( $reason ) {
843
+		if ($reason) {
845 844
 			$request['metadata'] = array(
846 845
 				'reason' => $reason,
847 846
 			);
848 847
 		}
849 848
 
850 849
 		$request['charge'] = $charge_id;
851
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$charge_id} for the amount of {$amount}" );
850
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$charge_id} for the amount of {$amount}");
852 851
 
853
-		$request = apply_filters( 'wc_stripe_refund_request', $request, $order );
852
+		$request = apply_filters('wc_stripe_refund_request', $request, $order);
854 853
 
855
-		$intent = $this->get_intent_from_order( $order );
854
+		$intent = $this->get_intent_from_order($order);
856 855
 		$intent_cancelled = false;
857
-		if ( $intent ) {
856
+		if ($intent) {
858 857
 			// If the order has a Payment Intent pending capture, then the Intent itself must be refunded (cancelled), not the Charge
859
-			if ( ! empty( $intent->error ) ) {
858
+			if ( ! empty($intent->error)) {
860 859
 				$response = $intent;
861 860
 				$intent_cancelled = true;
862
-			} elseif ( 'requires_capture' === $intent->status ) {
861
+			} elseif ('requires_capture' === $intent->status) {
863 862
 				$result = WC_Stripe_API::request(
864 863
 					array(),
865 864
 					'payment_intents/' . $intent->id . '/cancel'
866 865
 				);
867 866
 				$intent_cancelled = true;
868 867
 
869
-				if ( ! empty( $result->error ) ) {
868
+				if ( ! empty($result->error)) {
870 869
 					$response = $result;
871 870
 				} else {
872
-					$charge = end( $result->charges->data );
873
-					$response = end( $charge->refunds->data );
871
+					$charge = end($result->charges->data);
872
+					$response = end($charge->refunds->data);
874 873
 				}
875 874
 			}
876 875
 		}
877 876
 
878
-		if ( ! $intent_cancelled ) {
879
-			$response = WC_Stripe_API::request( $request, 'refunds' );
877
+		if ( ! $intent_cancelled) {
878
+			$response = WC_Stripe_API::request($request, 'refunds');
880 879
 		}
881 880
 
882
-		if ( ! empty( $response->error ) ) {
883
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
881
+		if ( ! empty($response->error)) {
882
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
884 883
 
885 884
 			return $response;
886 885
 
887
-		} elseif ( ! empty( $response->id ) ) {
888
-			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 );
886
+		} elseif ( ! empty($response->id)) {
887
+			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);
889 888
 
890
-			$amount = wc_price( $response->amount / 100 );
889
+			$amount = wc_price($response->amount / 100);
891 890
 
892
-			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() ) ) {
893
-				$amount = wc_price( $response->amount );
891
+			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())) {
892
+				$amount = wc_price($response->amount);
894 893
 			}
895 894
 
896
-			if ( isset( $response->balance_transaction ) ) {
897
-				$this->update_fees( $order, $response->balance_transaction );
895
+			if (isset($response->balance_transaction)) {
896
+				$this->update_fees($order, $response->balance_transaction);
898 897
 			}
899 898
 
900 899
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
901
-			$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' );
900
+			$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');
902 901
 
903
-			$order->add_order_note( $refund_message );
904
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) );
902
+			$order->add_order_note($refund_message);
903
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message)));
905 904
 
906 905
 			return true;
907 906
 		}
@@ -916,46 +915,46 @@  discard block
 block discarded – undo
916 915
 	 */
917 916
 	public function add_payment_method() {
918 917
 		$error     = false;
919
-		$error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' );
918
+		$error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe');
920 919
 		$source_id = '';
921 920
 
922
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
921
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
923 922
 			$error = true;
924 923
 		}
925 924
 
926
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
925
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
927 926
 
928
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
927
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
929 928
 
930
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
929
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
931 930
 
932
-		if ( isset( $source_object ) ) {
933
-			if ( ! empty( $source_object->error ) ) {
931
+		if (isset($source_object)) {
932
+			if ( ! empty($source_object->error)) {
934 933
 				$error = true;
935 934
 			}
936 935
 
937 936
 			$source_id = $source_object->id;
938
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
939
-			$source_id = wc_clean( $_POST['stripe_token'] );
937
+		} elseif (isset($_POST['stripe_token'])) {
938
+			$source_id = wc_clean($_POST['stripe_token']);
940 939
 		}
941 940
 
942
-		$response = $stripe_customer->add_source( $source_id );
941
+		$response = $stripe_customer->add_source($source_id);
943 942
 
944
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
943
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
945 944
 			$error = true;
946 945
 		}
947 946
 
948
-		if ( $error ) {
949
-			wc_add_notice( $error_msg, 'error' );
950
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
947
+		if ($error) {
948
+			wc_add_notice($error_msg, 'error');
949
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
951 950
 			return;
952 951
 		}
953 952
 
954
-		do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object );
953
+		do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object);
955 954
 
956 955
 		return array(
957 956
 			'result'   => 'success',
958
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
957
+			'redirect' => wc_get_endpoint_url('payment-methods'),
959 958
 		);
960 959
 	}
961 960
 
@@ -972,10 +971,10 @@  discard block
 block discarded – undo
972 971
 		 * Stripe expects Norwegian to only be passed NO.
973 972
 		 * But WP has different dialects.
974 973
 		 */
975
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
974
+		if ('NO' === substr($locale, 3, 2)) {
976 975
 			$locale = 'no';
977 976
 		} else {
978
-			$locale = substr( get_locale(), 0, 2 );
977
+			$locale = substr(get_locale(), 0, 2);
979 978
 		}
980 979
 
981 980
 		return $locale;
@@ -989,9 +988,9 @@  discard block
 block discarded – undo
989 988
 	 * @param string $idempotency_key
990 989
 	 * @param array $request
991 990
 	 */
992
-	public function change_idempotency_key( $idempotency_key, $request ) {
993
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
994
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
991
+	public function change_idempotency_key($idempotency_key, $request) {
992
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
993
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
995 994
 		$count    = $this->retry_interval;
996 995
 
997 996
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
@@ -1005,8 +1004,8 @@  discard block
 block discarded – undo
1005 1004
 	 * @since 4.0.6
1006 1005
 	 * @param array $headers
1007 1006
 	 */
1008
-	public function is_original_request( $headers ) {
1009
-		if ( $headers['original-request'] === $headers['request-id'] ) {
1007
+	public function is_original_request($headers) {
1008
+		if ($headers['original-request'] === $headers['request-id']) {
1010 1009
 			return true;
1011 1010
 		}
1012 1011
 
@@ -1020,27 +1019,27 @@  discard block
 block discarded – undo
1020 1019
 	 * @param object   $prepared_source The source that is used for the payment.
1021 1020
 	 * @return array                    The arguments for the request.
1022 1021
 	 */
1023
-	public function generate_create_intent_request( $order, $prepared_source ) {
1022
+	public function generate_create_intent_request($order, $prepared_source) {
1024 1023
 		// The request for a charge contains metadata for the intent.
1025
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1024
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1026 1025
 
1027 1026
 		$request = array(
1028 1027
 			'source'               => $prepared_source->source,
1029
-			'amount'               => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
1030
-			'currency'             => strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ),
1028
+			'amount'               => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
1029
+			'currency'             => strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()),
1031 1030
 			'description'          => $full_request['description'],
1032 1031
 			'metadata'             => $full_request['metadata'],
1033
-			'capture_method'       => ( 'true' === $full_request['capture'] ) ? 'automatic' : 'manual',
1032
+			'capture_method'       => ('true' === $full_request['capture']) ? 'automatic' : 'manual',
1034 1033
 			'payment_method_types' => array(
1035 1034
 				'card',
1036 1035
 			),
1037 1036
 		);
1038 1037
 
1039
-		if ( $prepared_source->customer ) {
1038
+		if ($prepared_source->customer) {
1040 1039
 			$request['customer'] = $prepared_source->customer;
1041 1040
 		}
1042 1041
 
1043
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1042
+		if (isset($full_request['statement_descriptor'])) {
1044 1043
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1045 1044
 		}
1046 1045
 
@@ -1052,7 +1051,7 @@  discard block
 block discarded – undo
1052 1051
 		 * @param WC_Order $order
1053 1052
 		 * @param object $source
1054 1053
 		 */
1055
-		return apply_filters( 'wc_stripe_generate_create_intent_request', $request, $order, $prepared_source );
1054
+		return apply_filters('wc_stripe_generate_create_intent_request', $request, $order, $prepared_source);
1056 1055
 	}
1057 1056
 
1058 1057
 	/**
@@ -1062,20 +1061,20 @@  discard block
 block discarded – undo
1062 1061
 	 * @param object   $prepared_source The source that is used for the payment.
1063 1062
 	 * @return object                   An intent or an error.
1064 1063
 	 */
1065
-	public function create_intent( $order, $prepared_source ) {
1066
-		$request = $this->generate_create_intent_request( $order, $prepared_source );
1064
+	public function create_intent($order, $prepared_source) {
1065
+		$request = $this->generate_create_intent_request($order, $prepared_source);
1067 1066
 
1068 1067
 		// Create an intent that awaits an action.
1069
-		$intent = WC_Stripe_API::request( $request, 'payment_intents' );
1070
-		if ( ! empty( $intent->error ) ) {
1068
+		$intent = WC_Stripe_API::request($request, 'payment_intents');
1069
+		if ( ! empty($intent->error)) {
1071 1070
 			return $intent;
1072 1071
 		}
1073 1072
 
1074
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1075
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id initiated for order $order_id" );
1073
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1074
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id initiated for order $order_id");
1076 1075
 
1077 1076
 		// Save the intent ID to the order.
1078
-		$this->save_intent_to_order( $order, $intent );
1077
+		$this->save_intent_to_order($order, $intent);
1079 1078
 
1080 1079
 		return $intent;
1081 1080
 	}
@@ -1088,27 +1087,27 @@  discard block
 block discarded – undo
1088 1087
 	 * @param object   $prepared_source Currently selected source.
1089 1088
 	 * @return object                   An updated intent.
1090 1089
 	 */
1091
-	public function update_existing_intent( $intent, $order, $prepared_source ) {
1090
+	public function update_existing_intent($intent, $order, $prepared_source) {
1092 1091
 		$request = array();
1093 1092
 
1094
-		if ( $prepared_source->source !== $intent->source ) {
1093
+		if ($prepared_source->source !== $intent->source) {
1095 1094
 			$request['source'] = $prepared_source->source;
1096 1095
 		}
1097 1096
 
1098
-		$new_amount = WC_Stripe_Helper::get_stripe_amount( $order->get_total() );
1099
-		if ( $intent->amount !== $new_amount ) {
1097
+		$new_amount = WC_Stripe_Helper::get_stripe_amount($order->get_total());
1098
+		if ($intent->amount !== $new_amount) {
1100 1099
 			$request['amount'] = $new_amount;
1101 1100
 		}
1102 1101
 
1103
-		if ( $prepared_source->customer && $intent->customer !== $prepared_source->customer ) {
1102
+		if ($prepared_source->customer && $intent->customer !== $prepared_source->customer) {
1104 1103
 			$request['customer'] = $prepared_source->customer;
1105 1104
 		}
1106 1105
 
1107
-		if ( empty( $request ) ) {
1106
+		if (empty($request)) {
1108 1107
 			return $intent;
1109 1108
 		}
1110 1109
 
1111
-		return WC_Stripe_API::request( $request, "payment_intents/$intent->id" );
1110
+		return WC_Stripe_API::request($request, "payment_intents/$intent->id");
1112 1111
 	}
1113 1112
 
1114 1113
 	/**
@@ -1120,8 +1119,8 @@  discard block
 block discarded – undo
1120 1119
 	 * @param object   $prepared_source The source that is being charged.
1121 1120
 	 * @return object                   Either an error or the updated intent.
1122 1121
 	 */
1123
-	public function confirm_intent( $intent, $order, $prepared_source ) {
1124
-		if ( 'requires_confirmation' !== $intent->status ) {
1122
+	public function confirm_intent($intent, $order, $prepared_source) {
1123
+		if ('requires_confirmation' !== $intent->status) {
1125 1124
 			return $intent;
1126 1125
 		}
1127 1126
 
@@ -1130,18 +1129,18 @@  discard block
 block discarded – undo
1130 1129
 			'source' => $prepared_source->source,
1131 1130
 		);
1132 1131
 
1133
-		$confirmed_intent = WC_Stripe_API::request( $confirm_request, "payment_intents/$intent->id/confirm" );
1132
+		$confirmed_intent = WC_Stripe_API::request($confirm_request, "payment_intents/$intent->id/confirm");
1134 1133
 
1135
-		if ( ! empty( $confirmed_intent->error ) ) {
1134
+		if ( ! empty($confirmed_intent->error)) {
1136 1135
 			return $confirmed_intent;
1137 1136
 		}
1138 1137
 
1139 1138
 		// Save a note about the status of the intent.
1140
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1141
-		if ( 'succeeded' === $confirmed_intent->status ) {
1142
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
1143
-		} elseif ( 'requires_action' === $confirmed_intent->status ) {
1144
-			WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id requires authentication for order $order_id" );
1139
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1140
+		if ('succeeded' === $confirmed_intent->status) {
1141
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id");
1142
+		} elseif ('requires_action' === $confirmed_intent->status) {
1143
+			WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id requires authentication for order $order_id");
1145 1144
 		}
1146 1145
 
1147 1146
 		return $confirmed_intent;
@@ -1154,16 +1153,16 @@  discard block
 block discarded – undo
1154 1153
 	 * @param WC_Order $order For to which the source applies.
1155 1154
 	 * @param stdClass $intent Payment intent information.
1156 1155
 	 */
1157
-	public function save_intent_to_order( $order, $intent ) {
1158
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1156
+	public function save_intent_to_order($order, $intent) {
1157
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1159 1158
 
1160
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1161
-			update_post_meta( $order_id, '_stripe_intent_id', $intent->id );
1159
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1160
+			update_post_meta($order_id, '_stripe_intent_id', $intent->id);
1162 1161
 		} else {
1163
-			$order->update_meta_data( '_stripe_intent_id', $intent->id );
1162
+			$order->update_meta_data('_stripe_intent_id', $intent->id);
1164 1163
 		}
1165 1164
 
1166
-		if ( is_callable( array( $order, 'save' ) ) ) {
1165
+		if (is_callable(array($order, 'save'))) {
1167 1166
 			$order->save();
1168 1167
 		}
1169 1168
 	}
@@ -1175,28 +1174,28 @@  discard block
 block discarded – undo
1175 1174
 	 * @param WC_Order $order The order to retrieve an intent for.
1176 1175
 	 * @return obect|bool     Either the intent object or `false`.
1177 1176
 	 */
1178
-	public function get_intent_from_order( $order ) {
1179
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1177
+	public function get_intent_from_order($order) {
1178
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1180 1179
 
1181
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1182
-			$intent_id = get_post_meta( $order_id, '_stripe_intent_id', true );
1180
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1181
+			$intent_id = get_post_meta($order_id, '_stripe_intent_id', true);
1183 1182
 		} else {
1184
-			$intent_id = $order->get_meta( '_stripe_intent_id' );
1183
+			$intent_id = $order->get_meta('_stripe_intent_id');
1185 1184
 		}
1186 1185
 
1187
-		if ( $intent_id ) {
1188
-			return WC_Stripe_API::request( array(), "payment_intents/$intent_id", 'GET' );
1186
+		if ($intent_id) {
1187
+			return WC_Stripe_API::request(array(), "payment_intents/$intent_id", 'GET');
1189 1188
 		}
1190 1189
 
1191 1190
 		// The order doesn't have a payment intent, but it may have a setup intent.
1192
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1193
-			$intent_id = get_post_meta( $order_id, '_stripe_setup_intent', true );
1191
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1192
+			$intent_id = get_post_meta($order_id, '_stripe_setup_intent', true);
1194 1193
 		} else {
1195
-			$intent_id = $order->get_meta( '_stripe_setup_intent' );
1194
+			$intent_id = $order->get_meta('_stripe_setup_intent');
1196 1195
 		}
1197 1196
 
1198
-		if ( $intent_id ) {
1199
-			return WC_Stripe_API::request( array(), "setup_intents/$intent_id", 'GET' );
1197
+		if ($intent_id) {
1198
+			return WC_Stripe_API::request(array(), "setup_intents/$intent_id", 'GET');
1200 1199
 		}
1201 1200
 
1202 1201
 		return false;
@@ -1210,18 +1209,18 @@  discard block
 block discarded – undo
1210 1209
 	 * @param stdClass $intent The intent that is being processed.
1211 1210
 	 * @return bool            A flag that indicates whether the order is already locked.
1212 1211
 	 */
1213
-	public function lock_order_payment( $order, $intent = null ) {
1214
-		$order_id       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1212
+	public function lock_order_payment($order, $intent = null) {
1213
+		$order_id       = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1215 1214
 		$transient_name = 'wc_stripe_processing_intent_' . $order_id;
1216
-		$processing     = get_transient( $transient_name );
1215
+		$processing     = get_transient($transient_name);
1217 1216
 
1218 1217
 		// Block the process if the same intent is already being handled.
1219
-		if ( "-1" === $processing || ( isset( $intent->id ) && $processing === $intent->id ) ) {
1218
+		if ("-1" === $processing || (isset($intent->id) && $processing === $intent->id)) {
1220 1219
 			return true;
1221 1220
 		}
1222 1221
 
1223 1222
 		// Save the new intent as a transient, eventually overwriting another one.
1224
-		set_transient( $transient_name, empty( $intent ) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS );
1223
+		set_transient($transient_name, empty($intent) ? '-1' : $intent->id, 5 * MINUTE_IN_SECONDS);
1225 1224
 
1226 1225
 		return false;
1227 1226
 	}
@@ -1232,9 +1231,9 @@  discard block
 block discarded – undo
1232 1231
 	 * @since 4.2
1233 1232
 	 * @param WC_Order $order The order that is being unlocked.
1234 1233
 	 */
1235
-	public function unlock_order_payment( $order ) {
1236
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1237
-		delete_transient( 'wc_stripe_processing_intent_' . $order_id );
1234
+	public function unlock_order_payment($order) {
1235
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1236
+		delete_transient('wc_stripe_processing_intent_' . $order_id);
1238 1237
 	}
1239 1238
 
1240 1239
 	/**
@@ -1244,9 +1243,9 @@  discard block
 block discarded – undo
1244 1243
 	 * @param object $response The response from Stripe.
1245 1244
 	 * @return boolean Whether or not it's a 'authentication_required' error
1246 1245
 	 */
1247
-	public function is_authentication_required_for_payment( $response ) {
1248
-		return ( ! empty( $response->error ) && 'authentication_required' === $response->error->code )
1249
-			|| ( ! empty( $response->last_payment_error ) && 'authentication_required' === $response->last_payment_error->code );
1246
+	public function is_authentication_required_for_payment($response) {
1247
+		return ( ! empty($response->error) && 'authentication_required' === $response->error->code)
1248
+			|| ( ! empty($response->last_payment_error) && 'authentication_required' === $response->last_payment_error->code);
1250 1249
 	}
1251 1250
 
1252 1251
 	/**
@@ -1256,21 +1255,21 @@  discard block
 block discarded – undo
1256 1255
 	 * @param object   $prepared_source The source, entered/chosen by the customer.
1257 1256
 	 * @return string                   The client secret of the intent, used for confirmation in JS.
1258 1257
 	 */
1259
-	public function setup_intent( $order, $prepared_source ) {
1260
-		$order_id     = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1261
-		$setup_intent = WC_Stripe_API::request( array(
1258
+	public function setup_intent($order, $prepared_source) {
1259
+		$order_id     = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1260
+		$setup_intent = WC_Stripe_API::request(array(
1262 1261
 			'payment_method' => $prepared_source->source,
1263 1262
 			'customer'       => $prepared_source->customer,
1264 1263
 			'confirm'        => 'true',
1265
-		), 'setup_intents' );
1264
+		), 'setup_intents');
1266 1265
 
1267
-		if ( is_wp_error( $setup_intent ) ) {
1268
-			WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) );
1269
-		} elseif ( 'requires_action' === $setup_intent->status ) {
1270
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1271
-				update_post_meta( $order_id, '_stripe_setup_intent', $setup_intent->id );
1266
+		if (is_wp_error($setup_intent)) {
1267
+			WC_Stripe_Logger::log("Unable to create SetupIntent for Order #$order_id: " . print_r($setup_intent, true));
1268
+		} elseif ('requires_action' === $setup_intent->status) {
1269
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1270
+				update_post_meta($order_id, '_stripe_setup_intent', $setup_intent->id);
1272 1271
 			} else {
1273
-				$order->update_meta_data( '_stripe_setup_intent', $setup_intent->id );
1272
+				$order->update_meta_data('_stripe_setup_intent', $setup_intent->id);
1274 1273
 				$order->save();
1275 1274
 			}
1276 1275
 
@@ -1286,12 +1285,12 @@  discard block
 block discarded – undo
1286 1285
 	 * @param float    $amount          The amount to charge. If not specified, it will be read from the order.
1287 1286
 	 * @return object                   An intent or an error.
1288 1287
 	 */
1289
-	public function create_and_confirm_intent_for_off_session( $order, $prepared_source, $amount = NULL ) {
1288
+	public function create_and_confirm_intent_for_off_session($order, $prepared_source, $amount = NULL) {
1290 1289
 		// The request for a charge contains metadata for the intent.
1291
-		$full_request = $this->generate_payment_request( $order, $prepared_source );
1290
+		$full_request = $this->generate_payment_request($order, $prepared_source);
1292 1291
 
1293 1292
 		$request = array(
1294
-			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount( $amount, $full_request['currency'] ) : $full_request['amount'],
1293
+			'amount'               => $amount ? WC_Stripe_Helper::get_stripe_amount($amount, $full_request['currency']) : $full_request['amount'],
1295 1294
 			'currency'             => $full_request['currency'],
1296 1295
 			'description'          => $full_request['description'],
1297 1296
 			'metadata'             => $full_request['metadata'],
@@ -1303,38 +1302,38 @@  discard block
 block discarded – undo
1303 1302
 			'confirmation_method'  => 'automatic',
1304 1303
 		);
1305 1304
 
1306
-		if ( isset( $full_request['statement_descriptor'] ) ) {
1305
+		if (isset($full_request['statement_descriptor'])) {
1307 1306
 			$request['statement_descriptor'] = $full_request['statement_descriptor'];
1308 1307
 		}
1309 1308
 
1310
-		if ( isset( $full_request['customer'] ) ) {
1309
+		if (isset($full_request['customer'])) {
1311 1310
 			$request['customer'] = $full_request['customer'];
1312 1311
 		}
1313 1312
 
1314
-		if ( isset( $full_request['source'] ) ) {
1313
+		if (isset($full_request['source'])) {
1315 1314
 			$request['source'] = $full_request['source'];
1316 1315
 		}
1317 1316
 
1318
-		$intent = WC_Stripe_API::request( $request, 'payment_intents' );
1319
-		$is_authentication_required = $this->is_authentication_required_for_payment( $intent );
1317
+		$intent = WC_Stripe_API::request($request, 'payment_intents');
1318
+		$is_authentication_required = $this->is_authentication_required_for_payment($intent);
1320 1319
 
1321
-		if ( ! empty( $intent->error ) && ! $is_authentication_required ) {
1320
+		if ( ! empty($intent->error) && ! $is_authentication_required) {
1322 1321
 			return $intent;
1323 1322
 		}
1324 1323
 
1325
-		$intent_id      = ( ! empty( $intent->error )
1324
+		$intent_id = ( ! empty($intent->error)
1326 1325
 			? $intent->error->payment_intent->id
1327 1326
 			: $intent->id
1328 1327
 		);
1329
-		$payment_intent = ( ! empty( $intent->error )
1328
+		$payment_intent = ( ! empty($intent->error)
1330 1329
 			? $intent->error->payment_intent
1331 1330
 			: $intent
1332 1331
 		);
1333
-		$order_id       = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
1334
-		WC_Stripe_Logger::log( "Stripe PaymentIntent $intent_id initiated for order $order_id" );
1332
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
1333
+		WC_Stripe_Logger::log("Stripe PaymentIntent $intent_id initiated for order $order_id");
1335 1334
 
1336 1335
 		// Save the intent ID to the order.
1337
-		$this->save_intent_to_order( $order, $payment_intent );
1336
+		$this->save_intent_to_order($order, $payment_intent);
1338 1337
 
1339 1338
 		return $intent;
1340 1339
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-subs-compat.php 1 patch
Spacing   +187 added lines, -187 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
 
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
23
-			add_action( 'wc_stripe_cards_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) );
24
-			add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23
+			add_action('wc_stripe_cards_payment_fields', array($this, 'display_update_subs_payment_checkout'));
24
+			add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2);
25 25
 
26 26
 			// display the credit card used for a subscription in the "My Subscriptions" table
27
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
27
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
28 28
 
29 29
 			// allow store managers to manually set Stripe as the payment method on a subscription
30
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
31
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
32
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
30
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
31
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
32
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
33 33
 
34 34
 			/*
35 35
 			 * WC subscriptions hooks into the "template_redirect" hook with priority 100.
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 			 * See: https://github.com/woocommerce/woocommerce-subscriptions/blob/99a75687e109b64cbc07af6e5518458a6305f366/includes/class-wcs-cart-renewal.php#L165
38 38
 			 * If we are in the "You just need to authorize SCA" flow, we don't want that redirection to happen.
39 39
 			 */
40
-			add_action( 'template_redirect', array( $this, 'remove_order_pay_var' ), 99 );
41
-			add_action( 'template_redirect', array( $this, 'restore_order_pay_var' ), 101 );
40
+			add_action('template_redirect', array($this, 'remove_order_pay_var'), 99);
41
+			add_action('template_redirect', array($this, 'restore_order_pay_var'), 101);
42 42
 		}
43 43
 	}
44 44
 
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	 * @since 4.0.0
50 50
 	 * @version 4.0.0
51 51
 	 */
52
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
53
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
52
+	public function maybe_hide_save_checkbox($display_tokenization) {
53
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
54 54
 			return false;
55 55
 		}
56 56
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @param  int  $order_id
63 63
 	 * @return boolean
64 64
 	 */
65
-	public function has_subscription( $order_id ) {
66
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
65
+	public function has_subscription($order_id) {
66
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
67 67
 	}
68 68
 
69 69
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return bool
74 74
 	 */
75 75
 	public function is_subs_change_payment() {
76
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
76
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
77 77
 	}
78 78
 
79 79
 	/**
@@ -83,20 +83,20 @@  discard block
 block discarded – undo
83 83
 	 * @since 4.1.11
84 84
 	 */
85 85
 	public function display_update_subs_payment_checkout() {
86
-		$subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
86
+		$subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active'));
87 87
 		if (
88
-			apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) &&
89
-			wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) &&
88
+			apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) &&
89
+			wcs_user_has_subscription(get_current_user_id(), '', $subs_statuses) &&
90 90
 			is_add_payment_method_page()
91 91
 		) {
92
-			$label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) );
93
-			$id    = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id );
92
+			$label = esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe')));
93
+			$id    = sprintf('wc-%1$s-update-subs-payment-method-card', $this->id);
94 94
 			woocommerce_form_field(
95 95
 				$id,
96 96
 				array(
97 97
 					'type'    => 'checkbox',
98 98
 					'label'   => $label,
99
-					'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ),
99
+					'default' => apply_filters('wc_stripe_save_to_subs_checked', false),
100 100
 				)
101 101
 			);
102 102
 		}
@@ -109,17 +109,17 @@  discard block
 block discarded – undo
109 109
 	 * @param string $source_id
110 110
 	 * @param object $source_object
111 111
 	 */
112
-	public function handle_add_payment_method_success( $source_id, $source_object ) {
113
-		if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) {
112
+	public function handle_add_payment_method_success($source_id, $source_object) {
113
+		if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) {
114 114
 			$all_subs = wcs_get_users_subscriptions();
115
-			$subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
116
-
117
-			if ( ! empty( $all_subs ) ) {
118
-				foreach ( $all_subs as $sub ) {
119
-					if ( $sub->has_status( $subs_statuses ) ) {
120
-						update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id );
121
-						update_post_meta( $sub->get_id(), '_payment_method', $this->id );
122
-						update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title );
115
+			$subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active'));
116
+
117
+			if ( ! empty($all_subs)) {
118
+				foreach ($all_subs as $sub) {
119
+					if ($sub->has_status($subs_statuses)) {
120
+						update_post_meta($sub->get_id(), '_stripe_source_id', $source_id);
121
+						update_post_meta($sub->get_id(), '_payment_method', $this->id);
122
+						update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title);
123 123
 					}
124 124
 				}
125 125
 			}
@@ -133,24 +133,24 @@  discard block
 block discarded – undo
133 133
 	 * @since 4.1.11 Remove 3DS check as it is not needed.
134 134
 	 * @param int $order_id
135 135
 	 */
136
-	public function change_subs_payment_method( $order_id ) {
136
+	public function change_subs_payment_method($order_id) {
137 137
 		try {
138
-			$subscription    = wc_get_order( $order_id );
139
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
138
+			$subscription    = wc_get_order($order_id);
139
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
140 140
 
141
-			$this->maybe_disallow_prepaid_card( $prepared_source );
142
-			$this->check_source( $prepared_source );
143
-			$this->save_source_to_order( $subscription, $prepared_source );
141
+			$this->maybe_disallow_prepaid_card($prepared_source);
142
+			$this->check_source($prepared_source);
143
+			$this->save_source_to_order($subscription, $prepared_source);
144 144
 
145
-			do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source );
145
+			do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source);
146 146
 
147 147
 			return array(
148 148
 				'result'   => 'success',
149
-				'redirect' => $this->get_return_url( $subscription ),
149
+				'redirect' => $this->get_return_url($subscription),
150 150
 			);
151
-		} catch ( WC_Stripe_Exception $e ) {
152
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
153
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
151
+		} catch (WC_Stripe_Exception $e) {
152
+			wc_add_notice($e->getLocalizedMessage(), 'error');
153
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
154 154
 		}
155 155
 	}
156 156
 
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
 	 * @param  int $order_id
160 160
 	 * @return array
161 161
 	 */
162
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
163
-		if ( $this->has_subscription( $order_id ) ) {
164
-			if ( $this->is_subs_change_payment() ) {
165
-				return $this->change_subs_payment_method( $order_id );
162
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
163
+		if ($this->has_subscription($order_id)) {
164
+			if ($this->is_subs_change_payment()) {
165
+				return $this->change_subs_payment_method($order_id);
166 166
 			}
167 167
 
168 168
 			// Regular payment with force customer enabled
169
-			return parent::process_payment( $order_id, $retry, true, $previous_error );
169
+			return parent::process_payment($order_id, $retry, true, $previous_error);
170 170
 		} else {
171
-			return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error );
171
+			return parent::process_payment($order_id, $retry, $force_save_source, $previous_error);
172 172
 		}
173 173
 	}
174 174
 
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 	 * @param object   $prepared_source The source that is used for the payment.
181 181
 	 * @return array                    The arguments for the request.
182 182
 	 */
183
-	public function generate_create_intent_request( $order, $prepared_source ) {
184
-		$request = parent::generate_create_intent_request( $order, $prepared_source );
183
+	public function generate_create_intent_request($order, $prepared_source) {
184
+		$request = parent::generate_create_intent_request($order, $prepared_source);
185 185
 
186 186
 		// Non-subscription orders do not need any additional parameters.
187
-		if ( ! $this->has_subscription( $order ) ) {
187
+		if ( ! $this->has_subscription($order)) {
188 188
 			return $request;
189 189
 		}
190 190
 
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 	 * @param $amount_to_charge float The amount to charge.
201 201
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
202 202
 	 */
203
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
204
-		$this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false );
203
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
204
+		$this->process_subscription_payment($amount_to_charge, $renewal_order, true, false);
205 205
 	}
206 206
 
207 207
 	/**
@@ -215,115 +215,115 @@  discard block
 block discarded – undo
215 215
 	 * @param bool $retry Should we retry the process?
216 216
 	 * @param object $previous_error
217 217
 	 */
218
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
218
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) {
219 219
 		try {
220
-			if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
220
+			if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
221 221
 				/* translators: minimum amount */
222
-				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_Helper::get_minimum_amount() / 100 ) ) );
222
+				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_Helper::get_minimum_amount() / 100)));
223 223
 			}
224 224
 
225
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
225
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
226 226
 
227 227
 			// Check for an existing intent, which is associated with the order.
228
-			if ( $this->has_authentication_already_failed( $renewal_order ) ) {
228
+			if ($this->has_authentication_already_failed($renewal_order)) {
229 229
 				return;
230 230
 			}
231 231
 
232 232
 			// Get source from order
233
-			$prepared_source = $this->prepare_order_source( $renewal_order );
233
+			$prepared_source = $this->prepare_order_source($renewal_order);
234 234
 			$source_object   = $prepared_source->source_object;
235 235
 
236
-			if ( ! $prepared_source->customer ) {
237
-				return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
236
+			if ( ! $prepared_source->customer) {
237
+				return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
238 238
 			}
239 239
 
240
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
240
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
241 241
 
242 242
 			/* If we're doing a retry and source is chargeable, we need to pass
243 243
 			 * a different idempotency key and retry for success.
244 244
 			 */
245
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
246
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
245
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
246
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
247 247
 			}
248 248
 
249
-			if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
249
+			if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) {
250 250
 				// Passing empty source will charge customer default.
251 251
 				$prepared_source->source = '';
252 252
 			}
253 253
 
254
-			$this->lock_order_payment( $renewal_order );
254
+			$this->lock_order_payment($renewal_order);
255 255
 
256
-			$response                   = $this->create_and_confirm_intent_for_off_session( $renewal_order, $prepared_source, $amount );
257
-			$is_authentication_required = $this->is_authentication_required_for_payment( $response );
256
+			$response                   = $this->create_and_confirm_intent_for_off_session($renewal_order, $prepared_source, $amount);
257
+			$is_authentication_required = $this->is_authentication_required_for_payment($response);
258 258
 
259 259
 			// It's only a failed payment if it's an error and it's not of the type 'authentication_required'.
260 260
 			// If it's 'authentication_required', then we should email the user and ask them to authenticate.
261
-			if ( ! empty( $response->error ) && ! $is_authentication_required ) {
261
+			if ( ! empty($response->error) && ! $is_authentication_required) {
262 262
 				// We want to retry.
263
-				if ( $this->is_retryable_error( $response->error ) ) {
264
-					if ( $retry ) {
263
+				if ($this->is_retryable_error($response->error)) {
264
+					if ($retry) {
265 265
 						// Don't do anymore retries after this.
266
-						if ( 5 <= $this->retry_interval ) {
267
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
266
+						if (5 <= $this->retry_interval) {
267
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
268 268
 						}
269 269
 
270
-						sleep( $this->retry_interval );
270
+						sleep($this->retry_interval);
271 271
 
272 272
 						$this->retry_interval++;
273 273
 
274
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
274
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
275 275
 					} else {
276
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
277
-						$renewal_order->add_order_note( $localized_message );
278
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
276
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
277
+						$renewal_order->add_order_note($localized_message);
278
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
279 279
 					}
280 280
 				}
281 281
 
282 282
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
283 283
 
284
-				if ( 'card_error' === $response->error->type ) {
285
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
284
+				if ('card_error' === $response->error->type) {
285
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
286 286
 				} else {
287
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
287
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
288 288
 				}
289 289
 
290
-				$renewal_order->add_order_note( $localized_message );
290
+				$renewal_order->add_order_note($localized_message);
291 291
 
292
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
292
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
293 293
 			}
294 294
 
295 295
 			// Either the charge was successfully captured, or it requires further authentication.
296 296
 
297
-			if ( $is_authentication_required ) {
298
-				do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response );
297
+			if ($is_authentication_required) {
298
+				do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response);
299 299
 
300
-				$error_message = __( 'This transaction requires authentication.', 'woocommerce-gateway-stripe' );
301
-				$renewal_order->add_order_note( $error_message );
300
+				$error_message = __('This transaction requires authentication.', 'woocommerce-gateway-stripe');
301
+				$renewal_order->add_order_note($error_message);
302 302
 
303
-				$charge = end( $response->error->payment_intent->charges->data );
303
+				$charge = end($response->error->payment_intent->charges->data);
304 304
 				$id = $charge->id;
305
-				$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
305
+				$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
306 306
 
307
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $id ) : $renewal_order->set_transaction_id( $id );
308
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) );
309
-				if ( is_callable( array( $renewal_order, 'save' ) ) ) {
307
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $id) : $renewal_order->set_transaction_id($id);
308
+				$renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $id));
309
+				if (is_callable(array($renewal_order, 'save'))) {
310 310
 					$renewal_order->save();
311 311
 				}
312 312
 			} else {
313 313
 				// The charge was successfully captured
314
-				do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
314
+				do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
315 315
 
316
-				$this->process_response( end( $response->charges->data ), $renewal_order );
316
+				$this->process_response(end($response->charges->data), $renewal_order);
317 317
 			}
318 318
 
319
-			$this->unlock_order_payment( $renewal_order );
320
-		} catch ( WC_Stripe_Exception $e ) {
321
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
319
+			$this->unlock_order_payment($renewal_order);
320
+		} catch (WC_Stripe_Exception $e) {
321
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
322 322
 
323
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
323
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
324 324
 
325 325
 			/* translators: error message */
326
-			$renewal_order->update_status( 'failed' );
326
+			$renewal_order->update_status('failed');
327 327
 		}
328 328
 	}
329 329
 
@@ -333,24 +333,24 @@  discard block
 block discarded – undo
333 333
 	 * @since 3.1.0
334 334
 	 * @version 4.0.0
335 335
 	 */
336
-	public function save_source_to_order( $order, $source ) {
337
-		parent::save_source_to_order( $order, $source );
336
+	public function save_source_to_order($order, $source) {
337
+		parent::save_source_to_order($order, $source);
338 338
 
339
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
339
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
340 340
 
341 341
 		// Also store it on the subscriptions being purchased or paid for in the order
342
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
343
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
344
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
345
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
342
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
343
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
344
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
345
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
346 346
 		} else {
347 347
 			$subscriptions = array();
348 348
 		}
349 349
 
350
-		foreach ( $subscriptions as $subscription ) {
351
-			$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
352
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
353
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
350
+		foreach ($subscriptions as $subscription) {
351
+			$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
352
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
353
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
354 354
 		}
355 355
 	}
356 356
 
@@ -358,26 +358,26 @@  discard block
 block discarded – undo
358 358
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
359 359
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
360 360
 	 */
361
-	public function delete_resubscribe_meta( $resubscribe_order ) {
362
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
363
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
361
+	public function delete_resubscribe_meta($resubscribe_order) {
362
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
363
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
364 364
 		// For BW compat will remove in future
365
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
365
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
366 366
 		// delete payment intent ID
367
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_intent_id' );
368
-		$this->delete_renewal_meta( $resubscribe_order );
367
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_intent_id');
368
+		$this->delete_renewal_meta($resubscribe_order);
369 369
 	}
370 370
 
371 371
 	/**
372 372
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
373 373
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
374 374
 	 */
375
-	public function delete_renewal_meta( $renewal_order ) {
376
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
377
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
375
+	public function delete_renewal_meta($renewal_order) {
376
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
377
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
378 378
 
379 379
 		// delete payment intent ID
380
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id() ), '_stripe_intent_id' );
380
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id()), '_stripe_intent_id');
381 381
 
382 382
 		return $renewal_order;
383 383
 	}
@@ -391,14 +391,14 @@  discard block
 block discarded – undo
391 391
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
392 392
 	 * @return void
393 393
 	 */
394
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
395
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
396
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
397
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
394
+	public function update_failing_payment_method($subscription, $renewal_order) {
395
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
396
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
397
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
398 398
 
399 399
 		} else {
400
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
401
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
400
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
401
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
402 402
 		}
403 403
 	}
404 404
 
@@ -411,23 +411,23 @@  discard block
 block discarded – undo
411 411
 	 * @param WC_Subscription $subscription An instance of a subscription object
412 412
 	 * @return array
413 413
 	 */
414
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
415
-		$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
416
-		$source_id       = get_post_meta( $subscription_id, '_stripe_source_id', true );
414
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
415
+		$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
416
+		$source_id       = get_post_meta($subscription_id, '_stripe_source_id', true);
417 417
 
418 418
 		// For BW compat will remove in future.
419
-		if ( empty( $source_id ) ) {
420
-			$source_id = get_post_meta( $subscription_id, '_stripe_card_id', true );
419
+		if (empty($source_id)) {
420
+			$source_id = get_post_meta($subscription_id, '_stripe_card_id', true);
421 421
 
422 422
 			// Take this opportunity to update the key name.
423
-			update_post_meta( $subscription_id, '_stripe_source_id', $source_id );
424
-			delete_post_meta( $subscription_id, '_stripe_card_id', $source_id );
423
+			update_post_meta($subscription_id, '_stripe_source_id', $source_id);
424
+			delete_post_meta($subscription_id, '_stripe_card_id', $source_id);
425 425
 		}
426 426
 
427
-		$payment_meta[ $this->id ] = array(
427
+		$payment_meta[$this->id] = array(
428 428
 			'post_meta' => array(
429 429
 				'_stripe_customer_id' => array(
430
-					'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ),
430
+					'value' => get_post_meta($subscription_id, '_stripe_customer_id', true),
431 431
 					'label' => 'Stripe Customer ID',
432 432
 				),
433 433
 				'_stripe_source_id'   => array(
@@ -450,22 +450,22 @@  discard block
 block discarded – undo
450 450
 	 * @param array $payment_meta associative array of meta data required for automatic payments
451 451
 	 * @return array
452 452
 	 */
453
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
454
-		if ( $this->id === $payment_method_id ) {
453
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
454
+		if ($this->id === $payment_method_id) {
455 455
 
456
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
457
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
458
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
459
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
456
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
457
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
458
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
459
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
460 460
 			}
461 461
 
462 462
 			if (
463
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
464
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
465
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
466
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
463
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
464
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
465
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
466
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
467 467
 
468
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
468
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
469 469
 			}
470 470
 		}
471 471
 	}
@@ -478,75 +478,75 @@  discard block
 block discarded – undo
478 478
 	 * @param WC_Subscription $subscription the subscription details
479 479
 	 * @return string the subscription payment method
480 480
 	 */
481
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
482
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
481
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
482
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
483 483
 
484 484
 		// bail for other payment methods
485
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
485
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
486 486
 			return $payment_method_to_display;
487 487
 		}
488 488
 
489
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
489
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
490 490
 
491 491
 		// For BW compat will remove in future.
492
-		if ( empty( $stripe_source_id ) ) {
493
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
492
+		if (empty($stripe_source_id)) {
493
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
494 494
 
495 495
 			// Take this opportunity to update the key name.
496
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
496
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
497 497
 		}
498 498
 
499 499
 		$stripe_customer    = new WC_Stripe_Customer();
500
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
500
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
501 501
 
502 502
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
503
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
503
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
504 504
 			$user_id            = $customer_user;
505
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
506
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
505
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
506
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
507 507
 
508 508
 			// For BW compat will remove in future.
509
-			if ( empty( $stripe_source_id ) ) {
510
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
509
+			if (empty($stripe_source_id)) {
510
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
511 511
 
512 512
 				// Take this opportunity to update the key name.
513
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
513
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
514 514
 			}
515 515
 		}
516 516
 
517 517
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
518
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
519
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
520
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
518
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
519
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
520
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
521 521
 
522 522
 			// For BW compat will remove in future.
523
-			if ( empty( $stripe_source_id ) ) {
524
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
523
+			if (empty($stripe_source_id)) {
524
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
525 525
 
526 526
 				// Take this opportunity to update the key name.
527
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
527
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
528 528
 			}
529 529
 		}
530 530
 
531
-		$stripe_customer->set_id( $stripe_customer_id );
531
+		$stripe_customer->set_id($stripe_customer_id);
532 532
 
533 533
 		$sources                   = $stripe_customer->get_sources();
534
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
534
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
535 535
 
536
-		if ( $sources ) {
536
+		if ($sources) {
537 537
 			$card = false;
538 538
 
539
-			foreach ( $sources as $source ) {
540
-				if ( isset( $source->type ) && 'card' === $source->type ) {
539
+			foreach ($sources as $source) {
540
+				if (isset($source->type) && 'card' === $source->type) {
541 541
 					$card = $source->card;
542
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
542
+				} elseif (isset($source->object) && 'card' === $source->object) {
543 543
 					$card = $source;
544 544
 				}
545 545
 
546
-				if ( $source->id === $stripe_source_id ) {
547
-					if ( $card ) {
546
+				if ($source->id === $stripe_source_id) {
547
+					if ($card) {
548 548
 						/* translators: 1) card brand 2) last 4 digits */
549
-						$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
549
+						$payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4);
550 550
 					}
551 551
 
552 552
 					break;
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 	 */
564 564
 	public function remove_order_pay_var() {
565 565
 		global $wp;
566
-		if ( isset( $_GET['wc-stripe-confirmation'] ) ) {
566
+		if (isset($_GET['wc-stripe-confirmation'])) {
567 567
 			$this->order_pay_var = $wp->query_vars['order-pay'];
568 568
 			$wp->query_vars['order-pay'] = null;
569 569
 		}
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	 */
575 575
 	public function restore_order_pay_var() {
576 576
 		global $wp;
577
-		if ( isset( $this->order_pay_var ) ) {
577
+		if (isset($this->order_pay_var)) {
578 578
 			$wp->query_vars['order-pay'] = $this->order_pay_var;
579 579
 		}
580 580
 	}
@@ -585,13 +585,13 @@  discard block
 block discarded – undo
585 585
 	 * @param WC_Order $renewal_order The renewal order.
586 586
 	 * @return boolean
587 587
 	 */
588
-	public function has_authentication_already_failed( $renewal_order ) {
589
-		$existing_intent = $this->get_intent_from_order( $renewal_order );
588
+	public function has_authentication_already_failed($renewal_order) {
589
+		$existing_intent = $this->get_intent_from_order($renewal_order);
590 590
 
591 591
 		if (
592 592
 			! $existing_intent
593 593
 			|| 'requires_payment_method' !== $existing_intent->status
594
-			|| empty( $existing_intent->last_payment_error )
594
+			|| empty($existing_intent->last_payment_error)
595 595
 			|| 'authentication_required' !== $existing_intent->last_payment_error->code
596 596
 		) {
597 597
 			return false;
@@ -605,12 +605,12 @@  discard block
 block discarded – undo
605 605
 		 *
606 606
 		 * @param WC_Order $renewal_order The order that is being renewed.
607 607
 		 */
608
-		do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order );
608
+		do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order);
609 609
 
610 610
 		// Fail the payment attempt (order would be currently pending because of retry rules).
611
-		$charge    = end( $existing_intent->charges->data );
611
+		$charge    = end($existing_intent->charges->data);
612 612
 		$charge_id = $charge->id;
613
-		$renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $charge_id ) );
613
+		$renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $charge_id));
614 614
 
615 615
 		return true;
616 616
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-subs-compat.php 1 patch
Spacing   +158 added lines, -158 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
 
@@ -15,21 +15,21 @@  discard block
 block discarded – undo
15 15
 	public function __construct() {
16 16
 		parent::__construct();
17 17
 
18
-		if ( class_exists( 'WC_Subscriptions_Order' ) ) {
19
-			add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
20
-			add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 );
21
-			add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 );
22
-			add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 );
23
-			add_action( 'wc_stripe_sepa_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) );
24
-			add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 );
18
+		if (class_exists('WC_Subscriptions_Order')) {
19
+			add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
20
+			add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10);
21
+			add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10);
22
+			add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2);
23
+			add_action('wc_stripe_sepa_payment_fields', array($this, 'display_update_subs_payment_checkout'));
24
+			add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2);
25 25
 
26 26
 			// Display the credit card used for a subscription in the "My Subscriptions" table.
27
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
27
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
28 28
 
29 29
 			// Allow store managers to manually set Stripe as the payment method on a subscription.
30
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
31
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
32
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
30
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
31
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
32
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
33 33
 		}
34 34
 	}
35 35
 
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	 * @since 4.0.0
41 41
 	 * @version 4.0.0
42 42
 	 */
43
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
44
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
43
+	public function maybe_hide_save_checkbox($display_tokenization) {
44
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
45 45
 			return false;
46 46
 		}
47 47
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 * @param  int  $order_id
54 54
 	 * @return boolean
55 55
 	 */
56
-	public function has_subscription( $order_id ) {
57
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
56
+	public function has_subscription($order_id) {
57
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
58 58
 	}
59 59
 
60 60
 	/**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return bool
65 65
 	 */
66 66
 	public function is_subs_change_payment() {
67
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
67
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
68 68
 	}
69 69
 
70 70
 	/**
@@ -74,20 +74,20 @@  discard block
 block discarded – undo
74 74
 	 * @since 4.1.11
75 75
 	 */
76 76
 	public function display_update_subs_payment_checkout() {
77
-		$subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
77
+		$subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active'));
78 78
 		if (
79
-			apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) &&
80
-			wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) &&
79
+			apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) &&
80
+			wcs_user_has_subscription(get_current_user_id(), '', $subs_statuses) &&
81 81
 			is_add_payment_method_page()
82 82
 		) {
83
-			$label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) );
84
-			$id    = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id );
83
+			$label = esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe')));
84
+			$id    = sprintf('wc-%1$s-update-subs-payment-method-card', $this->id);
85 85
 			woocommerce_form_field(
86 86
 				$id,
87 87
 				array(
88 88
 					'type'    => 'checkbox',
89 89
 					'label'   => $label,
90
-					'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ),
90
+					'default' => apply_filters('wc_stripe_save_to_subs_checked', false),
91 91
 				)
92 92
 			);
93 93
 		}
@@ -100,17 +100,17 @@  discard block
 block discarded – undo
100 100
 	 * @param string $source_id
101 101
 	 * @param object $source_object
102 102
 	 */
103
-	public function handle_add_payment_method_success( $source_id, $source_object ) {
104
-		if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) {
103
+	public function handle_add_payment_method_success($source_id, $source_object) {
104
+		if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) {
105 105
 			$all_subs = wcs_get_users_subscriptions();
106
-			$subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
107
-
108
-			if ( ! empty( $all_subs ) ) {
109
-				foreach ( $all_subs as $sub ) {
110
-					if ( $sub->has_status( $subs_statuses ) ) {
111
-						update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id );
112
-						update_post_meta( $sub->get_id(), '_payment_method', $this->id );
113
-						update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title );
106
+			$subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active'));
107
+
108
+			if ( ! empty($all_subs)) {
109
+				foreach ($all_subs as $sub) {
110
+					if ($sub->has_status($subs_statuses)) {
111
+						update_post_meta($sub->get_id(), '_stripe_source_id', $source_id);
112
+						update_post_meta($sub->get_id(), '_payment_method', $this->id);
113
+						update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title);
114 114
 					}
115 115
 				}
116 116
 			}
@@ -123,24 +123,24 @@  discard block
 block discarded – undo
123 123
 	 * @since 3.1.0
124 124
 	 * @version 4.0.0
125 125
 	 */
126
-	public function save_source_to_order( $order, $source ) {
127
-		parent::save_source_to_order( $order, $source );
126
+	public function save_source_to_order($order, $source) {
127
+		parent::save_source_to_order($order, $source);
128 128
 
129
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
129
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
130 130
 
131 131
 		// Also store it on the subscriptions being purchased or paid for in the order.
132
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
133
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
134
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
135
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
132
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
133
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
134
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
135
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
136 136
 		} else {
137 137
 			$subscriptions = array();
138 138
 		}
139 139
 
140
-		foreach ( $subscriptions as $subscription ) {
141
-			$subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id();
142
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
143
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
140
+		foreach ($subscriptions as $subscription) {
141
+			$subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id();
142
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
143
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
144 144
 		}
145 145
 	}
146 146
 
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
 	 * @param  int $order_id
150 150
 	 * @return array
151 151
 	 */
152
-	public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) {
153
-		if ( $this->has_subscription( $order_id ) ) {
154
-			if ( $this->is_subs_change_payment() ) {
155
-				return $this->change_subs_payment_method( $order_id );
152
+	public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) {
153
+		if ($this->has_subscription($order_id)) {
154
+			if ($this->is_subs_change_payment()) {
155
+				return $this->change_subs_payment_method($order_id);
156 156
 			}
157 157
 
158 158
 			// Regular payment with force customer enabled
159
-			return parent::process_payment( $order_id, $retry, true, $previous_error );
159
+			return parent::process_payment($order_id, $retry, true, $previous_error);
160 160
 		} else {
161
-			return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error );
161
+			return parent::process_payment($order_id, $retry, $force_save_source, $previous_error);
162 162
 		}
163 163
 	}
164 164
 
@@ -168,27 +168,27 @@  discard block
 block discarded – undo
168 168
 	 * @since 4.0.4
169 169
 	 * @param int $order_id
170 170
 	 */
171
-	public function change_subs_payment_method( $order_id ) {
171
+	public function change_subs_payment_method($order_id) {
172 172
 		try {
173
-			$subscription    = wc_get_order( $order_id );
174
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
173
+			$subscription    = wc_get_order($order_id);
174
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
175 175
 
176
-			if ( empty( $prepared_source->source ) ) {
177
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
178
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
176
+			if (empty($prepared_source->source)) {
177
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
178
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
179 179
 			}
180 180
 
181
-			$this->save_source_to_order( $subscription, $prepared_source );
181
+			$this->save_source_to_order($subscription, $prepared_source);
182 182
 
183
-			do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source );
183
+			do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source);
184 184
 
185 185
 			return array(
186 186
 				'result'   => 'success',
187
-				'redirect' => $this->get_return_url( $subscription ),
187
+				'redirect' => $this->get_return_url($subscription),
188 188
 			);
189
-		} catch ( WC_Stripe_Exception $e ) {
190
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
191
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
189
+		} catch (WC_Stripe_Exception $e) {
190
+			wc_add_notice($e->getLocalizedMessage(), 'error');
191
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
192 192
 		}
193 193
 	}
194 194
 
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
 	 * @param $amount_to_charge float The amount to charge.
199 199
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
200 200
 	 */
201
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
202
-		$this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false );
201
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
202
+		$this->process_subscription_payment($amount_to_charge, $renewal_order, true, false);
203 203
 	}
204 204
 
205 205
 	/**
@@ -213,86 +213,86 @@  discard block
 block discarded – undo
213 213
 	 * @param bool $retry Should we retry the process?
214 214
 	 * @param object $previous_error
215 215
 	 */
216
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) {
216
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) {
217 217
 		try {
218
-			if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
218
+			if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
219 219
 				/* translators: minimum amount */
220
-				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_Helper::get_minimum_amount() / 100 ) ) );
220
+				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_Helper::get_minimum_amount() / 100)));
221 221
 			}
222 222
 
223
-			$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id();
223
+			$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id();
224 224
 
225 225
 			// Get source from order
226
-			$prepared_source = $this->prepare_order_source( $renewal_order );
226
+			$prepared_source = $this->prepare_order_source($renewal_order);
227 227
 			$source_object   = $prepared_source->source_object;
228 228
 
229
-			if ( ! $prepared_source->customer ) {
230
-				return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
229
+			if ( ! $prepared_source->customer) {
230
+				return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
231 231
 			}
232 232
 
233
-			WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
233
+			WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
234 234
 
235 235
 			/* If we're doing a retry and source is chargeable, we need to pass
236 236
 			 * a different idempotency key and retry for success.
237 237
 			 */
238
-			if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) {
239
-				add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
238
+			if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) {
239
+				add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
240 240
 			}
241 241
 
242
-			if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
242
+			if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) {
243 243
 				// Passing empty source will charge customer default.
244 244
 				$prepared_source->source = '';
245 245
 			}
246 246
 
247
-			$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
247
+			$request            = $this->generate_payment_request($renewal_order, $prepared_source);
248 248
 			$request['capture'] = 'true';
249
-			$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
250
-			$response           = WC_Stripe_API::request( $request );
249
+			$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
250
+			$response           = WC_Stripe_API::request($request);
251 251
 
252
-			if ( ! empty( $response->error ) ) {
252
+			if ( ! empty($response->error)) {
253 253
 				// We want to retry.
254
-				if ( $this->is_retryable_error( $response->error ) ) {
255
-					if ( $retry ) {
254
+				if ($this->is_retryable_error($response->error)) {
255
+					if ($retry) {
256 256
 						// Don't do anymore retries after this.
257
-						if ( 5 <= $this->retry_interval ) {
258
-							return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error );
257
+						if (5 <= $this->retry_interval) {
258
+							return $this->process_subscription_payment($amount, $renewal_order, false, $response->error);
259 259
 						}
260 260
 
261
-						sleep( $this->retry_interval );
261
+						sleep($this->retry_interval);
262 262
 
263 263
 						$this->retry_interval++;
264 264
 
265
-						return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error );
265
+						return $this->process_subscription_payment($amount, $renewal_order, true, $response->error);
266 266
 					} else {
267
-						$localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' );
268
-						$renewal_order->add_order_note( $localized_message );
269
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
267
+						$localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe');
268
+						$renewal_order->add_order_note($localized_message);
269
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
270 270
 					}
271 271
 				}
272 272
 
273 273
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
274 274
 
275
-				if ( 'card_error' === $response->error->type ) {
276
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
275
+				if ('card_error' === $response->error->type) {
276
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
277 277
 				} else {
278
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
278
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
279 279
 				}
280 280
 
281
-				$renewal_order->add_order_note( $localized_message );
281
+				$renewal_order->add_order_note($localized_message);
282 282
 
283
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
283
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
284 284
 			}
285 285
 
286
-			do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order );
286
+			do_action('wc_gateway_stripe_process_payment', $response, $renewal_order);
287 287
 
288
-			$this->process_response( $response, $renewal_order );
289
-		} catch ( WC_Stripe_Exception $e ) {
290
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
288
+			$this->process_response($response, $renewal_order);
289
+		} catch (WC_Stripe_Exception $e) {
290
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
291 291
 
292
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order );
292
+			do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order);
293 293
 
294 294
 			/* translators: error message */
295
-			$renewal_order->update_status( 'failed' );
295
+			$renewal_order->update_status('failed');
296 296
 		}
297 297
 	}
298 298
 
@@ -300,21 +300,21 @@  discard block
 block discarded – undo
300 300
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
301 301
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
302 302
 	 */
303
-	public function delete_resubscribe_meta( $resubscribe_order ) {
304
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
305
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
303
+	public function delete_resubscribe_meta($resubscribe_order) {
304
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
305
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
306 306
 		// For BW compat will remove in future
307
-		delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
308
-		$this->delete_renewal_meta( $resubscribe_order );
307
+		delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
308
+		$this->delete_renewal_meta($resubscribe_order);
309 309
 	}
310 310
 
311 311
 	/**
312 312
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
313 313
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
314 314
 	 */
315
-	public function delete_renewal_meta( $renewal_order ) {
316
-		WC_Stripe_Helper::delete_stripe_fee( $renewal_order );
317
-		WC_Stripe_Helper::delete_stripe_net( $renewal_order );
315
+	public function delete_renewal_meta($renewal_order) {
316
+		WC_Stripe_Helper::delete_stripe_fee($renewal_order);
317
+		WC_Stripe_Helper::delete_stripe_net($renewal_order);
318 318
 
319 319
 		return $renewal_order;
320 320
 	}
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
329 329
 	 * @return void
330 330
 	 */
331
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
332
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
333
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
334
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
331
+	public function update_failing_payment_method($subscription, $renewal_order) {
332
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
333
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
334
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
335 335
 
336 336
 		} else {
337
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
338
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
337
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
338
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
339 339
 		}
340 340
 	}
341 341
 
@@ -348,21 +348,21 @@  discard block
 block discarded – undo
348 348
 	 * @param WC_Subscription $subscription An instance of a subscription object
349 349
 	 * @return array
350 350
 	 */
351
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
352
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
351
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
352
+		$source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
353 353
 
354 354
 		// For BW compat will remove in future.
355
-		if ( empty( $source_id ) ) {
356
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
355
+		if (empty($source_id)) {
356
+			$source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
357 357
 
358 358
 			// Take this opportunity to update the key name.
359
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
359
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
360 360
 		}
361 361
 
362
-		$payment_meta[ $this->id ] = array(
362
+		$payment_meta[$this->id] = array(
363 363
 			'post_meta' => array(
364 364
 				'_stripe_customer_id' => array(
365
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
365
+					'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
366 366
 					'label' => 'Stripe Customer ID',
367 367
 				),
368 368
 				'_stripe_source_id'   => array(
@@ -383,22 +383,22 @@  discard block
 block discarded – undo
383 383
 	 * @param array $payment_meta associative array of meta data required for automatic payments
384 384
 	 * @return array
385 385
 	 */
386
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
387
-		if ( $this->id === $payment_method_id ) {
386
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
387
+		if ($this->id === $payment_method_id) {
388 388
 
389
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
390
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
391
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
392
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
389
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
390
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
391
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
392
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
393 393
 			}
394 394
 
395 395
 			if (
396
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
397
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
398
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
399
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
396
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
397
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
398
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
399
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
400 400
 
401
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
401
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
402 402
 			}
403 403
 		}
404 404
 	}
@@ -411,67 +411,67 @@  discard block
 block discarded – undo
411 411
 	 * @param WC_Subscription $subscription the subscription details
412 412
 	 * @return string the subscription payment method
413 413
 	 */
414
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
415
-		$customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id();
414
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
415
+		$customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id();
416 416
 
417 417
 		// bail for other payment methods
418
-		if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
418
+		if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
419 419
 			return $payment_method_to_display;
420 420
 		}
421 421
 
422
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
422
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
423 423
 
424 424
 		// For BW compat will remove in future.
425
-		if ( empty( $stripe_source_id ) ) {
426
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
425
+		if (empty($stripe_source_id)) {
426
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
427 427
 
428 428
 			// Take this opportunity to update the key name.
429
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
429
+			WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
430 430
 		}
431 431
 
432 432
 		$stripe_customer    = new WC_Stripe_Customer();
433
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
433
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
434 434
 
435 435
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
436
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
436
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
437 437
 			$user_id            = $customer_user;
438
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
439
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
438
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
439
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
440 440
 
441 441
 			// For BW compat will remove in future.
442
-			if ( empty( $stripe_source_id ) ) {
443
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
442
+			if (empty($stripe_source_id)) {
443
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
444 444
 
445 445
 				// Take this opportunity to update the key name.
446
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
446
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
447 447
 			}
448 448
 		}
449 449
 
450 450
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
451
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
452
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
453
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
451
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
452
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
453
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
454 454
 
455 455
 			// For BW compat will remove in future.
456
-			if ( empty( $stripe_source_id ) ) {
457
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
456
+			if (empty($stripe_source_id)) {
457
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
458 458
 
459 459
 				// Take this opportunity to update the key name.
460
-				WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id );
460
+				WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id);
461 461
 			}
462 462
 		}
463 463
 
464
-		$stripe_customer->set_id( $stripe_customer_id );
464
+		$stripe_customer->set_id($stripe_customer_id);
465 465
 
466 466
 		$sources                   = $stripe_customer->get_sources();
467
-		$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
467
+		$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
468 468
 
469
-		if ( $sources ) {
470
-			foreach ( $sources as $source ) {
471
-				if ( $source->id === $stripe_source_id ) {
472
-					if ( $source->sepa_debit ) {
469
+		if ($sources) {
470
+			foreach ($sources as $source) {
471
+				if ($source->id === $stripe_source_id) {
472
+					if ($source->sepa_debit) {
473 473
 						/* translators: 1) last 4 digits of SEPA Direct Debit */
474
-						$payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 );
474
+						$payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4);
475 475
 					}
476 476
 
477 477
 					break;
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  *
16 16
  */
17 17
 
18
-if ( ! defined( 'ABSPATH' ) ) {
18
+if ( ! defined('ABSPATH')) {
19 19
 	exit;
20 20
 }
21 21
 
@@ -29,29 +29,29 @@  discard block
 block discarded – undo
29 29
  */
30 30
 function woocommerce_stripe_missing_wc_notice() {
31 31
 	/* translators: 1. URL link. */
32
-	echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Stripe requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-gateway-stripe' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
32
+	echo '<div class="error"><p><strong>' . sprintf(esc_html__('Stripe requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-gateway-stripe'), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>') . '</strong></p></div>';
33 33
 }
34 34
 
35
-add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' );
35
+add_action('plugins_loaded', 'woocommerce_gateway_stripe_init');
36 36
 
37 37
 function woocommerce_gateway_stripe_init() {
38
-	load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
38
+	load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
39 39
 
40
-	if ( ! class_exists( 'WooCommerce' ) ) {
41
-		add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' );
40
+	if ( ! class_exists('WooCommerce')) {
41
+		add_action('admin_notices', 'woocommerce_stripe_missing_wc_notice');
42 42
 		return;
43 43
 	}
44 44
 
45
-	if ( ! class_exists( 'WC_Stripe' ) ) :
45
+	if ( ! class_exists('WC_Stripe')) :
46 46
 		/**
47 47
 		 * Required minimums and constants
48 48
 		 */
49
-		define( 'WC_STRIPE_VERSION', '4.3.1' );
50
-		define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' );
51
-		define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' );
52
-		define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
53
-		define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
54
-		define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
49
+		define('WC_STRIPE_VERSION', '4.3.1');
50
+		define('WC_STRIPE_MIN_PHP_VER', '5.6.0');
51
+		define('WC_STRIPE_MIN_WC_VER', '2.6.0');
52
+		define('WC_STRIPE_MAIN_FILE', __FILE__);
53
+		define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
54
+		define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
55 55
 
56 56
 		class WC_Stripe {
57 57
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 			 * @return Singleton The *Singleton* instance.
67 67
 			 */
68 68
 			public static function get_instance() {
69
-				if ( null === self::$instance ) {
69
+				if (null === self::$instance) {
70 70
 					self::$instance = new self();
71 71
 				}
72 72
 				return self::$instance;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 			 * *Singleton* via the `new` operator from outside of this class.
94 94
 			 */
95 95
 			private function __construct() {
96
-				add_action( 'admin_init', array( $this, 'install' ) );
96
+				add_action('admin_init', array($this, 'install'));
97 97
 				$this->init();
98 98
 			}
99 99
 
@@ -104,52 +104,52 @@  discard block
 block discarded – undo
104 104
 			 * @version 4.0.0
105 105
 			 */
106 106
 			public function init() {
107
-				if ( is_admin() ) {
108
-					require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-privacy.php';
107
+				if (is_admin()) {
108
+					require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-privacy.php';
109 109
 				}
110 110
 
111
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php';
112
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php';
113
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php';
114
-				include_once dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php';
115
-				require_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php';
116
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php';
117
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php';
118
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php';
119
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php';
120
-				require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php';
121
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php';
122
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php';
123
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php';
124
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php';
125
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php';
126
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php';
127
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php';
128
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php';
129
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php';
130
-				require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php';
131
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php';
132
-				require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php';
133
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php';
134
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php';
135
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php';
136
-				require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-intent-controller.php';
137
-
138
-				if ( is_admin() ) {
139
-					require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php';
111
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-exception.php';
112
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-logger.php';
113
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-helper.php';
114
+				include_once dirname(__FILE__) . '/includes/class-wc-stripe-api.php';
115
+				require_once dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php';
116
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php';
117
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php';
118
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php';
119
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php';
120
+				require_once dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php';
121
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php';
122
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php';
123
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php';
124
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php';
125
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php';
126
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php';
127
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php';
128
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php';
129
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php';
130
+				require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php';
131
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php';
132
+				require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php';
133
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php';
134
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php';
135
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-customer.php';
136
+				require_once dirname(__FILE__) . '/includes/class-wc-stripe-intent-controller.php';
137
+
138
+				if (is_admin()) {
139
+					require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php';
140 140
 				}
141 141
 
142 142
 				// REMOVE IN THE FUTURE.
143
-				require_once dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php';
143
+				require_once dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php';
144 144
 
145
-				add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
146
-				add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
145
+				add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
146
+				add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
147 147
 
148 148
 				// Modify emails emails.
149
-				add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ), 20 );
149
+				add_filter('woocommerce_email_classes', array($this, 'add_emails'), 20);
150 150
 
151
-				if ( version_compare( WC_VERSION, '3.4', '<' ) ) {
152
-					add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) );
151
+				if (version_compare(WC_VERSION, '3.4', '<')) {
152
+					add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin'));
153 153
 				}
154 154
 			}
155 155
 
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 			 * @version 4.0.0
161 161
 			 */
162 162
 			public function update_plugin_version() {
163
-				delete_option( 'wc_stripe_version' );
164
-				update_option( 'wc_stripe_version', WC_STRIPE_VERSION );
163
+				delete_option('wc_stripe_version');
164
+				update_option('wc_stripe_version', WC_STRIPE_VERSION);
165 165
 			}
166 166
 
167 167
 			/**
@@ -171,15 +171,15 @@  discard block
 block discarded – undo
171 171
 			 * @version 3.1.0
172 172
 			 */
173 173
 			public function install() {
174
-				if ( ! is_plugin_active( plugin_basename( __FILE__ ) ) ) {
174
+				if ( ! is_plugin_active(plugin_basename(__FILE__))) {
175 175
 					return;
176 176
 				}
177 177
 
178
-				if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) {
179
-					do_action( 'woocommerce_stripe_updated' );
178
+				if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) {
179
+					do_action('woocommerce_stripe_updated');
180 180
 
181
-					if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) {
182
-						define( 'WC_STRIPE_INSTALLING', true );
181
+					if ( ! defined('WC_STRIPE_INSTALLING')) {
182
+						define('WC_STRIPE_INSTALLING', true);
183 183
 					}
184 184
 
185 185
 					$this->update_plugin_version();
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
 			 * @since 1.0.0
193 193
 			 * @version 4.0.0
194 194
 			 */
195
-			public function plugin_action_links( $links ) {
195
+			public function plugin_action_links($links) {
196 196
 				$plugin_links = array(
197
-					'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
198
-					'<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
199
-					'<a href="https://woocommerce.com/my-account/create-a-ticket?broken=primary&select=18627">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
197
+					'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>',
198
+					'<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>',
199
+					'<a href="https://woocommerce.com/my-account/create-a-ticket?broken=primary&select=18627">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>',
200 200
 				);
201
-				return array_merge( $plugin_links, $links );
201
+				return array_merge($plugin_links, $links);
202 202
 			}
203 203
 
204 204
 			/**
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 			 * @since 1.0.0
208 208
 			 * @version 4.0.0
209 209
 			 */
210
-			public function add_gateways( $methods ) {
211
-				if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
210
+			public function add_gateways($methods) {
211
+				if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
212 212
 					$methods[] = 'WC_Stripe_Subs_Compat';
213 213
 					$methods[] = 'WC_Stripe_Sepa_Subs_Compat';
214 214
 				} else {
@@ -234,28 +234,28 @@  discard block
 block discarded – undo
234 234
 			 * @since 4.0.0
235 235
 			 * @version 4.0.0
236 236
 			 */
237
-			public function filter_gateway_order_admin( $sections ) {
238
-				unset( $sections['stripe'] );
239
-				unset( $sections['stripe_bancontact'] );
240
-				unset( $sections['stripe_sofort'] );
241
-				unset( $sections['stripe_giropay'] );
242
-				unset( $sections['stripe_eps'] );
243
-				unset( $sections['stripe_ideal'] );
244
-				unset( $sections['stripe_p24'] );
245
-				unset( $sections['stripe_alipay'] );
246
-				unset( $sections['stripe_sepa'] );
247
-				unset( $sections['stripe_multibanco'] );
237
+			public function filter_gateway_order_admin($sections) {
238
+				unset($sections['stripe']);
239
+				unset($sections['stripe_bancontact']);
240
+				unset($sections['stripe_sofort']);
241
+				unset($sections['stripe_giropay']);
242
+				unset($sections['stripe_eps']);
243
+				unset($sections['stripe_ideal']);
244
+				unset($sections['stripe_p24']);
245
+				unset($sections['stripe_alipay']);
246
+				unset($sections['stripe_sepa']);
247
+				unset($sections['stripe_multibanco']);
248 248
 
249 249
 				$sections['stripe']            = 'Stripe';
250
-				$sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
251
-				$sections['stripe_sofort']     = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
252
-				$sections['stripe_giropay']    = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
253
-				$sections['stripe_eps']        = __( 'Stripe EPS', 'woocommerce-gateway-stripe' );
254
-				$sections['stripe_ideal']      = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
255
-				$sections['stripe_p24']        = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
256
-				$sections['stripe_alipay']     = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
257
-				$sections['stripe_sepa']       = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
258
-				$sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' );
250
+				$sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
251
+				$sections['stripe_sofort']     = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
252
+				$sections['stripe_giropay']    = __('Stripe Giropay', 'woocommerce-gateway-stripe');
253
+				$sections['stripe_eps']        = __('Stripe EPS', 'woocommerce-gateway-stripe');
254
+				$sections['stripe_ideal']      = __('Stripe iDeal', 'woocommerce-gateway-stripe');
255
+				$sections['stripe_p24']        = __('Stripe P24', 'woocommerce-gateway-stripe');
256
+				$sections['stripe_alipay']     = __('Stripe Alipay', 'woocommerce-gateway-stripe');
257
+				$sections['stripe_sepa']       = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
258
+				$sections['stripe_multibanco'] = __('Stripe Multibanco', 'woocommerce-gateway-stripe');
259 259
 
260 260
 				return $sections;
261 261
 			}
@@ -266,16 +266,16 @@  discard block
 block discarded – undo
266 266
 			 * @param WC_Email[] $email_classes All existing emails.
267 267
 			 * @return WC_Email[]
268 268
 			 */
269
-			public function add_emails( $email_classes ) {
269
+			public function add_emails($email_classes) {
270 270
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php';
271 271
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php';
272 272
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php';
273 273
 				require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php';
274 274
 
275 275
 				// Add all emails, generated by the gateway.
276
-				$email_classes['WC_Stripe_Email_Failed_Renewal_Authentication']  = new WC_Stripe_Email_Failed_Renewal_Authentication( $email_classes );
277
-				$email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication( $email_classes );
278
-				$email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry( $email_classes );
276
+				$email_classes['WC_Stripe_Email_Failed_Renewal_Authentication']  = new WC_Stripe_Email_Failed_Renewal_Authentication($email_classes);
277
+				$email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication($email_classes);
278
+				$email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry($email_classes);
279 279
 
280 280
 				return $email_classes;
281 281
 			}
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   4.0.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -64,41 +64,41 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		self::$_this            = $this;
67
-		$this->stripe_settings  = get_option( 'woocommerce_stripe_settings', array() );
68
-		$this->testmode         = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
69
-		$this->publishable_key  = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
70
-		$this->secret_key       = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : '';
71
-		$this->total_label      = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
67
+		$this->stripe_settings  = get_option('woocommerce_stripe_settings', array());
68
+		$this->testmode         = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
69
+		$this->publishable_key  = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
70
+		$this->secret_key       = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : '';
71
+		$this->total_label      = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
72 72
 
73
-		if ( $this->testmode ) {
74
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
75
-			$this->secret_key      = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : '';
73
+		if ($this->testmode) {
74
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
75
+			$this->secret_key      = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : '';
76 76
 		}
77 77
 
78
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
78
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
79 79
 
80 80
 		// Checks if Stripe Gateway is enabled.
81
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
81
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
82 82
 			return;
83 83
 		}
84 84
 
85 85
 		// Checks if Payment Request is enabled.
86
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
86
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
87 87
 			return;
88 88
 		}
89 89
 
90 90
 		// Don't load for change payment method page.
91
-		if ( isset( $_GET['change_payment_method'] ) ) {
91
+		if (isset($_GET['change_payment_method'])) {
92 92
 			return;
93 93
 		}
94 94
 
95
-		$wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
95
+		$wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2);
96 96
 
97
-		if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) {
97
+		if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) {
98 98
 			return;
99 99
 		}
100 100
 
101
-		add_action( 'template_redirect', array( $this, 'set_session' ) );
101
+		add_action('template_redirect', array($this, 'set_session'));
102 102
 		$this->init();
103 103
 	}
104 104
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @return array The list of countries.
110 110
 	 */
111 111
 	public function get_stripe_supported_countries() {
112
-		return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) );
112
+		return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US'));
113 113
 	}
114 114
 
115 115
 	/**
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @return bool
120 120
 	 */
121 121
 	public function are_keys_set() {
122
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
122
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
123 123
 			return false;
124 124
 		}
125 125
 
@@ -143,18 +143,18 @@  discard block
 block discarded – undo
143 143
 	 * @since 4.0.0
144 144
 	 */
145 145
 	public function set_session() {
146
-		if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
146
+		if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) {
147 147
 			return;
148 148
 		}
149 149
 
150
-		$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
150
+		$session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler');
151 151
 		$wc_session    = new $session_class();
152 152
 
153
-		if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
153
+		if (version_compare(WC_VERSION, '3.3', '>=')) {
154 154
 			$wc_session->init();
155 155
 		}
156 156
 
157
-		$wc_session->set_customer_session_cookie( true );
157
+		$wc_session->set_customer_session_cookie(true);
158 158
 	}
159 159
 
160 160
 	/**
@@ -164,40 +164,40 @@  discard block
 block discarded – undo
164 164
 	 * @version 4.0.0
165 165
 	 */
166 166
 	public function init() {
167
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
167
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
168 168
 
169 169
 		/*
170 170
 		 * In order to display the Payment Request button in the correct position,
171 171
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
172 172
 		 * CSS is used to position the button.
173 173
 		 */
174
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
175
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
176
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
174
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
175
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
176
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
177 177
 		} else {
178
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
179
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
178
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
179
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
180 180
 		}
181 181
 
182
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
183
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
182
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
183
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
184 184
 
185
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
186
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
185
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
186
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
187 187
 
188
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
189
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
190
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
191
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
192
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
193
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
194
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
195
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
188
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
189
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
190
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
191
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
192
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
193
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
194
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
195
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
196 196
 
197
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
198
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
197
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
198
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
199 199
 
200
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
200
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
201 201
 	}
202 202
 
203 203
 	/**
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 * @return string
209 209
 	 */
210 210
 	public function get_button_type() {
211
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
211
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
212 212
 	}
213 213
 
214 214
 	/**
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 * @return string
220 220
 	 */
221 221
 	public function get_button_theme() {
222
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
222
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
223 223
 	}
224 224
 
225 225
 	/**
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 * @return string
231 231
 	 */
232 232
 	public function get_button_height() {
233
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
233
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
234 234
 	}
235 235
 
236 236
 	/**
@@ -240,40 +240,40 @@  discard block
 block discarded – undo
240 240
 	 * @version 4.0.0
241 241
 	 */
242 242
 	public function get_product_data() {
243
-		if ( ! is_product() ) {
243
+		if ( ! is_product()) {
244 244
 			return false;
245 245
 		}
246 246
 
247 247
 		global $post;
248 248
 
249
-		$product = wc_get_product( $post->ID );
249
+		$product = wc_get_product($post->ID);
250 250
 
251 251
 		$data  = array();
252 252
 		$items = array();
253 253
 
254 254
 		$items[] = array(
255
-			'label'  => WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name(),
256
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ),
255
+			'label'  => WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name(),
256
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()),
257 257
 		);
258 258
 
259
-		if ( wc_tax_enabled() ) {
259
+		if (wc_tax_enabled()) {
260 260
 			$items[] = array(
261
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
261
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
262 262
 				'amount'  => 0,
263 263
 				'pending' => true,
264 264
 			);
265 265
 		}
266 266
 
267
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
267
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
268 268
 			$items[] = array(
269
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
269
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
270 270
 				'amount'  => 0,
271 271
 				'pending' => true,
272 272
 			);
273 273
 
274 274
 			$data['shippingOptions'] = array(
275 275
 				'id'     => 'pending',
276
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
276
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
277 277
 				'detail' => '',
278 278
 				'amount' => 0,
279 279
 			);
@@ -281,41 +281,41 @@  discard block
 block discarded – undo
281 281
 
282 282
 		$data['displayItems'] = $items;
283 283
 		$data['total']        = array(
284
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
285
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ),
284
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
285
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()),
286 286
 			'pending' => true,
287 287
 		);
288 288
 
289
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
290
-		$data['currency']        = strtolower( get_woocommerce_currency() );
291
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
289
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
290
+		$data['currency']        = strtolower(get_woocommerce_currency());
291
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
292 292
 
293
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
293
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
294 294
 	}
295 295
 
296 296
 	/**
297 297
 	 * Filters the gateway title to reflect Payment Request type
298 298
 	 *
299 299
 	 */
300
-	public function filter_gateway_title( $title, $id ) {
300
+	public function filter_gateway_title($title, $id) {
301 301
 		global $post;
302 302
 
303
-		if ( ! is_object( $post ) ) {
303
+		if ( ! is_object($post)) {
304 304
 			return $title;
305 305
 		}
306 306
 
307
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
308
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
307
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
308
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
309 309
 		} else {
310
-			$order        = wc_get_order( $post->ID );
311
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
310
+			$order        = wc_get_order($post->ID);
311
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
312 312
 		}
313 313
 
314
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
314
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
315 315
 			return $method_title;
316 316
 		}
317 317
 
318
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
318
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
319 319
 			return $method_title;
320 320
 		}
321 321
 
@@ -328,16 +328,16 @@  discard block
 block discarded – undo
328 328
 	 * @since 3.1.4
329 329
 	 * @version 4.0.0
330 330
 	 */
331
-	public function postal_code_validation( $valid, $postcode, $country ) {
331
+	public function postal_code_validation($valid, $postcode, $country) {
332 332
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
333 333
 
334
-		if ( ! isset( $gateways['stripe'] ) ) {
334
+		if ( ! isset($gateways['stripe'])) {
335 335
 			return $valid;
336 336
 		}
337 337
 
338
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
338
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
339 339
 
340
-		if ( 'apple_pay' !== $payment_request_type ) {
340
+		if ('apple_pay' !== $payment_request_type) {
341 341
 			return $valid;
342 342
 		}
343 343
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
348 348
 		 * Note that this only works with shipping providers that don't validate full postal codes.
349 349
 		 */
350
-		if ( 'GB' === $country || 'CA' === $country ) {
350
+		if ('GB' === $country || 'CA' === $country) {
351 351
 			return true;
352 352
 		}
353 353
 
@@ -362,29 +362,29 @@  discard block
 block discarded – undo
362 362
 	 * @param int $order_id
363 363
 	 * @param array $posted_data The posted data from checkout form.
364 364
 	 */
365
-	public function add_order_meta( $order_id, $posted_data ) {
366
-		if ( empty( $_POST['payment_request_type'] ) ) {
365
+	public function add_order_meta($order_id, $posted_data) {
366
+		if (empty($_POST['payment_request_type'])) {
367 367
 			return;
368 368
 		}
369 369
 
370
-		$order = wc_get_order( $order_id );
370
+		$order = wc_get_order($order_id);
371 371
 
372
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
372
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
373 373
 
374
-		if ( 'apple_pay' === $payment_request_type ) {
375
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
376
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
374
+		if ('apple_pay' === $payment_request_type) {
375
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
376
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
377 377
 			} else {
378
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
378
+				$order->set_payment_method_title('Apple Pay (Stripe)');
379 379
 				$order->save();
380 380
 			}
381 381
 		}
382 382
 
383
-		if ( 'payment_request_api' === $payment_request_type ) {
384
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
385
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
383
+		if ('payment_request_api' === $payment_request_type) {
384
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
385
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
386 386
 			} else {
387
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
387
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
388 388
 				$order->save();
389 389
 			}
390 390
 		}
@@ -423,20 +423,20 @@  discard block
 block discarded – undo
423 423
 	 * @return bool
424 424
 	 */
425 425
 	public function allowed_items_in_cart() {
426
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
427
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
426
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
427
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
428 428
 
429
-			if ( ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
429
+			if ( ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
430 430
 				return false;
431 431
 			}
432 432
 
433 433
 			// Trial subscriptions with shipping are not supported
434
-			if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) {
434
+			if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) {
435 435
 				return false;
436 436
 			}
437 437
 
438 438
 			// Pre Orders compatbility where we don't support charge upon release.
439
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) {
439
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) {
440 440
 				return false;
441 441
 			}
442 442
 		}
@@ -452,73 +452,73 @@  discard block
 block discarded – undo
452 452
 	 */
453 453
 	public function scripts() {
454 454
 		// If keys are not set bail.
455
-		if ( ! $this->are_keys_set() ) {
456
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
455
+		if ( ! $this->are_keys_set()) {
456
+			WC_Stripe_Logger::log('Keys are not set correctly.');
457 457
 			return;
458 458
 		}
459 459
 
460 460
 		// If no SSL bail.
461
-		if ( ! $this->testmode && ! is_ssl() ) {
462
-			WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' );
461
+		if ( ! $this->testmode && ! is_ssl()) {
462
+			WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.');
463 463
 			return;
464 464
 		}
465 465
 
466
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
466
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
467 467
 			return;
468 468
 		}
469 469
 
470
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
470
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
471 471
 			return;
472 472
 		}
473 473
 
474
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
474
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
475 475
 
476 476
 		$stripe_params = array(
477
-			'ajax_url'        => WC_AJAX::get_endpoint( '%%endpoint%%' ),
477
+			'ajax_url'        => WC_AJAX::get_endpoint('%%endpoint%%'),
478 478
 			'stripe'          => array(
479 479
 				'key'                => $this->publishable_key,
480
-				'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
480
+				'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
481 481
 			),
482 482
 			'nonce'           => array(
483
-				'payment'                   => wp_create_nonce( 'wc-stripe-payment-request' ),
484
-				'shipping'                  => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
485
-				'update_shipping'           => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
486
-				'checkout'                  => wp_create_nonce( 'woocommerce-process_checkout' ),
487
-				'add_to_cart'               => wp_create_nonce( 'wc-stripe-add-to-cart' ),
488
-				'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
489
-				'log_errors'                => wp_create_nonce( 'wc-stripe-log-errors' ),
490
-				'clear_cart'                => wp_create_nonce( 'wc-stripe-clear-cart' ),
483
+				'payment'                   => wp_create_nonce('wc-stripe-payment-request'),
484
+				'shipping'                  => wp_create_nonce('wc-stripe-payment-request-shipping'),
485
+				'update_shipping'           => wp_create_nonce('wc-stripe-update-shipping-method'),
486
+				'checkout'                  => wp_create_nonce('woocommerce-process_checkout'),
487
+				'add_to_cart'               => wp_create_nonce('wc-stripe-add-to-cart'),
488
+				'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'),
489
+				'log_errors'                => wp_create_nonce('wc-stripe-log-errors'),
490
+				'clear_cart'                => wp_create_nonce('wc-stripe-clear-cart'),
491 491
 			),
492 492
 			'i18n'            => array(
493
-				'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
493
+				'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
494 494
 				/* translators: Do not translate the [option] placeholder */
495
-				'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
495
+				'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
496 496
 			),
497 497
 			'checkout'        => array(
498 498
 				'url'            => wc_get_checkout_url(),
499
-				'currency_code'  => strtolower( get_woocommerce_currency() ),
500
-				'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
499
+				'currency_code'  => strtolower(get_woocommerce_currency()),
500
+				'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
501 501
 				'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
502 502
 			),
503 503
 			'button'          => array(
504 504
 				'type'   => $this->get_button_type(),
505 505
 				'theme'  => $this->get_button_theme(),
506 506
 				'height' => $this->get_button_height(),
507
-				'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US.
507
+				'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US.
508 508
 			),
509 509
 			'is_product_page' => is_product(),
510 510
 			'product'         => $this->get_product_data(),
511 511
 		);
512 512
 
513
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
514
-		wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true );
513
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
514
+		wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true);
515 515
 
516
-		wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) );
516
+		wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params));
517 517
 
518
-		wp_enqueue_script( 'wc_stripe_payment_request' );
518
+		wp_enqueue_script('wc_stripe_payment_request');
519 519
 
520 520
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
521
-		if ( isset( $gateways['stripe'] ) ) {
521
+		if (isset($gateways['stripe'])) {
522 522
 			$gateways['stripe']->payment_scripts();
523 523
 		}
524 524
 	}
@@ -534,23 +534,23 @@  discard block
 block discarded – undo
534 534
 
535 535
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
536 536
 
537
-		if ( ! isset( $gateways['stripe'] ) ) {
537
+		if ( ! isset($gateways['stripe'])) {
538 538
 			return;
539 539
 		}
540 540
 
541
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
541
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
542 542
 			return;
543 543
 		}
544 544
 
545
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
545
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
546 546
 			return;
547 547
 		}
548 548
 
549
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
549
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
550 550
 			return;
551 551
 		} else {
552
-			if ( ! $this->allowed_items_in_cart() ) {
553
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
552
+			if ( ! $this->allowed_items_in_cart()) {
553
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
554 554
 				return;
555 555
 			}
556 556
 		}
@@ -574,28 +574,28 @@  discard block
 block discarded – undo
574 574
 
575 575
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
576 576
 
577
-		if ( ! isset( $gateways['stripe'] ) ) {
577
+		if ( ! isset($gateways['stripe'])) {
578 578
 			return;
579 579
 		}
580 580
 
581
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
581
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
582 582
 			return;
583 583
 		}
584 584
 
585
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
585
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) {
586 586
 			return;
587 587
 		}
588 588
 
589
-		if ( is_product() && ! $this->should_show_payment_button_on_product_page() ) {
589
+		if (is_product() && ! $this->should_show_payment_button_on_product_page()) {
590 590
 			return;
591 591
 		} else {
592
-			if ( ! $this->allowed_items_in_cart() ) {
593
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
592
+			if ( ! $this->allowed_items_in_cart()) {
593
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
594 594
 				return;
595 595
 			}
596 596
 		}
597 597
 		?>
598
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> &mdash;</p>
598
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> &mdash;</p>
599 599
 		<?php
600 600
 	}
601 601
 
@@ -611,31 +611,31 @@  discard block
 block discarded – undo
611 611
 	private function should_show_payment_button_on_product_page() {
612 612
 		global $post;
613 613
 
614
-		$product = wc_get_product( $post->ID );
614
+		$product = wc_get_product($post->ID);
615 615
 
616
-		if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
616
+		if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) {
617 617
 			return false;
618 618
 		}
619 619
 
620
-		if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
620
+		if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
621 621
 			return false;
622 622
 		}
623 623
 
624 624
 		// Trial subscriptions with shipping are not supported
625
-		if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) {
625
+		if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) {
626 626
 			return false;
627 627
 		}
628 628
 
629 629
 		// Pre Orders charge upon release not supported.
630
-		if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
631
-			WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
630
+		if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
631
+			WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
632 632
 			return false;
633 633
 		}
634 634
 
635
-		if ( class_exists( 'WC_Product_Addons_Helper' ) ) {
636
-			$product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() );
637
-			foreach ( $product_addons as $addon ) {
638
-				if ( 'file_upload' === $addon['type'] ) {
635
+		if (class_exists('WC_Product_Addons_Helper')) {
636
+			$product_addons = WC_Product_Addons_Helper::get_product_addons($product->get_id());
637
+			foreach ($product_addons as $addon) {
638
+				if ('file_upload' === $addon['type']) {
639 639
 					return false;
640 640
 				}
641 641
 			}
@@ -651,11 +651,11 @@  discard block
 block discarded – undo
651 651
 	 * @version 4.0.0
652 652
 	 */
653 653
 	public function ajax_log_errors() {
654
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
654
+		check_ajax_referer('wc-stripe-log-errors', 'security');
655 655
 
656
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
656
+		$errors = wc_clean(stripslashes($_POST['errors']));
657 657
 
658
-		WC_Stripe_Logger::log( $errors );
658
+		WC_Stripe_Logger::log($errors);
659 659
 
660 660
 		exit;
661 661
 	}
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 	 * @version 4.0.0
668 668
 	 */
669 669
 	public function ajax_clear_cart() {
670
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
670
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
671 671
 
672 672
 		WC()->cart->empty_cart();
673 673
 		exit;
@@ -677,10 +677,10 @@  discard block
 block discarded – undo
677 677
 	 * Get cart details.
678 678
 	 */
679 679
 	public function ajax_get_cart_details() {
680
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
680
+		check_ajax_referer('wc-stripe-payment-request', 'security');
681 681
 
682
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
683
-			define( 'WOOCOMMERCE_CART', true );
682
+		if ( ! defined('WOOCOMMERCE_CART')) {
683
+			define('WOOCOMMERCE_CART', true);
684 684
 		}
685 685
 
686 686
 		WC()->cart->calculate_totals();
@@ -691,14 +691,14 @@  discard block
 block discarded – undo
691 691
 		$data = array(
692 692
 			'shipping_required' => WC()->cart->needs_shipping(),
693 693
 			'order_data'        => array(
694
-				'currency'     => strtolower( $currency ),
695
-				'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
694
+				'currency'     => strtolower($currency),
695
+				'country_code' => substr(get_option('woocommerce_default_country'), 0, 2),
696 696
 			),
697 697
 		);
698 698
 
699 699
 		$data['order_data'] += $this->build_display_items();
700 700
 
701
-		wp_send_json( $data );
701
+		wp_send_json($data);
702 702
 	}
703 703
 
704 704
 	/**
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	 * @see WC_Shipping::get_packages().
710 710
 	 */
711 711
 	public function ajax_get_shipping_options() {
712
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
712
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
713 713
 
714 714
 		try {
715 715
 			// Set the shipping package.
@@ -725,34 +725,34 @@  discard block
 block discarded – undo
725 725
 				)
726 726
 			);
727 727
 
728
-			$this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) );
728
+			$this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted));
729 729
 
730 730
 			// Set the shipping options.
731 731
 			$data     = array();
732 732
 			$packages = WC()->shipping->get_packages();
733 733
 
734
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
735
-				foreach ( $packages as $package_key => $package ) {
736
-					if ( empty( $package['rates'] ) ) {
737
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
734
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
735
+				foreach ($packages as $package_key => $package) {
736
+					if (empty($package['rates'])) {
737
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
738 738
 					}
739 739
 
740
-					foreach ( $package['rates'] as $key => $rate ) {
740
+					foreach ($package['rates'] as $key => $rate) {
741 741
 						$data['shipping_options'][] = array(
742 742
 							'id'     => $rate->id,
743 743
 							'label'  => $rate->label,
744 744
 							'detail' => '',
745
-							'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
745
+							'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost),
746 746
 						);
747 747
 					}
748 748
 				}
749 749
 			} else {
750
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
750
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
751 751
 			}
752 752
 
753
-			if ( isset( $data[0] ) ) {
753
+			if (isset($data[0])) {
754 754
 				// Auto select the first shipping method.
755
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
755
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
756 756
 			}
757 757
 
758 758
 			WC()->cart->calculate_totals();
@@ -760,12 +760,12 @@  discard block
 block discarded – undo
760 760
 			$data          += $this->build_display_items();
761 761
 			$data['result'] = 'success';
762 762
 
763
-			wp_send_json( $data );
764
-		} catch ( Exception $e ) {
763
+			wp_send_json($data);
764
+		} catch (Exception $e) {
765 765
 			$data          += $this->build_display_items();
766 766
 			$data['result'] = 'invalid_shipping_address';
767 767
 
768
-			wp_send_json( $data );
768
+			wp_send_json($data);
769 769
 		}
770 770
 	}
771 771
 
@@ -773,22 +773,22 @@  discard block
 block discarded – undo
773 773
 	 * Update shipping method.
774 774
 	 */
775 775
 	public function ajax_update_shipping_method() {
776
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
776
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
777 777
 
778
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
779
-			define( 'WOOCOMMERCE_CART', true );
778
+		if ( ! defined('WOOCOMMERCE_CART')) {
779
+			define('WOOCOMMERCE_CART', true);
780 780
 		}
781 781
 
782
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
783
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
782
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
783
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
784 784
 
785
-		if ( is_array( $shipping_method ) ) {
786
-			foreach ( $shipping_method as $i => $value ) {
787
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
785
+		if (is_array($shipping_method)) {
786
+			foreach ($shipping_method as $i => $value) {
787
+				$chosen_shipping_methods[$i] = wc_clean($value);
788 788
 			}
789 789
 		}
790 790
 
791
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
791
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
792 792
 
793 793
 		WC()->cart->calculate_totals();
794 794
 
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 		$data          += $this->build_display_items();
797 797
 		$data['result'] = 'success';
798 798
 
799
-		wp_send_json( $data );
799
+		wp_send_json($data);
800 800
 	}
801 801
 
802 802
 	/**
@@ -807,47 +807,47 @@  discard block
 block discarded – undo
807 807
 	 * @return array $data
808 808
 	 */
809 809
 	public function ajax_get_selected_product_data() {
810
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
810
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
811 811
 
812 812
 		try {
813
-			$product_id   = absint( $_POST['product_id'] );
814
-			$qty          = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id );
815
-			$addon_value  = isset( $_POST['addon_value'] ) ? max( floatval( $_POST['addon_value'] ), 0 ) : 0;
816
-			$product      = wc_get_product( $product_id );
813
+			$product_id   = absint($_POST['product_id']);
814
+			$qty          = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id);
815
+			$addon_value  = isset($_POST['addon_value']) ? max(floatval($_POST['addon_value']), 0) : 0;
816
+			$product      = wc_get_product($product_id);
817 817
 			$variation_id = null;
818 818
 
819
-			if ( ! is_a( $product, 'WC_Product' ) ) {
820
-				throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) );
819
+			if ( ! is_a($product, 'WC_Product')) {
820
+				throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id));
821 821
 			}
822 822
 
823
-			if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
824
-				$attributes = array_map( 'wc_clean', $_POST['attributes'] );
823
+			if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
824
+				$attributes = array_map('wc_clean', $_POST['attributes']);
825 825
 
826
-				if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
827
-					$variation_id = $product->get_matching_variation( $attributes );
826
+				if (WC_Stripe_Helper::is_wc_lt('3.0')) {
827
+					$variation_id = $product->get_matching_variation($attributes);
828 828
 				} else {
829
-					$data_store   = WC_Data_Store::load( 'product' );
830
-					$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
829
+					$data_store   = WC_Data_Store::load('product');
830
+					$variation_id = $data_store->find_matching_product_variation($product, $attributes);
831 831
 				}
832 832
 
833
-				if ( ! empty( $variation_id ) ) {
834
-					$product = wc_get_product( $variation_id );
833
+				if ( ! empty($variation_id)) {
834
+					$product = wc_get_product($variation_id);
835 835
 				}
836
-			} elseif ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) {
837
-				$product = wc_get_product( $product_id );
836
+			} elseif ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) {
837
+				$product = wc_get_product($product_id);
838 838
 			}
839 839
 
840 840
 			// Force quantity to 1 if sold individually and check for existing item in cart.
841
-			if ( $product->is_sold_individually() ) {
842
-				$qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id );
841
+			if ($product->is_sold_individually()) {
842
+				$qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id);
843 843
 			}
844 844
 
845
-			if ( ! $product->has_enough_stock( $qty ) ) {
845
+			if ( ! $product->has_enough_stock($qty)) {
846 846
 				/* translators: 1: product name 2: quantity in stock */
847
-				throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) );
847
+				throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product)));
848 848
 			}
849 849
 
850
-			$total = $qty * ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ) + $addon_value;
850
+			$total = $qty * (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()) + $addon_value;
851 851
 
852 852
 			$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
853 853
 
@@ -855,28 +855,28 @@  discard block
 block discarded – undo
855 855
 			$items = array();
856 856
 
857 857
 			$items[] = array(
858
-				'label'  => ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name() ) . $quantity_label,
859
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
858
+				'label'  => (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name()) . $quantity_label,
859
+				'amount' => WC_Stripe_Helper::get_stripe_amount($total),
860 860
 			);
861 861
 
862
-			if ( wc_tax_enabled() ) {
862
+			if (wc_tax_enabled()) {
863 863
 				$items[] = array(
864
-					'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
864
+					'label'   => __('Tax', 'woocommerce-gateway-stripe'),
865 865
 					'amount'  => 0,
866 866
 					'pending' => true,
867 867
 				);
868 868
 			}
869 869
 
870
-			if ( wc_shipping_enabled() && $product->needs_shipping() ) {
870
+			if (wc_shipping_enabled() && $product->needs_shipping()) {
871 871
 				$items[] = array(
872
-					'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
872
+					'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
873 873
 					'amount'  => 0,
874 874
 					'pending' => true,
875 875
 				);
876 876
 
877 877
 				$data['shippingOptions'] = array(
878 878
 					'id'     => 'pending',
879
-					'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
879
+					'label'  => __('Pending', 'woocommerce-gateway-stripe'),
880 880
 					'detail' => '',
881 881
 					'amount' => 0,
882 882
 				);
@@ -885,17 +885,17 @@  discard block
 block discarded – undo
885 885
 			$data['displayItems'] = $items;
886 886
 			$data['total']        = array(
887 887
 				'label'   => $this->total_label,
888
-				'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
888
+				'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
889 889
 				'pending' => true,
890 890
 			);
891 891
 
892
-			$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
893
-			$data['currency']        = strtolower( get_woocommerce_currency() );
894
-			$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
892
+			$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
893
+			$data['currency']        = strtolower(get_woocommerce_currency());
894
+			$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
895 895
 
896
-			wp_send_json( $data );
897
-		} catch ( Exception $e ) {
898
-			wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) );
896
+			wp_send_json($data);
897
+		} catch (Exception $e) {
898
+			wp_send_json(array('error' => wp_strip_all_tags($e->getMessage())));
899 899
 		}
900 900
 	}
901 901
 
@@ -907,37 +907,37 @@  discard block
 block discarded – undo
907 907
 	 * @return array $data
908 908
 	 */
909 909
 	public function ajax_add_to_cart() {
910
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
910
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
911 911
 
912
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
913
-			define( 'WOOCOMMERCE_CART', true );
912
+		if ( ! defined('WOOCOMMERCE_CART')) {
913
+			define('WOOCOMMERCE_CART', true);
914 914
 		}
915 915
 
916 916
 		WC()->shipping->reset_shipping();
917 917
 
918
-		$product_id   = absint( $_POST['product_id'] );
919
-		$qty          = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
920
-		$product      = wc_get_product( $product_id );
921
-		$product_type = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type();
918
+		$product_id   = absint($_POST['product_id']);
919
+		$qty          = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
920
+		$product      = wc_get_product($product_id);
921
+		$product_type = WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type();
922 922
 
923 923
 		// First empty the cart to prevent wrong calculation.
924 924
 		WC()->cart->empty_cart();
925 925
 
926
-		if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) {
927
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
926
+		if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) {
927
+			$attributes = array_map('wc_clean', $_POST['attributes']);
928 928
 
929
-			if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
930
-				$variation_id = $product->get_matching_variation( $attributes );
929
+			if (WC_Stripe_Helper::is_wc_lt('3.0')) {
930
+				$variation_id = $product->get_matching_variation($attributes);
931 931
 			} else {
932
-				$data_store   = WC_Data_Store::load( 'product' );
933
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
932
+				$data_store   = WC_Data_Store::load('product');
933
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
934 934
 			}
935 935
 
936
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
936
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
937 937
 		}
938 938
 
939
-		if ( 'simple' === $product_type || 'subscription' === $product_type ) {
940
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
939
+		if ('simple' === $product_type || 'subscription' === $product_type) {
940
+			WC()->cart->add_to_cart($product->get_id(), $qty);
941 941
 		}
942 942
 
943 943
 		WC()->cart->calculate_totals();
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
 		$data          += $this->build_display_items();
947 947
 		$data['result'] = 'success';
948 948
 
949
-		wp_send_json( $data );
949
+		wp_send_json($data);
950 950
 	}
951 951
 
952 952
 	/**
@@ -959,31 +959,31 @@  discard block
 block discarded – undo
959 959
 	 * @version 4.0.0
960 960
 	 */
961 961
 	public function normalize_state() {
962
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
963
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
964
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
965
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
962
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
963
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
964
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
965
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
966 966
 
967
-		if ( $billing_state && $billing_country ) {
968
-			$valid_states = WC()->countries->get_states( $billing_country );
967
+		if ($billing_state && $billing_country) {
968
+			$valid_states = WC()->countries->get_states($billing_country);
969 969
 
970 970
 			// Valid states found for country.
971
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
972
-				foreach ( $valid_states as $state_abbr => $state ) {
973
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
971
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
972
+				foreach ($valid_states as $state_abbr => $state) {
973
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
974 974
 						$_POST['billing_state'] = $state_abbr;
975 975
 					}
976 976
 				}
977 977
 			}
978 978
 		}
979 979
 
980
-		if ( $shipping_state && $shipping_country ) {
981
-			$valid_states = WC()->countries->get_states( $shipping_country );
980
+		if ($shipping_state && $shipping_country) {
981
+			$valid_states = WC()->countries->get_states($shipping_country);
982 982
 
983 983
 			// Valid states found for country.
984
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
985
-				foreach ( $valid_states as $state_abbr => $state ) {
986
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
984
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
985
+				foreach ($valid_states as $state_abbr => $state) {
986
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
987 987
 						$_POST['shipping_state'] = $state_abbr;
988 988
 					}
989 989
 				}
@@ -998,19 +998,19 @@  discard block
 block discarded – undo
998 998
 	 * @version 4.0.0
999 999
 	 */
1000 1000
 	public function ajax_create_order() {
1001
-		if ( WC()->cart->is_empty() ) {
1002
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
1001
+		if (WC()->cart->is_empty()) {
1002
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
1003 1003
 		}
1004 1004
 
1005
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
1006
-			define( 'WOOCOMMERCE_CHECKOUT', true );
1005
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
1006
+			define('WOOCOMMERCE_CHECKOUT', true);
1007 1007
 		}
1008 1008
 
1009 1009
 		$this->normalize_state();
1010 1010
 
1011 1011
 		WC()->checkout()->process_checkout();
1012 1012
 
1013
-		die( 0 );
1013
+		die(0);
1014 1014
 	}
1015 1015
 
1016 1016
 	/**
@@ -1020,41 +1020,41 @@  discard block
 block discarded – undo
1020 1020
 	 * @version 4.0.0
1021 1021
 	 * @param array $address
1022 1022
 	 */
1023
-	protected function calculate_shipping( $address = array() ) {
1023
+	protected function calculate_shipping($address = array()) {
1024 1024
 		$country   = $address['country'];
1025 1025
 		$state     = $address['state'];
1026 1026
 		$postcode  = $address['postcode'];
1027 1027
 		$city      = $address['city'];
1028 1028
 		$address_1 = $address['address'];
1029 1029
 		$address_2 = $address['address_2'];
1030
-		$wc_states = WC()->countries->get_states( $country );
1030
+		$wc_states = WC()->countries->get_states($country);
1031 1031
 
1032 1032
 		/**
1033 1033
 		 * In some versions of Chrome, state can be a full name. So we need
1034 1034
 		 * to convert that to abbreviation as WC is expecting that.
1035 1035
 		 */
1036
-		if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) {
1037
-			$state = array_search( ucwords( strtolower( $state ) ), $wc_states, true );
1036
+		if (2 < strlen($state) && ! empty($wc_states)) {
1037
+			$state = array_search(ucwords(strtolower($state)), $wc_states, true);
1038 1038
 		}
1039 1039
 
1040 1040
 		WC()->shipping->reset_shipping();
1041 1041
 
1042
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
1043
-			$postcode = wc_format_postcode( $postcode, $country );
1042
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
1043
+			$postcode = wc_format_postcode($postcode, $country);
1044 1044
 		}
1045 1045
 
1046
-		if ( $country ) {
1047
-			WC()->customer->set_location( $country, $state, $postcode, $city );
1048
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
1046
+		if ($country) {
1047
+			WC()->customer->set_location($country, $state, $postcode, $city);
1048
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
1049 1049
 		} else {
1050
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1051
-			WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1050
+			WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1051
+			WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1052 1052
 		}
1053 1053
 
1054
-		if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) {
1055
-			WC()->customer->calculated_shipping( true );
1054
+		if (WC_Stripe_Helper::is_wc_lt('3.0')) {
1055
+			WC()->customer->calculated_shipping(true);
1056 1056
 		} else {
1057
-			WC()->customer->set_calculated_shipping( true );
1057
+			WC()->customer->set_calculated_shipping(true);
1058 1058
 			WC()->customer->save();
1059 1059
 		}
1060 1060
 
@@ -1071,17 +1071,17 @@  discard block
 block discarded – undo
1071 1071
 		$packages[0]['destination']['address']   = $address_1;
1072 1072
 		$packages[0]['destination']['address_2'] = $address_2;
1073 1073
 
1074
-		foreach ( WC()->cart->get_cart() as $item ) {
1075
-			if ( $item['data']->needs_shipping() ) {
1076
-				if ( isset( $item['line_total'] ) ) {
1074
+		foreach (WC()->cart->get_cart() as $item) {
1075
+			if ($item['data']->needs_shipping()) {
1076
+				if (isset($item['line_total'])) {
1077 1077
 					$packages[0]['contents_cost'] += $item['line_total'];
1078 1078
 				}
1079 1079
 			}
1080 1080
 		}
1081 1081
 
1082
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1082
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1083 1083
 
1084
-		WC()->shipping->calculate_shipping( $packages );
1084
+		WC()->shipping->calculate_shipping($packages);
1085 1085
 	}
1086 1086
 
1087 1087
 	/**
@@ -1090,19 +1090,19 @@  discard block
 block discarded – undo
1090 1090
 	 * @since 3.1.0
1091 1091
 	 * @version 4.0.0
1092 1092
 	 */
1093
-	protected function build_shipping_methods( $shipping_methods ) {
1094
-		if ( empty( $shipping_methods ) ) {
1093
+	protected function build_shipping_methods($shipping_methods) {
1094
+		if (empty($shipping_methods)) {
1095 1095
 			return array();
1096 1096
 		}
1097 1097
 
1098 1098
 		$shipping = array();
1099 1099
 
1100
-		foreach ( $shipping_methods as $method ) {
1100
+		foreach ($shipping_methods as $method) {
1101 1101
 			$shipping[] = array(
1102 1102
 				'id'     => $method['id'],
1103 1103
 				'label'  => $method['label'],
1104 1104
 				'detail' => '',
1105
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1105
+				'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1106 1106
 			);
1107 1107
 		}
1108 1108
 
@@ -1116,8 +1116,8 @@  discard block
 block discarded – undo
1116 1116
 	 * @version 4.0.0
1117 1117
 	 */
1118 1118
 	protected function build_display_items() {
1119
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1120
-			define( 'WOOCOMMERCE_CART', true );
1119
+		if ( ! defined('WOOCOMMERCE_CART')) {
1120
+			define('WOOCOMMERCE_CART', true);
1121 1121
 		}
1122 1122
 
1123 1123
 		$items     = array();
@@ -1125,71 +1125,71 @@  discard block
 block discarded – undo
1125 1125
 		$discounts = 0;
1126 1126
 
1127 1127
 		// Default show only subtotal instead of itemization.
1128
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1129
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1128
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1129
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1130 1130
 				$amount         = $cart_item['line_subtotal'];
1131 1131
 				$subtotal      += $cart_item['line_subtotal'];
1132 1132
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1133 1133
 
1134
-				$product_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1134
+				$product_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1135 1135
 
1136 1136
 				$item = array(
1137 1137
 					'label'  => $product_name . $quantity_label,
1138
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1138
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1139 1139
 				);
1140 1140
 
1141 1141
 				$items[] = $item;
1142 1142
 			}
1143 1143
 		}
1144 1144
 
1145
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1146
-			$discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1145
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1146
+			$discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1147 1147
 		} else {
1148
-			$applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() );
1148
+			$applied_coupons = array_values(WC()->cart->get_coupon_discount_totals());
1149 1149
 
1150
-			foreach ( $applied_coupons as $amount ) {
1150
+			foreach ($applied_coupons as $amount) {
1151 1151
 				$discounts += (float) $amount;
1152 1152
 			}
1153 1153
 		}
1154 1154
 
1155
-		$discounts   = wc_format_decimal( $discounts, WC()->cart->dp );
1156
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1157
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1158
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1159
-		$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false );
1155
+		$discounts   = wc_format_decimal($discounts, WC()->cart->dp);
1156
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1157
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1158
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1159
+		$order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false);
1160 1160
 
1161
-		if ( wc_tax_enabled() ) {
1161
+		if (wc_tax_enabled()) {
1162 1162
 			$items[] = array(
1163
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1164
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1163
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1164
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1165 1165
 			);
1166 1166
 		}
1167 1167
 
1168
-		if ( WC()->cart->needs_shipping() ) {
1168
+		if (WC()->cart->needs_shipping()) {
1169 1169
 			$items[] = array(
1170
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1171
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1170
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1171
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1172 1172
 			);
1173 1173
 		}
1174 1174
 
1175
-		if ( WC()->cart->has_discount() ) {
1175
+		if (WC()->cart->has_discount()) {
1176 1176
 			$items[] = array(
1177
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1178
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1177
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1178
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1179 1179
 			);
1180 1180
 		}
1181 1181
 
1182
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1182
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1183 1183
 			$cart_fees = WC()->cart->fees;
1184 1184
 		} else {
1185 1185
 			$cart_fees = WC()->cart->get_fees();
1186 1186
 		}
1187 1187
 
1188 1188
 		// Include fees and taxes as display items.
1189
-		foreach ( $cart_fees as $key => $fee ) {
1189
+		foreach ($cart_fees as $key => $fee) {
1190 1190
 			$items[] = array(
1191 1191
 				'label'  => $fee->name,
1192
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1192
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1193 1193
 			);
1194 1194
 		}
1195 1195
 
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
 			'displayItems' => $items,
1198 1198
 			'total'        => array(
1199 1199
 				'label'   => $this->total_label,
1200
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1200
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1201 1201
 				'pending' => false,
1202 1202
 			),
1203 1203
 		);
Please login to merge, or discard this patch.