Completed
Pull Request — master (#488)
by Roy
02:06
created
includes/payment-methods/class-wc-gateway-stripe-sepa.php 1 patch
Spacing   +102 added lines, -102 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
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sepa';
60
-		$this->method_title         = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -84,25 +84,25 @@  discard block
 block discarded – undo
84 84
 		// Load the settings.
85 85
 		$this->init_settings();
86 86
 
87
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
88
-		$this->title                = $this->get_option( 'title' );
89
-		$this->description          = $this->get_option( 'description' );
90
-		$this->enabled              = $this->get_option( 'enabled' );
91
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
92
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
93
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
94
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
95
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
96
-
97
-		if ( $this->testmode ) {
98
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
99
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
87
+		$main_settings              = get_option('woocommerce_stripe_settings');
88
+		$this->title                = $this->get_option('title');
89
+		$this->description          = $this->get_option('description');
90
+		$this->enabled              = $this->get_option('enabled');
91
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
92
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
93
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
94
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
95
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
96
+
97
+		if ($this->testmode) {
98
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
99
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
100 100
 		}
101 101
 
102
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
103
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
104
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
105
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
102
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
103
+		add_action('admin_notices', array($this, 'check_environment'));
104
+		add_action('admin_head', array($this, 'remove_admin_notice'));
105
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
 	 * @version 4.0.0
113 113
 	 */
114 114
 	public function check_environment() {
115
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
115
+		if ( ! current_user_can('manage_woocommerce')) {
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		$environment_warning = $this->get_environment_warning();
120 120
 
121
-		if ( $environment_warning ) {
122
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
121
+		if ($environment_warning) {
122
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
123 123
 		}
124 124
 
125
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
126
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
127
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
125
+		foreach ((array) $this->notices as $notice_key => $notice) {
126
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
127
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
128 128
 			echo '</p></div>';
129 129
 		}
130 130
 	}
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @version 4.0.0
138 138
 	 */
139 139
 	public function get_environment_warning() {
140
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
141
-			$message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
140
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
141
+			$message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
142 142
 
143 143
 			return $message;
144 144
 		}
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
 	public function get_supported_currency() {
157
-		return apply_filters( 'wc_stripe_sepa_supported_currencies', array(
157
+		return apply_filters('wc_stripe_sepa_supported_currencies', array(
158 158
 			'EUR',
159
-		) );
159
+		));
160 160
 	}
161 161
 
162 162
 	/**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 	 * @return bool
168 168
 	 */
169 169
 	public function is_available() {
170
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
170
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
171 171
 			return false;
172 172
 		}
173 173
 
174
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
174
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
175 175
 			return false;
176 176
 		}
177 177
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
 		$icons_str .= $icons['sepa'];
194 194
 
195
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
195
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
196 196
 	}
197 197
 
198 198
 	/**
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
 	 * @access public
204 204
 	 */
205 205
 	public function payment_scripts() {
206
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
206
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
207 207
 			return;
208 208
 		}
209 209
 
210
-		wp_enqueue_style( 'stripe_paymentfonts' );
211
-		wp_enqueue_script( 'woocommerce_stripe' );
210
+		wp_enqueue_style('stripe_paymentfonts');
211
+		wp_enqueue_script('woocommerce_stripe');
212 212
 	}
213 213
 
214 214
 	/**
215 215
 	 * Initialize Gateway Settings Form Fields.
216 216
 	 */
217 217
 	public function init_form_fields() {
218
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' );
218
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php');
219 219
 	}
220 220
 
221 221
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	public function mandate_display() {
229 229
 		/* translators: statement descriptor */
230
-		printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) );
230
+		printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor));
231 231
 	}
232 232
 
233 233
 	/**
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	public function form() {
240 240
 		?>
241
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form">
242
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
241
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form">
242
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
243 243
 			<p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p>
244 244
 			<p class="form-row form-row-wide">
245 245
 				<label for="stripe-sepa-owner">
246
-					<?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
246
+					<?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
247 247
 				</label>
248 248
 				<input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
249 249
 			</p>
250 250
 			<p class="form-row form-row-wide">
251 251
 				<label for="stripe-sepa-iban">
252
-					<?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span>
252
+					<?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span>
253 253
 				</label>
254 254
 				<input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" />
255 255
 			</p>
256 256
 			<!-- Used to display form errors -->
257 257
 			<div class="stripe-source-errors" role="alert"></div>
258
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
258
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
259 259
 			<div class="clear"></div>
260 260
 		</fieldset>
261 261
 		<?php
@@ -267,42 +267,42 @@  discard block
 block discarded – undo
267 267
 	public function payment_fields() {
268 268
 		$user                 = wp_get_current_user();
269 269
 		$total                = WC()->cart->total;
270
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
270
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
271 271
 
272 272
 		// If paying from order, we need to get total from order not cart.
273
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
274
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
273
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
274
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
275 275
 			$total = $order->get_total();
276 276
 		}
277 277
 
278
-		if ( is_add_payment_method_page() ) {
279
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
280
-			$total        = '';
278
+		if (is_add_payment_method_page()) {
279
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
280
+			$total = '';
281 281
 		} else {
282 282
 			$pay_button_text = '';
283 283
 		}
284 284
 
285 285
 		echo '<div
286 286
 			id="stripe-sepa_debit-payment-data"
287
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
288
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
287
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
288
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
289 289
 
290
-		if ( $this->description ) {
291
-			if ( $this->testmode ) {
292
-				$this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' );
293
-				$this->description  = trim( $this->description );
290
+		if ($this->description) {
291
+			if ($this->testmode) {
292
+				$this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe');
293
+				$this->description  = trim($this->description);
294 294
 			}
295
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
295
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
296 296
 		}
297 297
 
298
-		if ( $display_tokenization ) {
298
+		if ($display_tokenization) {
299 299
 			$this->tokenization_script();
300 300
 			$this->saved_payment_methods();
301 301
 		}
302 302
 
303 303
 		$this->form();
304 304
 
305
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
305
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
306 306
 			$this->save_payment_method_checkbox();
307 307
 		}
308 308
 
@@ -320,87 +320,87 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @return array|void
322 322
 	 */
323
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
323
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
324 324
 		try {
325
-			$order = wc_get_order( $order_id );
325
+			$order = wc_get_order($order_id);
326 326
 
327 327
 			// This comes from the create account checkbox in the checkout page.
328
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
328
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
329 329
 
330
-			if ( $create_account ) {
330
+			if ($create_account) {
331 331
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
332
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
332
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
333 333
 				$new_stripe_customer->create_customer();
334 334
 			}
335 335
 
336
-			$prepared_source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), $force_save_source );
336
+			$prepared_source = $this->prepare_source($this->get_source_object(), get_current_user_id(), $force_save_source);
337 337
 
338 338
 			// Store source to order meta.
339
-			$this->save_source( $order, $prepared_source );
339
+			$this->save_source($order, $prepared_source);
340 340
 
341 341
 			// Result from Stripe API request.
342 342
 			$response = null;
343 343
 
344
-			if ( $order->get_total() > 0 ) {
344
+			if ($order->get_total() > 0) {
345 345
 				// This will throw exception if not valid.
346
-				$this->validate_minimum_order_amount( $order );
346
+				$this->validate_minimum_order_amount($order);
347 347
 
348
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
348
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
349 349
 
350 350
 				// Make the request.
351
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
351
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
352 352
 
353
-				if ( ! empty( $response->error ) ) {
353
+				if ( ! empty($response->error)) {
354 354
 					// If it is an API error such connection or server, let's retry.
355
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
356
-						if ( $retry ) {
357
-							sleep( 5 );
358
-							return $this->process_payment( $order_id, false, $force_save_source );
355
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
356
+						if ($retry) {
357
+							sleep(5);
358
+							return $this->process_payment($order_id, false, $force_save_source);
359 359
 						} else {
360 360
 							$localized_message = 'API connection error and retries exhausted.';
361
-							$order->add_order_note( $localized_message );
362
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
361
+							$order->add_order_note($localized_message);
362
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
363 363
 						}
364 364
 					}
365 365
 
366 366
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
367
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
368
-						if ( WC_Stripe_Helper::is_pre_30() ) {
369
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
370
-							delete_post_meta( $order_id, '_stripe_customer_id' );
367
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
368
+						if (WC_Stripe_Helper::is_pre_30()) {
369
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
370
+							delete_post_meta($order_id, '_stripe_customer_id');
371 371
 						} else {
372
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
373
-							$order->delete_meta_data( '_stripe_customer_id' );
372
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
373
+							$order->delete_meta_data('_stripe_customer_id');
374 374
 							$order->save();
375 375
 						}
376 376
 
377
-						return $this->process_payment( $order_id, false, $force_save_source );
378
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
377
+						return $this->process_payment($order_id, false, $force_save_source);
378
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
379 379
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
380
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
380
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
381 381
 						$wc_token->delete();
382
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
383
-						$order->add_order_note( $localized_message );
384
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
382
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
383
+						$order->add_order_note($localized_message);
384
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
385 385
 					}
386 386
 
387 387
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
388 388
 
389
-					if ( 'card_error' === $response->error->type ) {
390
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
389
+					if ('card_error' === $response->error->type) {
390
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
391 391
 					} else {
392
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
392
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
393 393
 					}
394 394
 
395
-					$order->add_order_note( $localized_message );
395
+					$order->add_order_note($localized_message);
396 396
 
397
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
397
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
398 398
 				}
399 399
 
400
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
400
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
401 401
 
402 402
 				// Process valid response.
403
-				$this->process_response( $response, $order );
403
+				$this->process_response($response, $order);
404 404
 			} else {
405 405
 				$order->payment_complete();
406 406
 			}
@@ -411,17 +411,17 @@  discard block
 block discarded – undo
411 411
 			// Return thank you page redirect.
412 412
 			return array(
413 413
 				'result'   => 'success',
414
-				'redirect' => $this->get_return_url( $order ),
414
+				'redirect' => $this->get_return_url($order),
415 415
 			);
416 416
 
417
-		} catch ( WC_Stripe_Exception $e ) {
418
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
419
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
417
+		} catch (WC_Stripe_Exception $e) {
418
+			wc_add_notice($e->getLocalizedMessage(), 'error');
419
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
420 420
 
421
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
421
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
422 422
 
423
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
424
-				$this->send_failed_order_email( $order_id );
423
+			if ($order->has_status(array('pending', 'failed'))) {
424
+				$this->send_failed_order_email($order_id);
425 425
 			}
426 426
 
427 427
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-sofort.php 1 patch
Spacing   +80 added lines, -80 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
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 		$this->id                   = 'stripe_sofort';
60
-		$this->method_title         = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
60
+		$this->method_title         = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
61 61
 		/* translators: link */
62
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
62
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
63 63
 		$this->supports             = array(
64 64
 			'products',
65 65
 			'refunds',
@@ -71,25 +71,25 @@  discard block
 block discarded – undo
71 71
 		// Load the settings.
72 72
 		$this->init_settings();
73 73
 
74
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
75
-		$this->title                = $this->get_option( 'title' );
76
-		$this->description          = $this->get_option( 'description' );
77
-		$this->enabled              = $this->get_option( 'enabled' );
78
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
79
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
80
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
81
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
82
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
83
-
84
-		if ( $this->testmode ) {
85
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
86
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
74
+		$main_settings              = get_option('woocommerce_stripe_settings');
75
+		$this->title                = $this->get_option('title');
76
+		$this->description          = $this->get_option('description');
77
+		$this->enabled              = $this->get_option('enabled');
78
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
79
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
80
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
81
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
82
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
83
+
84
+		if ($this->testmode) {
85
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
86
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
87 87
 		}
88 88
 
89
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
90
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
91
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
92
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
89
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
90
+		add_action('admin_notices', array($this, 'check_environment'));
91
+		add_action('admin_head', array($this, 'remove_admin_notice'));
92
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function check_environment() {
102
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
102
+		if ( ! current_user_can('manage_woocommerce')) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		$environment_warning = $this->get_environment_warning();
107 107
 
108
-		if ( $environment_warning ) {
109
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
108
+		if ($environment_warning) {
109
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
110 110
 		}
111 111
 
112
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
113
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
114
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
112
+		foreach ((array) $this->notices as $notice_key => $notice) {
113
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
114
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
115 115
 			echo '</p></div>';
116 116
 		}
117 117
 	}
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	 * @version 4.0.0
125 125
 	 */
126 126
 	public function get_environment_warning() {
127
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
128
-			$message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' );
127
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
128
+			$message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe');
129 129
 
130 130
 			return $message;
131 131
 		}
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @return array
142 142
 	 */
143 143
 	public function get_supported_currency() {
144
-		return apply_filters( 'wc_stripe_sofort_supported_currencies', array(
144
+		return apply_filters('wc_stripe_sofort_supported_currencies', array(
145 145
 			'EUR',
146
-		) );
146
+		));
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	public function is_available() {
157
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
157
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
158 158
 			return false;
159 159
 		}
160 160
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
 		$icons_str .= $icons['sofort'];
177 177
 
178
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
178
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
179 179
 	}
180 180
 
181 181
 	/**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
 	 * @access public
187 187
 	 */
188 188
 	public function payment_scripts() {
189
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
189
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
190 190
 			return;
191 191
 		}
192 192
 
193
-		wp_enqueue_style( 'stripe_paymentfonts' );
194
-		wp_enqueue_script( 'woocommerce_stripe' );
193
+		wp_enqueue_style('stripe_paymentfonts');
194
+		wp_enqueue_script('woocommerce_stripe');
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Initialize Gateway Settings Form Fields.
199 199
 	 */
200 200
 	public function init_form_fields() {
201
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' );
201
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php');
202 202
 	}
203 203
 
204 204
 	/**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
 		$total = WC()->cart->total;
210 210
 
211 211
 		// If paying from order, we need to get total from order not cart.
212
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
213
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
212
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
213
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
214 214
 			$total = $order->get_total();
215 215
 		}
216 216
 
217
-		if ( is_add_payment_method_page() ) {
218
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
219
-			$total        = '';
217
+		if (is_add_payment_method_page()) {
218
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
219
+			$total = '';
220 220
 		} else {
221 221
 			$pay_button_text = '';
222 222
 		}
223 223
 
224 224
 		echo '<div
225 225
 			id="stripe-sofort-payment-data"
226
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
227
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
226
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
227
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
228 228
 
229
-		if ( $this->description ) {
230
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
229
+		if ($this->description) {
230
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
231 231
 		}
232 232
 
233 233
 		echo '</div>';
@@ -241,28 +241,28 @@  discard block
 block discarded – undo
241 241
 	 * @param object $order
242 242
 	 * @return mixed
243 243
 	 */
244
-	public function create_source( $order ) {
244
+	public function create_source($order) {
245 245
 		$currency              = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
246 246
 		$bank_country          = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
247
-		$return_url            = $this->get_stripe_return_url( $order );
247
+		$return_url            = $this->get_stripe_return_url($order);
248 248
 		$post_data             = array();
249
-		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
250
-		$post_data['currency'] = strtolower( $currency );
249
+		$post_data['amount']   = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
250
+		$post_data['currency'] = strtolower($currency);
251 251
 		$post_data['type']     = 'sofort';
252
-		$post_data['owner']    = $this->get_owner_details( $order );
253
-		$post_data['redirect'] = array( 'return_url' => $return_url );
252
+		$post_data['owner']    = $this->get_owner_details($order);
253
+		$post_data['redirect'] = array('return_url' => $return_url);
254 254
 		$post_data['sofort']   = array(
255 255
 			'country'            => $bank_country,
256
-			'preferred_language' => substr( get_locale(), 0, 2 ),
256
+			'preferred_language' => substr(get_locale(), 0, 2),
257 257
 		);
258 258
 
259
-		if ( ! empty( $this->statement_descriptor ) ) {
260
-			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor );
259
+		if ( ! empty($this->statement_descriptor)) {
260
+			$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor);
261 261
 		}
262 262
 
263
-		WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' );
263
+		WC_Stripe_Logger::log('Info: Begin creating SOFORT source');
264 264
 
265
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' );
265
+		return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources');
266 266
 	}
267 267
 
268 268
 	/**
@@ -276,59 +276,59 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @return array|void
278 278
 	 */
279
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
279
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
280 280
 		try {
281
-			$order = wc_get_order( $order_id );
281
+			$order = wc_get_order($order_id);
282 282
 
283 283
 			// This will throw exception if not valid.
284
-			$this->validate_minimum_order_amount( $order );
284
+			$this->validate_minimum_order_amount($order);
285 285
 
286 286
 			// This comes from the create account checkbox in the checkout page.
287
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
287
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
288 288
 
289
-			if ( $create_account ) {
289
+			if ($create_account) {
290 290
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
291
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
291
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
292 292
 				$new_stripe_customer->create_customer();
293 293
 			}
294 294
 
295
-			$response = $this->create_source( $order );
295
+			$response = $this->create_source($order);
296 296
 
297
-			if ( ! empty( $response->error ) ) {
298
-				$order->add_order_note( $response->error->message );
297
+			if ( ! empty($response->error)) {
298
+				$order->add_order_note($response->error->message);
299 299
 
300 300
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
301 301
 
302
-				if ( 'invalid_sofort_country' === $response->error->code ) {
303
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
302
+				if ('invalid_sofort_country' === $response->error->code) {
303
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
304 304
 				} else {
305
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
305
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
306 306
 				}
307 307
 
308
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
308
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
309 309
 			}
310 310
 
311
-			if ( WC_Stripe_Helper::is_pre_30() ) {
312
-				update_post_meta( $order_id, '_stripe_source_id', $response->id );
311
+			if (WC_Stripe_Helper::is_pre_30()) {
312
+				update_post_meta($order_id, '_stripe_source_id', $response->id);
313 313
 			} else {
314
-				$order->update_meta_data( '_stripe_source_id', $response->id );
314
+				$order->update_meta_data('_stripe_source_id', $response->id);
315 315
 				$order->save();
316 316
 			}
317 317
 
318
-			WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' );
318
+			WC_Stripe_Logger::log('Info: Redirecting to SOFORT...');
319 319
 
320 320
 			return array(
321 321
 				'result'   => 'success',
322
-				'redirect' => esc_url_raw( $response->redirect->url ),
322
+				'redirect' => esc_url_raw($response->redirect->url),
323 323
 			);
324
-		} catch ( WC_Stripe_Exception $e ) {
325
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
326
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
324
+		} catch (WC_Stripe_Exception $e) {
325
+			wc_add_notice($e->getLocalizedMessage(), 'error');
326
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
327 327
 
328
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
328
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
329 329
 
330
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
331
-				$this->send_failed_order_email( $order_id );
330
+			if ($order->has_status(array('pending', 'failed'))) {
331
+				$this->send_failed_order_email($order_id);
332 332
 			}
333 333
 
334 334
 			return array(
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   3.1.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -56,35 +56,35 @@  discard block
 block discarded – undo
56 56
 	 * @version 4.0.0
57 57
 	 */
58 58
 	public function __construct() {
59
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
60
-		$this->testmode                = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
61
-		$this->publishable_key         = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
62
-		$this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout'];
63
-		$this->total_label             = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
64
-
65
-		if ( $this->testmode ) {
66
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
59
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
60
+		$this->testmode                = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
61
+		$this->publishable_key         = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
62
+		$this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout'];
63
+		$this->total_label             = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
64
+
65
+		if ($this->testmode) {
66
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
67 67
 		}
68 68
 
69 69
 		// If both site title and statement descriptor is not set. Fallback.
70
-		if ( empty( $this->total_label ) ) {
70
+		if (empty($this->total_label)) {
71 71
 			$this->total_label = $_SERVER['SERVER_NAME'];
72 72
 		}
73 73
 
74
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
74
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
75 75
 
76 76
 		// Checks if Stripe Gateway is enabled.
77
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
77
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
78 78
 			return;
79 79
 		}
80 80
 
81 81
 		// Checks if Payment Request is enabled.
82
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
82
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
83 83
 			return;
84 84
 		}
85 85
 
86 86
 		// Don't load for change payment method page.
87
-		if ( isset( $_GET['change_payment_method'] ) ) {
87
+		if (isset($_GET['change_payment_method'])) {
88 88
 			return;
89 89
 		}
90 90
 
@@ -98,41 +98,41 @@  discard block
 block discarded – undo
98 98
 	 * @version 4.0.0
99 99
 	 */
100 100
 	protected function init() {
101
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
102
-		add_action( 'wp', array( $this, 'set_session' ) );
101
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
102
+		add_action('wp', array($this, 'set_session'));
103 103
 
104 104
 		/*
105 105
 		 * In order to display the Payment Request button in the correct position,
106 106
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
107 107
 		 * CSS is used to position the button.
108 108
 		 */
109
-		if ( WC_Stripe_Helper::is_pre_30() ) {
110
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
111
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
109
+		if (WC_Stripe_Helper::is_pre_30()) {
110
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
111
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
112 112
 		} else {
113
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
114
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
113
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
114
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
115 115
 		}
116 116
 
117
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
118
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
117
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
118
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
119 119
 
120
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
121
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
120
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
121
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
122 122
 
123
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
124
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
125
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
126
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
127
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
128
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
129
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
130
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
123
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
124
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
125
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
126
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
127
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
128
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
129
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
130
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
131 131
 
132
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
133
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
132
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
133
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
134 134
 
135
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 );
135
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3);
136 136
 	}
137 137
 
138 138
 	/**
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @since 4.0.0
143 143
 	 */
144 144
 	public function set_session() {
145
-		if ( ! is_user_logged_in() ) {
145
+		if ( ! is_user_logged_in()) {
146 146
 			$wc_session = new WC_Session_Handler();
147 147
 
148
-			if ( ! $wc_session->has_session() ) {
149
-				$wc_session->set_customer_session_cookie( true );
148
+			if ( ! $wc_session->has_session()) {
149
+				$wc_session->set_customer_session_cookie(true);
150 150
 			}
151 151
 		}
152 152
 	}
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @return string
160 160
 	 */
161 161
 	public function get_button_type() {
162
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
162
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
163 163
 	}
164 164
 
165 165
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return string
171 171
 	 */
172 172
 	public function get_button_theme() {
173
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
173
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
174 174
 	}
175 175
 
176 176
 	/**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * @return string
182 182
 	 */
183 183
 	public function get_button_height() {
184
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
184
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
185 185
 	}
186 186
 
187 187
 	/**
@@ -191,40 +191,40 @@  discard block
 block discarded – undo
191 191
 	 * @version 4.0.0
192 192
 	 */
193 193
 	public function get_product_data() {
194
-		if ( ! is_product() ) {
194
+		if ( ! is_product()) {
195 195
 			return false;
196 196
 		}
197 197
 
198 198
 		global $post;
199 199
 
200
-		$product = wc_get_product( $post->ID );
200
+		$product = wc_get_product($post->ID);
201 201
 
202 202
 		$data  = array();
203 203
 		$items = array();
204 204
 
205 205
 		$items[] = array(
206 206
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
207
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
207
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
208 208
 		);
209 209
 
210
-		if ( wc_tax_enabled() ) {
210
+		if (wc_tax_enabled()) {
211 211
 			$items[] = array(
212
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
212
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
213 213
 				'amount'  => 0,
214 214
 				'pending' => true,
215 215
 			);
216 216
 		}
217 217
 
218
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
218
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
219 219
 			$items[] = array(
220
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
220
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
221 221
 				'amount'  => 0,
222 222
 				'pending' => true,
223 223
 			);
224 224
 
225
-			$data['shippingOptions']  = array(
225
+			$data['shippingOptions'] = array(
226 226
 				'id'     => 'pending',
227
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
227
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
228 228
 				'detail' => '',
229 229
 				'amount' => 0,
230 230
 			);
@@ -232,41 +232,41 @@  discard block
 block discarded – undo
232 232
 
233 233
 		$data['displayItems'] = $items;
234 234
 		$data['total'] = array(
235
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
236
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
235
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
236
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
237 237
 			'pending' => true,
238 238
 		);
239 239
 
240
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
241
-		$data['currency']        = strtolower( get_woocommerce_currency() );
242
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
240
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
241
+		$data['currency']        = strtolower(get_woocommerce_currency());
242
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
243 243
 
244
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
244
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
245 245
 	}
246 246
 
247 247
 	/**
248 248
 	 * Filters the gateway title to reflect Payment Request type
249 249
 	 *
250 250
 	 */
251
-	public function filter_gateway_title( $title, $id ) {
251
+	public function filter_gateway_title($title, $id) {
252 252
 		global $post;
253 253
 
254
-		if ( ! is_object( $post ) ) {
254
+		if ( ! is_object($post)) {
255 255
 			return $title;
256 256
 		}
257 257
 
258
-		if ( WC_Stripe_Helper::is_pre_30() ) {
259
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
258
+		if (WC_Stripe_Helper::is_pre_30()) {
259
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
260 260
 		} else {
261
-			$order        = wc_get_order( $post->ID );
262
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
261
+			$order        = wc_get_order($post->ID);
262
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
263 263
 		}
264 264
 
265
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
265
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
266 266
 			return $method_title;
267 267
 		}
268 268
 
269
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
269
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
270 270
 			return $method_title;
271 271
 		}
272 272
 
@@ -279,16 +279,16 @@  discard block
 block discarded – undo
279 279
 	 * @since 3.1.4
280 280
 	 * @version 4.0.0
281 281
 	 */
282
-	public function postal_code_validation( $valid, $postcode, $country ) {
282
+	public function postal_code_validation($valid, $postcode, $country) {
283 283
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
284 284
 
285
-		if ( ! isset( $gateways['stripe'] ) ) {
285
+		if ( ! isset($gateways['stripe'])) {
286 286
 			return $valid;
287 287
 		}
288 288
 
289
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
289
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
290 290
 
291
-		if ( 'apple_pay' !== $payment_request_type ) {
291
+		if ('apple_pay' !== $payment_request_type) {
292 292
 			return $valid;
293 293
 		}
294 294
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
299 299
 		 * Note that this only works with shipping providers that don't validate full postal codes.
300 300
 		 */
301
-		if ( 'GB' === $country || 'CA' === $country ) {
301
+		if ('GB' === $country || 'CA' === $country) {
302 302
 			return true;
303 303
 		}
304 304
 
@@ -314,27 +314,27 @@  discard block
 block discarded – undo
314 314
 	 * @param array $posted_data The posted data from checkout form.
315 315
 	 * @param object $order
316 316
 	 */
317
-	public function add_order_meta( $order_id, $posted_data, $order ) {
318
-		if ( empty( $_POST['payment_request_type'] ) ) {
317
+	public function add_order_meta($order_id, $posted_data, $order) {
318
+		if (empty($_POST['payment_request_type'])) {
319 319
 			return;
320 320
 		}
321 321
 
322
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
322
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
323 323
 
324
-		if ( 'apple_pay' === $payment_request_type ) {
325
-			if ( WC_Stripe_Helper::is_pre_30() ) {
326
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
324
+		if ('apple_pay' === $payment_request_type) {
325
+			if (WC_Stripe_Helper::is_pre_30()) {
326
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
327 327
 			} else {
328
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
328
+				$order->set_payment_method_title('Apple Pay (Stripe)');
329 329
 				$order->save();
330 330
 			}
331 331
 		}
332 332
 
333
-		if ( 'payment_request_api' === $payment_request_type ) {
334
-			if ( WC_Stripe_Helper::is_pre_30() ) {
335
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
333
+		if ('payment_request_api' === $payment_request_type) {
334
+			if (WC_Stripe_Helper::is_pre_30()) {
335
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
336 336
 			} else {
337
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
337
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
338 338
 				$order->save();
339 339
 			}
340 340
 		}
@@ -348,11 +348,11 @@  discard block
 block discarded – undo
348 348
 	 * @return array
349 349
 	 */
350 350
 	public function supported_product_types() {
351
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
351
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
352 352
 			'simple',
353 353
 			'variable',
354 354
 			'variation',
355
-		) );
355
+		));
356 356
 	}
357 357
 
358 358
 	/**
@@ -363,15 +363,15 @@  discard block
 block discarded – undo
363 363
 	 * @return bool
364 364
 	 */
365 365
 	public function allowed_items_in_cart() {
366
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
367
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
366
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
367
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
368 368
 
369
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
369
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
370 370
 				return false;
371 371
 			}
372 372
 
373 373
 			// Pre Orders compatbility where we don't support charge upon release.
374
-			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() ) ) {
374
+			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())) {
375 375
 				return false;
376 376
 			}
377 377
 		}
@@ -386,71 +386,71 @@  discard block
 block discarded – undo
386 386
 	 * @version 4.0.0
387 387
 	 */
388 388
 	public function scripts() {
389
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
389
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
390 390
 			return;
391 391
 		}
392 392
 
393
-		if ( is_product() ) {
393
+		if (is_product()) {
394 394
 			global $post;
395 395
 
396
-			$product = wc_get_product( $post->ID );
396
+			$product = wc_get_product($post->ID);
397 397
 
398
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
398
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
399 399
 				return;
400 400
 			}
401 401
 
402
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
402
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
403 403
 				return;
404 404
 			}
405 405
 		}
406 406
 
407
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
407
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
408 408
 
409
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
410
-		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 );
409
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
410
+		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);
411 411
 
412 412
 		wp_localize_script(
413 413
 			'wc_stripe_payment_request',
414 414
 			'wc_stripe_payment_request_params',
415 415
 			array(
416
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
416
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
417 417
 				'stripe'   => array(
418 418
 					'key'                => $this->publishable_key,
419
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
419
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
420 420
 				),
421 421
 				'nonce'    => array(
422
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
423
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
424
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
425
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
426
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
427
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
428
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
429
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
422
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
423
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
424
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
425
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
426
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
427
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
428
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
429
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
430 430
 				),
431 431
 				'i18n'     => array(
432
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
432
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
433 433
 					/* translators: Do not translate the [option] placeholder */
434
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
434
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
435 435
 				),
436 436
 				'checkout' => array(
437 437
 					'url'            => wc_get_checkout_url(),
438
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
439
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
438
+					'currency_code'  => strtolower(get_woocommerce_currency()),
439
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
440 440
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
441 441
 				),
442 442
 				'button' => array(
443 443
 					'type'   => $this->get_button_type(),
444 444
 					'theme'  => $this->get_button_theme(),
445 445
 					'height' => $this->get_button_height(),
446
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
446
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
447 447
 				),
448 448
 				'is_product_page' => is_product(),
449 449
 				'product'         => $this->get_product_data(),
450 450
 			)
451 451
 		);
452 452
 
453
-		wp_enqueue_script( 'wc_stripe_payment_request' );
453
+		wp_enqueue_script('wc_stripe_payment_request');
454 454
 	}
455 455
 
456 456
 	/**
@@ -462,39 +462,39 @@  discard block
 block discarded – undo
462 462
 	public function display_payment_request_button_html() {
463 463
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
464 464
 
465
-		if ( ! isset( $gateways['stripe'] ) ) {
465
+		if ( ! isset($gateways['stripe'])) {
466 466
 			return;
467 467
 		}
468 468
 
469
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
469
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
470 470
 			return;
471 471
 		}
472 472
 
473
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
473
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
474 474
 			return;
475 475
 		}
476 476
 
477
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
477
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
478 478
 			return;
479 479
 		}
480 480
 
481
-		if ( is_product() ) {
481
+		if (is_product()) {
482 482
 			global $post;
483 483
 
484
-			$product = wc_get_product( $post->ID );
484
+			$product = wc_get_product($post->ID);
485 485
 
486
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
486
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
487 487
 				return;
488 488
 			}
489 489
 
490 490
 			// Pre Orders charge upon release not supported.
491
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
492
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
491
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
492
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
493 493
 				return;
494 494
 			}
495 495
 		} else {
496
-			if ( ! $this->allowed_items_in_cart() ) {
497
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
496
+			if ( ! $this->allowed_items_in_cart()) {
497
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
498 498
 				return;
499 499
 			}
500 500
 		}
@@ -516,44 +516,44 @@  discard block
 block discarded – undo
516 516
 	public function display_payment_request_button_separator_html() {
517 517
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
518 518
 
519
-		if ( ! isset( $gateways['stripe'] ) ) {
519
+		if ( ! isset($gateways['stripe'])) {
520 520
 			return;
521 521
 		}
522 522
 
523
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
523
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
524 524
 			return;
525 525
 		}
526 526
 
527
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
527
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
528 528
 			return;
529 529
 		}
530 530
 
531
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
531
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
532 532
 			return;
533 533
 		}
534 534
 
535
-		if ( is_product() ) {
535
+		if (is_product()) {
536 536
 			global $post;
537 537
 
538
-			$product = wc_get_product( $post->ID );
538
+			$product = wc_get_product($post->ID);
539 539
 
540
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
540
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
541 541
 				return;
542 542
 			}
543 543
 
544 544
 			// Pre Orders charge upon release not supported.
545
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
546
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
545
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
546
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
547 547
 				return;
548 548
 			}
549 549
 		} else {
550
-			if ( ! $this->allowed_items_in_cart() ) {
551
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
550
+			if ( ! $this->allowed_items_in_cart()) {
551
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
552 552
 				return;
553 553
 			}
554 554
 		}
555 555
 		?>
556
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p>
556
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p>
557 557
 		<?php
558 558
 	}
559 559
 
@@ -564,11 +564,11 @@  discard block
 block discarded – undo
564 564
 	 * @version 4.0.0
565 565
 	 */
566 566
 	public function ajax_log_errors() {
567
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
567
+		check_ajax_referer('wc-stripe-log-errors', 'security');
568 568
 
569
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
569
+		$errors = wc_clean(stripslashes($_POST['errors']));
570 570
 
571
-		WC_Stripe_Logger::log( $errors );
571
+		WC_Stripe_Logger::log($errors);
572 572
 
573 573
 		exit;
574 574
 	}
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 	 * @version 4.0.0
581 581
 	 */
582 582
 	public function ajax_clear_cart() {
583
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
583
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
584 584
 
585 585
 		WC()->cart->empty_cart();
586 586
 		exit;
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
 	 * Get cart details.
591 591
 	 */
592 592
 	public function ajax_get_cart_details() {
593
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
593
+		check_ajax_referer('wc-stripe-payment-request', 'security');
594 594
 
595
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
596
-			define( 'WOOCOMMERCE_CART', true );
595
+		if ( ! defined('WOOCOMMERCE_CART')) {
596
+			define('WOOCOMMERCE_CART', true);
597 597
 		}
598 598
 
599 599
 		WC()->cart->calculate_totals();
@@ -604,14 +604,14 @@  discard block
 block discarded – undo
604 604
 		$data = array(
605 605
 			'shipping_required' => WC()->cart->needs_shipping(),
606 606
 			'order_data'        => array(
607
-				'currency'        => strtolower( $currency ),
608
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
607
+				'currency'        => strtolower($currency),
608
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
609 609
 			),
610 610
 		);
611 611
 
612 612
 		$data['order_data'] += $this->build_display_items();
613 613
 
614
-		wp_send_json( $data );
614
+		wp_send_json($data);
615 615
 	}
616 616
 
617 617
 	/**
@@ -622,47 +622,47 @@  discard block
 block discarded – undo
622 622
 	 * @see WC_Shipping::get_packages().
623 623
 	 */
624 624
 	public function ajax_get_shipping_options() {
625
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
625
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
626 626
 
627 627
 		try {
628 628
 			// Set the shipping package.
629
-			$posted = filter_input_array( INPUT_POST, array(
629
+			$posted = filter_input_array(INPUT_POST, array(
630 630
 				'country'   => FILTER_SANITIZE_STRING,
631 631
 				'state'     => FILTER_SANITIZE_STRING,
632 632
 				'postcode'  => FILTER_SANITIZE_STRING,
633 633
 				'city'      => FILTER_SANITIZE_STRING,
634 634
 				'address'   => FILTER_SANITIZE_STRING,
635 635
 				'address_2' => FILTER_SANITIZE_STRING,
636
-			) );
636
+			));
637 637
 
638
-			$this->calculate_shipping( $posted );
638
+			$this->calculate_shipping($posted);
639 639
 
640 640
 			// Set the shipping options.
641 641
 			$data     = array();
642 642
 			$packages = WC()->shipping->get_packages();
643 643
 
644
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
645
-				foreach ( $packages as $package_key => $package ) {
646
-					if ( empty( $package['rates'] ) ) {
647
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
644
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
645
+				foreach ($packages as $package_key => $package) {
646
+					if (empty($package['rates'])) {
647
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
648 648
 					}
649 649
 
650
-					foreach ( $package['rates'] as $key => $rate ) {
650
+					foreach ($package['rates'] as $key => $rate) {
651 651
 						$data['shipping_options'][] = array(
652 652
 							'id'       => $rate->id,
653 653
 							'label'    => $rate->label,
654 654
 							'detail'   => '',
655
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
655
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
656 656
 						);
657 657
 					}
658 658
 				}
659 659
 			} else {
660
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
660
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
661 661
 			}
662 662
 
663
-			if ( isset( $data[0] ) ) {
663
+			if (isset($data[0])) {
664 664
 				// Auto select the first shipping method.
665
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
665
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
666 666
 			}
667 667
 
668 668
 			WC()->cart->calculate_totals();
@@ -670,12 +670,12 @@  discard block
 block discarded – undo
670 670
 			$data += $this->build_display_items();
671 671
 			$data['result'] = 'success';
672 672
 
673
-			wp_send_json( $data );
674
-		} catch ( Exception $e ) {
673
+			wp_send_json($data);
674
+		} catch (Exception $e) {
675 675
 			$data += $this->build_display_items();
676 676
 			$data['result'] = 'invalid_shipping_address';
677 677
 
678
-			wp_send_json( $data );
678
+			wp_send_json($data);
679 679
 		}
680 680
 	}
681 681
 
@@ -683,22 +683,22 @@  discard block
 block discarded – undo
683 683
 	 * Update shipping method.
684 684
 	 */
685 685
 	public function ajax_update_shipping_method() {
686
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
686
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
687 687
 
688
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
689
-			define( 'WOOCOMMERCE_CART', true );
688
+		if ( ! defined('WOOCOMMERCE_CART')) {
689
+			define('WOOCOMMERCE_CART', true);
690 690
 		}
691 691
 
692
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
693
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
692
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
693
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
694 694
 
695
-		if ( is_array( $shipping_method ) ) {
696
-			foreach ( $shipping_method as $i => $value ) {
697
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
695
+		if (is_array($shipping_method)) {
696
+			foreach ($shipping_method as $i => $value) {
697
+				$chosen_shipping_methods[$i] = wc_clean($value);
698 698
 			}
699 699
 		}
700 700
 
701
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
701
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
702 702
 
703 703
 		WC()->cart->calculate_totals();
704 704
 
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 		$data += $this->build_display_items();
707 707
 		$data['result'] = 'success';
708 708
 
709
-		wp_send_json( $data );
709
+		wp_send_json($data);
710 710
 	}
711 711
 
712 712
 	/**
@@ -717,31 +717,31 @@  discard block
 block discarded – undo
717 717
 	 * @return array $data
718 718
 	 */
719 719
 	public function ajax_get_selected_product_data() {
720
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
720
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
721 721
 
722
-		$product_id = absint( $_POST['product_id'] );
723
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
722
+		$product_id = absint($_POST['product_id']);
723
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
724 724
 
725
-		$product = wc_get_product( $product_id );
725
+		$product = wc_get_product($product_id);
726 726
 
727
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
728
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
727
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
728
+			$attributes = array_map('wc_clean', $_POST['attributes']);
729 729
 
730
-			if ( WC_Stripe_Helper::is_pre_30() ) {
731
-				$variation_id = $product->get_matching_variation( $attributes );
730
+			if (WC_Stripe_Helper::is_pre_30()) {
731
+				$variation_id = $product->get_matching_variation($attributes);
732 732
 			} else {
733
-				$data_store = WC_Data_Store::load( 'product' );
734
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
733
+				$data_store = WC_Data_Store::load('product');
734
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
735 735
 			}
736 736
 
737
-			if ( ! empty( $variation_id ) ) {
738
-				$product = wc_get_product( $variation_id );
737
+			if ( ! empty($variation_id)) {
738
+				$product = wc_get_product($variation_id);
739 739
 			}
740
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
741
-			$product = wc_get_product( $product_id );
740
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
741
+			$product = wc_get_product($product_id);
742 742
 		}
743 743
 
744
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
744
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
745 745
 
746 746
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
747 747
 
@@ -749,28 +749,28 @@  discard block
 block discarded – undo
749 749
 		$items = array();
750 750
 
751 751
 		$items[] = array(
752
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
753
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
752
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
753
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
754 754
 		);
755 755
 
756
-		if ( wc_tax_enabled() ) {
756
+		if (wc_tax_enabled()) {
757 757
 			$items[] = array(
758
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
758
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
759 759
 				'amount'  => 0,
760 760
 				'pending' => true,
761 761
 			);
762 762
 		}
763 763
 
764
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
764
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
765 765
 			$items[] = array(
766
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
766
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
767 767
 				'amount'  => 0,
768 768
 				'pending' => true,
769 769
 			);
770 770
 
771
-			$data['shippingOptions']  = array(
771
+			$data['shippingOptions'] = array(
772 772
 				'id'     => 'pending',
773
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
773
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
774 774
 				'detail' => '',
775 775
 				'amount' => 0,
776 776
 			);
@@ -779,15 +779,15 @@  discard block
 block discarded – undo
779 779
 		$data['displayItems'] = $items;
780 780
 		$data['total'] = array(
781 781
 			'label'   => $this->total_label,
782
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
782
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
783 783
 			'pending' => true,
784 784
 		);
785 785
 
786
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
787
-		$data['currency']        = strtolower( get_woocommerce_currency() );
788
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
786
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
787
+		$data['currency']        = strtolower(get_woocommerce_currency());
788
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
789 789
 
790
-		wp_send_json( $data );
790
+		wp_send_json($data);
791 791
 	}
792 792
 
793 793
 	/**
@@ -798,37 +798,37 @@  discard block
 block discarded – undo
798 798
 	 * @return array $data
799 799
 	 */
800 800
 	public function ajax_add_to_cart() {
801
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
801
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
802 802
 
803
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
804
-			define( 'WOOCOMMERCE_CART', true );
803
+		if ( ! defined('WOOCOMMERCE_CART')) {
804
+			define('WOOCOMMERCE_CART', true);
805 805
 		}
806 806
 
807 807
 		WC()->shipping->reset_shipping();
808 808
 
809
-		$product_id = absint( $_POST['product_id'] );
810
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
809
+		$product_id = absint($_POST['product_id']);
810
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
811 811
 
812
-		$product = wc_get_product( $product_id );
812
+		$product = wc_get_product($product_id);
813 813
 
814 814
 		// First empty the cart to prevent wrong calculation.
815 815
 		WC()->cart->empty_cart();
816 816
 
817
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
818
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
817
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
818
+			$attributes = array_map('wc_clean', $_POST['attributes']);
819 819
 
820
-			if ( WC_Stripe_Helper::is_pre_30() ) {
821
-				$variation_id = $product->get_matching_variation( $attributes );
820
+			if (WC_Stripe_Helper::is_pre_30()) {
821
+				$variation_id = $product->get_matching_variation($attributes);
822 822
 			} else {
823
-				$data_store = WC_Data_Store::load( 'product' );
824
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
823
+				$data_store = WC_Data_Store::load('product');
824
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
825 825
 			}
826 826
 
827
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
827
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
828 828
 		}
829 829
 
830
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
831
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
830
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
831
+			WC()->cart->add_to_cart($product->get_id(), $qty);
832 832
 		}
833 833
 
834 834
 		WC()->cart->calculate_totals();
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 		$data += $this->build_display_items();
838 838
 		$data['result'] = 'success';
839 839
 
840
-		wp_send_json( $data );
840
+		wp_send_json($data);
841 841
 	}
842 842
 
843 843
 	/**
@@ -850,31 +850,31 @@  discard block
 block discarded – undo
850 850
 	 * @version 4.0.0
851 851
 	 */
852 852
 	public function normalize_state() {
853
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
854
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
855
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
856
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
853
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
854
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
855
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
856
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
857 857
 
858
-		if ( $billing_state && $billing_country ) {
859
-			$valid_states = WC()->countries->get_states( $billing_country );
858
+		if ($billing_state && $billing_country) {
859
+			$valid_states = WC()->countries->get_states($billing_country);
860 860
 
861 861
 			// Valid states found for country.
862
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
863
-				foreach ( $valid_states as $state_abbr => $state ) {
864
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
862
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
863
+				foreach ($valid_states as $state_abbr => $state) {
864
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
865 865
 						$_POST['billing_state'] = $state_abbr;
866 866
 					}
867 867
 				}
868 868
 			}
869 869
 		}
870 870
 
871
-		if ( $shipping_state && $shipping_country ) {
872
-			$valid_states = WC()->countries->get_states( $shipping_country );
871
+		if ($shipping_state && $shipping_country) {
872
+			$valid_states = WC()->countries->get_states($shipping_country);
873 873
 
874 874
 			// Valid states found for country.
875
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
876
-				foreach ( $valid_states as $state_abbr => $state ) {
877
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
875
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
876
+				foreach ($valid_states as $state_abbr => $state) {
877
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
878 878
 						$_POST['shipping_state'] = $state_abbr;
879 879
 					}
880 880
 				}
@@ -889,19 +889,19 @@  discard block
 block discarded – undo
889 889
 	 * @version 4.0.0
890 890
 	 */
891 891
 	public function ajax_create_order() {
892
-		if ( WC()->cart->is_empty() ) {
893
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
892
+		if (WC()->cart->is_empty()) {
893
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
894 894
 		}
895 895
 
896
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
897
-			define( 'WOOCOMMERCE_CHECKOUT', true );
896
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
897
+			define('WOOCOMMERCE_CHECKOUT', true);
898 898
 		}
899 899
 
900 900
 		$this->normalize_state();
901 901
 
902 902
 		WC()->checkout()->process_checkout();
903 903
 
904
-		die( 0 );
904
+		die(0);
905 905
 	}
906 906
 
907 907
 	/**
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
 	 * @version 4.0.0
912 912
 	 * @param array $address
913 913
 	 */
914
-	protected function calculate_shipping( $address = array() ) {
914
+	protected function calculate_shipping($address = array()) {
915 915
 		global $states;
916 916
 
917 917
 		$country   = $address['country'];
@@ -928,28 +928,28 @@  discard block
 block discarded – undo
928 928
 		 * In some versions of Chrome, state can be a full name. So we need
929 929
 		 * to convert that to abbreviation as WC is expecting that.
930 930
 		 */
931
-		if ( 2 < strlen( $state ) ) {
932
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
931
+		if (2 < strlen($state)) {
932
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
933 933
 		}
934 934
 
935 935
 		WC()->shipping->reset_shipping();
936 936
 
937
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
938
-			$postcode = wc_format_postcode( $postcode, $country );
937
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
938
+			$postcode = wc_format_postcode($postcode, $country);
939 939
 		}
940 940
 
941
-		if ( $country ) {
942
-			WC()->customer->set_location( $country, $state, $postcode, $city );
943
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
941
+		if ($country) {
942
+			WC()->customer->set_location($country, $state, $postcode, $city);
943
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
944 944
 		} else {
945 945
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
946 946
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
947 947
 		}
948 948
 
949
-		if ( WC_Stripe_Helper::is_pre_30() ) {
950
-			WC()->customer->calculated_shipping( true );
949
+		if (WC_Stripe_Helper::is_pre_30()) {
950
+			WC()->customer->calculated_shipping(true);
951 951
 		} else {
952
-			WC()->customer->set_calculated_shipping( true );
952
+			WC()->customer->set_calculated_shipping(true);
953 953
 			WC()->customer->save();
954 954
 		}
955 955
 
@@ -966,17 +966,17 @@  discard block
 block discarded – undo
966 966
 		$packages[0]['destination']['address']   = $address_1;
967 967
 		$packages[0]['destination']['address_2'] = $address_2;
968 968
 
969
-		foreach ( WC()->cart->get_cart() as $item ) {
970
-			if ( $item['data']->needs_shipping() ) {
971
-				if ( isset( $item['line_total'] ) ) {
969
+		foreach (WC()->cart->get_cart() as $item) {
970
+			if ($item['data']->needs_shipping()) {
971
+				if (isset($item['line_total'])) {
972 972
 					$packages[0]['contents_cost'] += $item['line_total'];
973 973
 				}
974 974
 			}
975 975
 		}
976 976
 
977
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
977
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
978 978
 
979
-		WC()->shipping->calculate_shipping( $packages );
979
+		WC()->shipping->calculate_shipping($packages);
980 980
 	}
981 981
 
982 982
 	/**
@@ -985,19 +985,19 @@  discard block
 block discarded – undo
985 985
 	 * @since 3.1.0
986 986
 	 * @version 4.0.0
987 987
 	 */
988
-	protected function build_shipping_methods( $shipping_methods ) {
989
-		if ( empty( $shipping_methods ) ) {
988
+	protected function build_shipping_methods($shipping_methods) {
989
+		if (empty($shipping_methods)) {
990 990
 			return array();
991 991
 		}
992 992
 
993 993
 		$shipping = array();
994 994
 
995
-		foreach ( $shipping_methods as $method ) {
995
+		foreach ($shipping_methods as $method) {
996 996
 			$shipping[] = array(
997 997
 				'id'         => $method['id'],
998 998
 				'label'      => $method['label'],
999 999
 				'detail'     => '',
1000
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1000
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1001 1001
 			);
1002 1002
 		}
1003 1003
 
@@ -1011,69 +1011,69 @@  discard block
 block discarded – undo
1011 1011
 	 * @version 4.0.0
1012 1012
 	 */
1013 1013
 	protected function build_display_items() {
1014
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1015
-			define( 'WOOCOMMERCE_CART', true );
1014
+		if ( ! defined('WOOCOMMERCE_CART')) {
1015
+			define('WOOCOMMERCE_CART', true);
1016 1016
 		}
1017 1017
 
1018 1018
 		$items    = array();
1019 1019
 		$subtotal = 0;
1020 1020
 
1021 1021
 		// Default show only subtotal instead of itemization.
1022
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1023
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1022
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1023
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1024 1024
 				$amount         = $cart_item['line_subtotal'];
1025
-				$subtotal       += $cart_item['line_subtotal'];
1025
+				$subtotal += $cart_item['line_subtotal'];
1026 1026
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1027 1027
 
1028 1028
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1029 1029
 
1030 1030
 				$item = array(
1031 1031
 					'label'  => $product_name . $quantity_label,
1032
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1032
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1033 1033
 				);
1034 1034
 
1035 1035
 				$items[] = $item;
1036 1036
 			}
1037 1037
 		}
1038 1038
 
1039
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1040
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1041
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1042
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1043
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1039
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1040
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1041
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1042
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1043
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1044 1044
 
1045
-		if ( wc_tax_enabled() ) {
1045
+		if (wc_tax_enabled()) {
1046 1046
 			$items[] = array(
1047
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1048
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1047
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1048
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1049 1049
 			);
1050 1050
 		}
1051 1051
 
1052
-		if ( WC()->cart->needs_shipping() ) {
1052
+		if (WC()->cart->needs_shipping()) {
1053 1053
 			$items[] = array(
1054
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1055
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1054
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1055
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1056 1056
 			);
1057 1057
 		}
1058 1058
 
1059
-		if ( WC()->cart->has_discount() ) {
1059
+		if (WC()->cart->has_discount()) {
1060 1060
 			$items[] = array(
1061
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1062
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1061
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1062
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1063 1063
 			);
1064 1064
 		}
1065 1065
 
1066
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1066
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1067 1067
 			$cart_fees = WC()->cart->fees;
1068 1068
 		} else {
1069 1069
 			$cart_fees = WC()->cart->get_fees();
1070 1070
 		}
1071 1071
 
1072 1072
 		// Include fees and taxes as display items.
1073
-		foreach ( $cart_fees as $key => $fee ) {
1073
+		foreach ($cart_fees as $key => $fee) {
1074 1074
 			$items[] = array(
1075 1075
 				'label'  => $fee->name,
1076
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1076
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1077 1077
 			);
1078 1078
 		}
1079 1079
 
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
 			'displayItems' => $items,
1082 1082
 			'total'      => array(
1083 1083
 				'label'   => $this->total_label,
1084
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1084
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1085 1085
 				'pending' => false,
1086 1086
 			),
1087 1087
 		);
Please login to merge, or discard this patch.
includes/admin/stripe-settings.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,184 +1,184 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 $webhook_url = WC_Stripe_Helper::get_webhook_url();
7 7
 
8
-return apply_filters( 'wc_stripe_settings',
8
+return apply_filters('wc_stripe_settings',
9 9
 	array(
10 10
 		'enabled' => array(
11
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
12
-			'label'       => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ),
11
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
12
+			'label'       => __('Enable Stripe', 'woocommerce-gateway-stripe'),
13 13
 			'type'        => 'checkbox',
14 14
 			'description' => '',
15 15
 			'default'     => 'no',
16 16
 		),
17 17
 		'title' => array(
18
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
18
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
19 19
 			'type'        => 'text',
20
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
21
-			'default'     => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
20
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
21
+			'default'     => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'),
22 22
 			'desc_tip'    => true,
23 23
 		),
24 24
 		'description' => array(
25
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
25
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
26 26
 			'type'        => 'text',
27
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
28
-			'default'     => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ),
27
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
28
+			'default'     => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'),
29 29
 			'desc_tip'    => true,
30 30
 		),
31 31
 		'webhook' => array(
32
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
32
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
33 33
 			'type'        => 'title',
34 34
 			/* translators: webhook URL */
35
-			'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ),
35
+			'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url),
36 36
 		),
37 37
 		'testmode' => array(
38
-			'title'       => __( 'Test mode', 'woocommerce-gateway-stripe' ),
39
-			'label'       => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
38
+			'title'       => __('Test mode', 'woocommerce-gateway-stripe'),
39
+			'label'       => __('Enable Test Mode', 'woocommerce-gateway-stripe'),
40 40
 			'type'        => 'checkbox',
41
-			'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
41
+			'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'),
42 42
 			'default'     => 'yes',
43 43
 			'desc_tip'    => true,
44 44
 		),
45 45
 		'test_publishable_key' => array(
46
-			'title'       => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
46
+			'title'       => __('Test Publishable Key', 'woocommerce-gateway-stripe'),
47 47
 			'type'        => 'password',
48
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
48
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
49 49
 			'default'     => '',
50 50
 			'desc_tip'    => true,
51 51
 		),
52 52
 		'test_secret_key' => array(
53
-			'title'       => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
53
+			'title'       => __('Test Secret Key', 'woocommerce-gateway-stripe'),
54 54
 			'type'        => 'password',
55
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
55
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
56 56
 			'default'     => '',
57 57
 			'desc_tip'    => true,
58 58
 		),
59 59
 		'publishable_key' => array(
60
-			'title'       => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
60
+			'title'       => __('Live Publishable Key', 'woocommerce-gateway-stripe'),
61 61
 			'type'        => 'password',
62
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
62
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
63 63
 			'default'     => '',
64 64
 			'desc_tip'    => true,
65 65
 		),
66 66
 		'secret_key' => array(
67
-			'title'       => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
67
+			'title'       => __('Live Secret Key', 'woocommerce-gateway-stripe'),
68 68
 			'type'        => 'password',
69
-			'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ),
69
+			'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'),
70 70
 			'default'     => '',
71 71
 			'desc_tip'    => true,
72 72
 		),
73 73
 		'inline_cc_form' => array(
74
-			'title'       => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ),
74
+			'title'       => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'),
75 75
 			'type'        => 'checkbox',
76
-			'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ),
76
+			'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'),
77 77
 			'default'     => 'no',
78 78
 			'desc_tip'    => true,
79 79
 		),
80 80
 		'statement_descriptor' => array(
81
-			'title'       => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ),
81
+			'title'       => __('Statement Descriptor', 'woocommerce-gateway-stripe'),
82 82
 			'type'        => 'text',
83
-			'description' => __( 'This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.' ),
83
+			'description' => __('This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.'),
84 84
 			'default'     => '',
85 85
 			'desc_tip'    => true,
86 86
 		),
87 87
 		'capture' => array(
88
-			'title'       => __( 'Capture', 'woocommerce-gateway-stripe' ),
89
-			'label'       => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),
88
+			'title'       => __('Capture', 'woocommerce-gateway-stripe'),
89
+			'label'       => __('Capture charge immediately', 'woocommerce-gateway-stripe'),
90 90
 			'type'        => 'checkbox',
91
-			'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ),
91
+			'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'),
92 92
 			'default'     => 'yes',
93 93
 			'desc_tip'    => true,
94 94
 		),
95 95
 		'three_d_secure' => array(
96
-			'title'       => __( '3D Secure', 'woocommerce-gateway-stripe' ),
97
-			'label'       => __( 'Require 3D Secure when applicable', 'woocommerce-gateway-stripe' ),
96
+			'title'       => __('3D Secure', 'woocommerce-gateway-stripe'),
97
+			'label'       => __('Require 3D Secure when applicable', 'woocommerce-gateway-stripe'),
98 98
 			'type'        => 'checkbox',
99
-			'description' => __( 'Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe' ),
99
+			'description' => __('Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe'),
100 100
 			'default'     => 'no',
101 101
 			'desc_tip'    => true,
102 102
 		),
103 103
 		'stripe_checkout' => array(
104
-			'title'       => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ),
105
-			'label'       => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ),
104
+			'title'       => __('Stripe Checkout', 'woocommerce-gateway-stripe'),
105
+			'label'       => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'),
106 106
 			'type'        => 'checkbox',
107
-			'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ),
107
+			'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'),
108 108
 			'default'     => 'no',
109 109
 			'desc_tip'    => true,
110 110
 		),
111 111
 		'stripe_bitcoin' => array(
112
-			'title'       => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ),
113
-			'label'       => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ),
112
+			'title'       => __('Bitcoin Currency', 'woocommerce-gateway-stripe'),
113
+			'label'       => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'),
114 114
 			'type'        => 'checkbox',
115
-			'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ),
115
+			'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'),
116 116
 			'default'     => 'no',
117 117
 			'desc_tip'    => true,
118 118
 		),
119 119
 		'stripe_checkout_image' => array(
120
-			'title'       => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ),
121
-			'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ),
120
+			'title'       => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'),
121
+			'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'),
122 122
 			'type'        => 'text',
123 123
 			'default'     => '',
124 124
 			'desc_tip'    => true,
125 125
 		),
126 126
 		'payment_request' => array(
127
-			'title'       => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
127
+			'title'       => __('Payment Request Buttons', 'woocommerce-gateway-stripe'),
128 128
 			/* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */
129
-			'label'       => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ),
129
+			'label'       => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'),
130 130
 			'type'        => 'checkbox',
131
-			'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ),
131
+			'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'),
132 132
 			'default'     => 'yes',
133 133
 			'desc_tip'    => true,
134 134
 		),
135 135
 		'payment_request_button_type' => array(
136
-			'title'       => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
137
-			'label'       => __( 'Button Type', 'woocommerce-gateway-stripe' ),
136
+			'title'       => __('Payment Request Button Type', 'woocommerce-gateway-stripe'),
137
+			'label'       => __('Button Type', 'woocommerce-gateway-stripe'),
138 138
 			'type'        => 'select',
139
-			'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ),
139
+			'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'),
140 140
 			'default'     => 'buy',
141 141
 			'desc_tip'    => true,
142 142
 			'options'     => array(
143
-				'default' => __( 'Default', 'woocommerce-gateway-stripe' ),
144
-				'buy'     => __( 'Buy', 'woocommerce-gateway-stripe' ),
145
-				'donate'  => __( 'Donate', 'woocommerce-gateway-stripe' ),
143
+				'default' => __('Default', 'woocommerce-gateway-stripe'),
144
+				'buy'     => __('Buy', 'woocommerce-gateway-stripe'),
145
+				'donate'  => __('Donate', 'woocommerce-gateway-stripe'),
146 146
 			),
147 147
 		),
148 148
 		'payment_request_button_theme' => array(
149
-			'title'       => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
150
-			'label'       => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
149
+			'title'       => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'),
150
+			'label'       => __('Button Theme', 'woocommerce-gateway-stripe'),
151 151
 			'type'        => 'select',
152
-			'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ),
152
+			'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'),
153 153
 			'default'     => 'dark',
154 154
 			'desc_tip'    => true,
155 155
 			'options'     => array(
156
-				'dark'          => __( 'Dark', 'woocommerce-gateway-stripe' ),
157
-				'light'         => __( 'Light', 'woocommerce-gateway-stripe' ),
158
-				'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ),
156
+				'dark'          => __('Dark', 'woocommerce-gateway-stripe'),
157
+				'light'         => __('Light', 'woocommerce-gateway-stripe'),
158
+				'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'),
159 159
 			),
160 160
 		),
161 161
 		'payment_request_button_height' => array(
162
-			'title'       => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ),
163
-			'label'       => __( 'Button Height', 'woocommerce-gateway-stripe' ),
162
+			'title'       => __('Payment Request Button Height', 'woocommerce-gateway-stripe'),
163
+			'label'       => __('Button Height', 'woocommerce-gateway-stripe'),
164 164
 			'type'        => 'text',
165
-			'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ),
165
+			'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'),
166 166
 			'default'     => '44',
167 167
 			'desc_tip'    => true,
168 168
 		),
169 169
 		'saved_cards' => array(
170
-			'title'       => __( 'Saved Cards', 'woocommerce-gateway-stripe' ),
171
-			'label'       => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ),
170
+			'title'       => __('Saved Cards', 'woocommerce-gateway-stripe'),
171
+			'label'       => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'),
172 172
 			'type'        => 'checkbox',
173
-			'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ),
173
+			'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'),
174 174
 			'default'     => 'no',
175 175
 			'desc_tip'    => true,
176 176
 		),
177 177
 		'logging' => array(
178
-			'title'       => __( 'Logging', 'woocommerce-gateway-stripe' ),
179
-			'label'       => __( 'Log debug messages', 'woocommerce-gateway-stripe' ),
178
+			'title'       => __('Logging', 'woocommerce-gateway-stripe'),
179
+			'label'       => __('Log debug messages', 'woocommerce-gateway-stripe'),
180 180
 			'type'        => 'checkbox',
181
-			'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ),
181
+			'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'),
182 182
 			'default'     => 'no',
183 183
 			'desc_tip'    => true,
184 184
 		),
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +193 added lines, -194 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
 
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 	 * Check if this gateway is enabled
19 19
 	 */
20 20
 	public function is_available() {
21
-		if ( 'yes' === $this->enabled ) {
22
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
21
+		if ('yes' === $this->enabled) {
22
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
23 23
 				return false;
24 24
 			}
25
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
25
+			if ( ! $this->secret_key || ! $this->publishable_key) {
26 26
 				return false;
27 27
 			}
28 28
 			return true;
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	 * @since 4.0.0
38 38
 	 * @version 4.0.0
39 39
 	 */
40
-	public function add_admin_notice( $slug, $class, $message ) {
41
-		$this->notices[ $slug ] = array(
40
+	public function add_admin_notice($slug, $class, $message) {
41
+		$this->notices[$slug] = array(
42 42
 			'class'   => $class,
43 43
 			'message' => $message,
44 44
 		);
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * @version 4.0.0
52 52
 	 */
53 53
 	public function remove_admin_notice() {
54
-		if ( did_action( 'woocommerce_update_options' ) ) {
55
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
54
+		if (did_action('woocommerce_update_options')) {
55
+			remove_action('admin_notices', array($this, 'check_environment'));
56 56
 		}
57 57
 	}
58 58
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return array
65 65
 	 */
66 66
 	public function payment_icons() {
67
-		return apply_filters( 'wc_stripe_payment_icons', array(
67
+		return apply_filters('wc_stripe_payment_icons', array(
68 68
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
69 69
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
70 70
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
82 82
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
83 83
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
84
-		) );
84
+		));
85 85
 	}
86 86
 
87 87
 	/**
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 	 * @version 4.0.0
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function validate_minimum_order_amount( $order ) {
96
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
95
+	public function validate_minimum_order_amount($order) {
96
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
97 97
 			/* translators: 1) dollar amount */
98
-			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 ) ) );
98
+			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)));
99 99
 		}
100 100
 	}
101 101
 
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 	 * @since 4.0.0
106 106
 	 * @version 4.0.0
107 107
 	 */
108
-	public function get_transaction_url( $order ) {
109
-		if ( $this->testmode ) {
108
+	public function get_transaction_url($order) {
109
+		if ($this->testmode) {
110 110
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
111 111
 		} else {
112 112
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
113 113
 		}
114 114
 
115
-		return parent::get_transaction_url( $order );
115
+		return parent::get_transaction_url($order);
116 116
 	}
117 117
 
118 118
 	/**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	 * @since 4.0.0
122 122
 	 * @version 4.0.0
123 123
 	 */
124
-	public function get_stripe_customer_id( $order ) {
125
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
124
+	public function get_stripe_customer_id($order) {
125
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
126 126
 
127
-		if ( empty( $customer ) ) {
127
+		if (empty($customer)) {
128 128
 			// Try to get it via the order.
129
-			if ( WC_Stripe_Helper::is_pre_30() ) {
130
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
129
+			if (WC_Stripe_Helper::is_pre_30()) {
130
+				return get_post_meta($order->id, '_stripe_customer_id', true);
131 131
 			} else {
132
-				return $order->get_meta( '_stripe_customer_id', true );
132
+				return $order->get_meta('_stripe_customer_id', true);
133 133
 			}
134 134
 		} else {
135 135
 			return $customer;
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
 	 * @param object $order
147 147
 	 * @param int $id Stripe session id.
148 148
 	 */
149
-	public function get_stripe_return_url( $order = null, $id = null ) {
150
-		if ( is_object( $order ) ) {
151
-			if ( empty( $id ) ) {
149
+	public function get_stripe_return_url($order = null, $id = null) {
150
+		if (is_object($order)) {
151
+			if (empty($id)) {
152 152
 				$id = uniqid();
153 153
 			}
154 154
 
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 				'order_id'       => $order_id,
160 160
 			);
161 161
 
162
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
162
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
163 163
 		}
164 164
 
165
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
165
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,27 +174,26 @@  discard block
 block discarded – undo
174 174
 	 * @param  object $source
175 175
 	 * @return array()
176 176
 	 */
177
-	public function generate_payment_request( $order, $source ) {
178
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
179
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
180
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
177
+	public function generate_payment_request($order, $source) {
178
+		$settings                          = get_option('woocommerce_stripe_settings', array());
179
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
180
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
181 181
 		$post_data                         = array();
182
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
183
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
182
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
183
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
184 184
 		/* translators: 1) blog name 2) order number */
185
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
185
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
186 186
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
187 187
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
188 188
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
189 189
 
190
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
190
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
191 191
 			$post_data['receipt_email'] = $billing_email;
192 192
 		}
193 193
 
194
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
195
-			case 'stripe':
196
-				if ( ! empty( $statement_descriptor ) ) {
197
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
194
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
195
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
196
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
198 197
 				}
199 198
 
200 199
 				$post_data['capture'] = $capture ? 'true' : 'false';
@@ -204,18 +203,18 @@  discard block
 block discarded – undo
204 203
 		$post_data['expand[]'] = 'balance_transaction';
205 204
 
206 205
 		$metadata = array(
207
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
208
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
206
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
207
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
209 208
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
210 209
 		);
211 210
 
212
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
211
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
213 212
 
214
-		if ( $source->customer ) {
213
+		if ($source->customer) {
215 214
 			$post_data['customer'] = $source->customer;
216 215
 		}
217 216
 
218
-		if ( $source->source ) {
217
+		if ($source->source) {
219 218
 			$post_data['source'] = $source->source;
220 219
 		}
221 220
 
@@ -227,77 +226,77 @@  discard block
 block discarded – undo
227 226
 		 * @param WC_Order $order
228 227
 		 * @param object $source
229 228
 		 */
230
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
229
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
231 230
 	}
232 231
 
233 232
 	/**
234 233
 	 * Store extra meta data for an order from a Stripe Response.
235 234
 	 */
236
-	public function process_response( $response, $order ) {
237
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
235
+	public function process_response($response, $order) {
236
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
238 237
 
239 238
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
240 239
 
241
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
240
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
242 241
 
243 242
 		// Store charge data
244
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
243
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
245 244
 
246 245
 		// Store other data such as fees
247
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
246
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
248 247
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
249 248
 			// values are in the local currency of the Stripe account, not from WC.
250
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
251
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
252
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
253
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
249
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
250
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
251
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
252
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
254 253
 		}
255 254
 
256
-		if ( 'yes' === $captured ) {
255
+		if ('yes' === $captured) {
257 256
 			/**
258 257
 			 * Charge can be captured but in a pending state. Payment methods
259 258
 			 * that are asynchronous may take couple days to clear. Webhook will
260 259
 			 * take care of the status changes.
261 260
 			 */
262
-			if ( 'pending' === $response->status ) {
263
-				if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) {
264
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
261
+			if ('pending' === $response->status) {
262
+				if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) {
263
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
265 264
 				}
266 265
 
267
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id );
266
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id);
268 267
 				/* translators: transaction id */
269
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
268
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
270 269
 			}
271 270
 
272
-			if ( 'succeeded' === $response->status ) {
273
-				$order->payment_complete( $response->id );
271
+			if ('succeeded' === $response->status) {
272
+				$order->payment_complete($response->id);
274 273
 
275 274
 				/* translators: transaction id */
276
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
277
-				$order->add_order_note( $message );
275
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
276
+				$order->add_order_note($message);
278 277
 			}
279 278
 
280
-			if ( 'failed' === $response->status ) {
281
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
282
-				$order->add_order_note( $localized_message );
283
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
279
+			if ('failed' === $response->status) {
280
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
281
+				$order->add_order_note($localized_message);
282
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
284 283
 			}
285 284
 		} else {
286
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id );
285
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id);
287 286
 
288
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
289
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
287
+			if ($order->has_status(array('pending', 'failed'))) {
288
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
290 289
 			}
291 290
 
292 291
 			/* translators: transaction id */
293
-			$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 ) );
292
+			$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));
294 293
 		}
295 294
 
296
-		if ( is_callable( array( $order, 'save' ) ) ) {
295
+		if (is_callable(array($order, 'save'))) {
297 296
 			$order->save();
298 297
 		}
299 298
 
300
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
299
+		do_action('wc_gateway_stripe_process_response', $response, $order);
301 300
 
302 301
 		return $response;
303 302
 	}
@@ -310,10 +309,10 @@  discard block
 block discarded – undo
310 309
 	 * @param int $order_id
311 310
 	 * @return null
312 311
 	 */
313
-	public function send_failed_order_email( $order_id ) {
312
+	public function send_failed_order_email($order_id) {
314 313
 		$emails = WC()->mailer()->get_emails();
315
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
316
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
314
+		if ( ! empty($emails) && ! empty($order_id)) {
315
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
317 316
 		}
318 317
 	}
319 318
 
@@ -325,7 +324,7 @@  discard block
 block discarded – undo
325 324
 	 * @param object $order
326 325
 	 * @return object $details
327 326
 	 */
328
-	public function get_owner_details( $order ) {
327
+	public function get_owner_details($order) {
329 328
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
330 329
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
331 330
 
@@ -336,8 +335,8 @@  discard block
 block discarded – undo
336 335
 
337 336
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
338 337
 
339
-		if ( ! empty( $phone ) ) {
340
-			$details['phone']              = $phone;
338
+		if ( ! empty($phone)) {
339
+			$details['phone'] = $phone;
341 340
 		}
342 341
 
343 342
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -347,7 +346,7 @@  discard block
 block discarded – undo
347 346
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
348 347
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
349 348
 
350
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
349
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
351 350
 	}
352 351
 
353 352
 	/**
@@ -356,16 +355,16 @@  discard block
 block discarded – undo
356 355
 	 * @since 4.0.3
357 356
 	 */
358 357
 	public function get_source_object() {
359
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
358
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
360 359
 		
361
-		if ( empty( $source ) ) {
360
+		if (empty($source)) {
362 361
 			return '';
363 362
 		}
364 363
 
365
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
364
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
366 365
 
367
-		if ( ! empty( $source_object->error ) ) {
368
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
366
+		if ( ! empty($source_object->error)) {
367
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
369 368
 		}
370 369
 
371 370
 		return $source_object;
@@ -378,11 +377,11 @@  discard block
 block discarded – undo
378 377
 	 * @param object $source_object
379 378
 	 * @return bool
380 379
 	 */
381
-	public function is_3ds_required( $source_object ) {
380
+	public function is_3ds_required($source_object) {
382 381
 		return (
383
-			$source_object && ! empty( $source_object->card ) ) &&
384
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
385
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
382
+			$source_object && ! empty($source_object->card) ) &&
383
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
384
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
386 385
 		);
387 386
 	}
388 387
 
@@ -393,8 +392,8 @@  discard block
 block discarded – undo
393 392
 	 * @param object $source_object
394 393
 	 * @return bool
395 394
 	 */
396
-	public function is_3ds_card( $source_object ) {
397
-		return ( $source_object && 'three_d_secure' === $source_object->type );
395
+	public function is_3ds_card($source_object) {
396
+		return ($source_object && 'three_d_secure' === $source_object->type);
398 397
 	}
399 398
 
400 399
 	/**
@@ -407,22 +406,22 @@  discard block
 block discarded – undo
407 406
 	 * @param string $return_url
408 407
 	 * @return mixed
409 408
 	 */
410
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
409
+	public function create_3ds_source($order, $source_object, $return_url = '') {
411 410
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
412 411
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
413
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
412
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
414 413
 
415 414
 		$post_data                   = array();
416
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
417
-		$post_data['currency']       = strtolower( $currency );
415
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
416
+		$post_data['currency']       = strtolower($currency);
418 417
 		$post_data['type']           = 'three_d_secure';
419
-		$post_data['owner']          = $this->get_owner_details( $order );
420
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
421
-		$post_data['redirect']       = array( 'return_url' => $return_url );
418
+		$post_data['owner']          = $this->get_owner_details($order);
419
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
420
+		$post_data['redirect']       = array('return_url' => $return_url);
422 421
 
423
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
422
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
424 423
 
425
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
424
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
426 425
 	}
427 426
 
428 427
 	/**
@@ -439,54 +438,54 @@  discard block
 block discarded – undo
439 438
 	 * @throws Exception When card was not added or for and invalid card.
440 439
 	 * @return object
441 440
 	 */
442
-	public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) {
443
-		$customer           = new WC_Stripe_Customer( $user_id );
441
+	public function prepare_source($source_object = '', $user_id, $force_save_source = false) {
442
+		$customer           = new WC_Stripe_Customer($user_id);
444 443
 		$set_customer       = true;
445
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
444
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
446 445
 		$source_id          = '';
447 446
 		$wc_token_id        = false;
448
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
447
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
449 448
 
450 449
 		// New CC info was entered and we have a new source to process.
451
-		if ( ! empty( $source_object ) ) {
450
+		if ( ! empty($source_object)) {
452 451
 			$source_id = $source_object->id;
453 452
 
454 453
 			// This checks to see if customer opted to save the payment method to file.
455
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
454
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
456 455
 
457 456
 			/**
458 457
 			 * This is true if the user wants to store the card to their account.
459 458
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
460 459
 			 * actually reusable. Either that or force_save_source is true.
461 460
 			 */
462
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
463
-				$response = $customer->add_source( $source_object->id );
461
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
462
+				$response = $customer->add_source($source_object->id);
464 463
 
465
-				if ( ! empty( $response->error ) ) {
466
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
464
+				if ( ! empty($response->error)) {
465
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
467 466
 				}
468 467
 			}
469
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
468
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
470 469
 			// Use an existing token, and then process the payment
471
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
472
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
470
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
471
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
473 472
 
474
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
475
-				WC()->session->set( 'refresh_totals', true );
476
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
473
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
474
+				WC()->session->set('refresh_totals', true);
475
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
477 476
 			}
478 477
 
479 478
 			$source_id = $wc_token->get_token();
480
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
481
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
482
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
479
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
480
+			$stripe_token     = wc_clean($_POST['stripe_token']);
481
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
483 482
 
484 483
 			// This is true if the user wants to store the card to their account.
485
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
486
-				$response = $customer->add_source( $stripe_token );
484
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
485
+				$response = $customer->add_source($stripe_token);
487 486
 
488
-				if ( ! empty( $response->error ) ) {
489
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
487
+				if ( ! empty($response->error)) {
488
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
490 489
 				}
491 490
 			} else {
492 491
 				$set_customer = false;
@@ -494,7 +493,7 @@  discard block
 block discarded – undo
494 493
 			}
495 494
 		}
496 495
 
497
-		if ( ! $set_customer ) {
496
+		if ( ! $set_customer) {
498 497
 			$customer_id = false;
499 498
 		} else {
500 499
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -520,37 +519,37 @@  discard block
 block discarded – undo
520 519
 	 * @param object $order
521 520
 	 * @return object
522 521
 	 */
523
-	public function prepare_order_source( $order = null ) {
522
+	public function prepare_order_source($order = null) {
524 523
 		$stripe_customer = new WC_Stripe_Customer();
525 524
 		$stripe_source   = false;
526 525
 		$token_id        = false;
527 526
 
528
-		if ( $order ) {
527
+		if ($order) {
529 528
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
530 529
 
531
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
530
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
532 531
 
533
-			if ( $stripe_customer_id ) {
534
-				$stripe_customer->set_id( $stripe_customer_id );
532
+			if ($stripe_customer_id) {
533
+				$stripe_customer->set_id($stripe_customer_id);
535 534
 			}
536 535
 
537
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
536
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
538 537
 
539 538
 			// Since 4.0.0, we changed card to source so we need to account for that.
540
-			if ( empty( $source_id ) ) {
541
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
539
+			if (empty($source_id)) {
540
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
542 541
 
543 542
 				// Take this opportunity to update the key name.
544
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id );
543
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
545 544
 
546
-				if ( is_callable( array( $order, 'save' ) ) ) {
545
+				if (is_callable(array($order, 'save'))) {
547 546
 					$order->save();
548 547
 				}
549 548
 			}
550 549
 
551
-			if ( $source_id ) {
550
+			if ($source_id) {
552 551
 				$stripe_source = $source_id;
553
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
552
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
554 553
 				/*
555 554
 				 * We can attempt to charge the customer's default source
556 555
 				 * by sending empty source id.
@@ -574,27 +573,27 @@  discard block
 block discarded – undo
574 573
 	 * @param WC_Order $order For to which the source applies.
575 574
 	 * @param stdClass $source Source information.
576 575
 	 */
577
-	public function save_source( $order, $source ) {
576
+	public function save_source($order, $source) {
578 577
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
579 578
 
580 579
 		// Store source in the order.
581
-		if ( $source->customer ) {
582
-			if ( WC_Stripe_Helper::is_pre_30() ) {
583
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
580
+		if ($source->customer) {
581
+			if (WC_Stripe_Helper::is_pre_30()) {
582
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
584 583
 			} else {
585
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
584
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
586 585
 			}
587 586
 		}
588 587
 
589
-		if ( $source->source ) {
590
-			if ( WC_Stripe_Helper::is_pre_30() ) {
591
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
588
+		if ($source->source) {
589
+			if (WC_Stripe_Helper::is_pre_30()) {
590
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
592 591
 			} else {
593
-				$order->update_meta_data( '_stripe_source_id', $source->source );
592
+				$order->update_meta_data('_stripe_source_id', $source->source);
594 593
 			}
595 594
 		}
596 595
 
597
-		if ( is_callable( array( $order, 'save' ) ) ) {
596
+		if (is_callable(array($order, 'save'))) {
598 597
 			$order->save();
599 598
 		}
600 599
 	}
@@ -608,27 +607,27 @@  discard block
 block discarded – undo
608 607
 	 * @param object $order The order object
609 608
 	 * @param int $balance_transaction_id
610 609
 	 */
611
-	public function update_fees( $order, $balance_transaction_id ) {
610
+	public function update_fees($order, $balance_transaction_id) {
612 611
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
613 612
 
614
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
613
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
615 614
 
616
-		if ( empty( $balance_transaction->error ) ) {
617
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
615
+		if (empty($balance_transaction->error)) {
616
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
618 617
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
619 618
 				// values are in the local currency of the Stripe account, not from WC.
620
-				$fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
621
-				$net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
619
+				$fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
620
+				$net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
622 621
 
623
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
624
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
622
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
623
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
625 624
 
626
-				if ( is_callable( array( $order, 'save' ) ) ) {
625
+				if (is_callable(array($order, 'save'))) {
627 626
 					$order->save();
628 627
 				}
629 628
 			}
630 629
 		} else {
631
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
630
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
632 631
 		}
633 632
 	}
634 633
 
@@ -641,57 +640,57 @@  discard block
 block discarded – undo
641 640
 	 * @param  float $amount
642 641
 	 * @return bool
643 642
 	 */
644
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
645
-		$order = wc_get_order( $order_id );
643
+	public function process_refund($order_id, $amount = null, $reason = '') {
644
+		$order = wc_get_order($order_id);
646 645
 
647
-		if ( ! $order || ! $order->get_transaction_id() ) {
646
+		if ( ! $order || ! $order->get_transaction_id()) {
648 647
 			return false;
649 648
 		}
650 649
 
651 650
 		$body = array();
652 651
 
653
-		if ( WC_Stripe_Helper::is_pre_30() ) {
654
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
652
+		if (WC_Stripe_Helper::is_pre_30()) {
653
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
655 654
 		} else {
656 655
 			$order_currency = $order->get_currency();
657 656
 		}
658 657
 
659
-		if ( ! is_null( $amount ) ) {
660
-			$body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
658
+		if ( ! is_null($amount)) {
659
+			$body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
661 660
 		}
662 661
 
663
-		if ( $reason ) {
662
+		if ($reason) {
664 663
 			$body['metadata'] = array(
665 664
 				'reason' => $reason,
666 665
 			);
667 666
 		}
668 667
 
669
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
668
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
670 669
 
671
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
670
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
672 671
 
673
-		if ( ! empty( $response->error ) ) {
674
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
672
+		if ( ! empty($response->error)) {
673
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
675 674
 
676 675
 			return $response;
677 676
 
678
-		} elseif ( ! empty( $response->id ) ) {
679
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id );
677
+		} elseif ( ! empty($response->id)) {
678
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id);
680 679
 
681
-			$amount = wc_price( $response->amount / 100 );
680
+			$amount = wc_price($response->amount / 100);
682 681
 
683
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
684
-				$amount = wc_price( $response->amount );
682
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
683
+				$amount = wc_price($response->amount);
685 684
 			}
686 685
 
687
-			if ( isset( $response->balance_transaction ) ) {
688
-				$this->update_fees( $order, $response->balance_transaction );
686
+			if (isset($response->balance_transaction)) {
687
+				$this->update_fees($order, $response->balance_transaction);
689 688
 			}
690 689
 
691 690
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
692
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason );
693
-			$order->add_order_note( $refund_message );
694
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
691
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason);
692
+			$order->add_order_note($refund_message);
693
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
695 694
 
696 695
 			return true;
697 696
 		}
@@ -706,44 +705,44 @@  discard block
 block discarded – undo
706 705
 	 */
707 706
 	public function add_payment_method() {
708 707
 		$error     = false;
709
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
708
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
710 709
 		$source_id = '';
711 710
 
712
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
711
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
713 712
 			$error = true;
714 713
 		}
715 714
 
716
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
715
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
717 716
 
718
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
717
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
719 718
 
720
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
719
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
721 720
 
722
-		if ( isset( $source_object ) ) {
723
-			if ( ! empty( $source_object->error ) ) {
721
+		if (isset($source_object)) {
722
+			if ( ! empty($source_object->error)) {
724 723
 				$error = true;
725 724
 			}
726 725
 
727 726
 			$source_id = $source_object->id;
728
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
729
-			$source_id = wc_clean( $_POST['stripe_token'] );
727
+		} elseif (isset($_POST['stripe_token'])) {
728
+			$source_id = wc_clean($_POST['stripe_token']);
730 729
 		}
731 730
 
732
-		$response = $stripe_customer->add_source( $source_id );
731
+		$response = $stripe_customer->add_source($source_id);
733 732
 
734
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
733
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
735 734
 			$error = true;
736 735
 		}
737 736
 
738
-		if ( $error ) {
739
-			wc_add_notice( $error_msg, 'error' );
740
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
737
+		if ($error) {
738
+			wc_add_notice($error_msg, 'error');
739
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
741 740
 			return;
742 741
 		}
743 742
 
744 743
 		return array(
745 744
 			'result'   => 'success',
746
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
745
+			'redirect' => wc_get_endpoint_url('payment-methods'),
747 746
 		);
748 747
 	}
749 748
 }
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-compat.php 2 patches
Doc Comments   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -221,7 +221,6 @@  discard block
 block discarded – undo
221 221
 	 * process_subscription_payment function.
222 222
 	 * @param mixed $order
223 223
 	 * @param int $amount (default: 0)
224
-	 * @param string $stripe_token (default: '')
225 224
 	 * @param  bool initial_payment
226 225
 	 */
227 226
 	public function process_subscription_payment( $order = '', $amount = 0 ) {
@@ -263,9 +262,7 @@  discard block
 block discarded – undo
263 262
 	 * This is used when renewal failed.
264 263
 	 *
265 264
 	 * @todo refactor to avoid DRY.
266
-	 * @param mixed $order
267 265
 	 * @param int $amount (default: 0)
268
-	 * @param string $stripe_token (default: '')
269 266
 	 * @param  bool initial_payment
270 267
 	 */
271 268
 	public function retry_subscription_payment( $amount = 0, $renewal_order ) {
@@ -317,7 +314,7 @@  discard block
 block discarded – undo
317 314
 
318 315
 	/**
319 316
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
320
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
317
+	 * @param integer $renewal_order
321 318
 	 */
322 319
 	public function delete_renewal_meta( $renewal_order ) {
323 320
 		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
@@ -559,6 +556,8 @@  discard block
 block discarded – undo
559 556
 	/**
560 557
 	 * Process the pre-order
561 558
 	 * @param int $order_id
559
+	 * @param boolean $retry
560
+	 * @param boolean $force_save_source
562 561
 	 * @return array
563 562
 	 */
564 563
 	public function process_pre_order( $order_id, $retry, $force_save_source ) {
Please login to merge, or discard this patch.
Spacing   +197 added lines, -197 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,24 +15,24 @@  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 );
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 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 * @return bool
68 68
 	 */
69 69
 	public function is_subs_change_payment() {
70
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
70
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
71 71
 	}
72 72
 
73 73
 	/**
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 	 * @param  int  $order_id
76 76
 	 * @return boolean
77 77
 	 */
78
-	public function is_pre_order( $order_id ) {
79
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
78
+	public function is_pre_order($order_id) {
79
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
80 80
 	}
81 81
 
82 82
 	/**
@@ -85,27 +85,27 @@  discard block
 block discarded – undo
85 85
 	 * @since 4.0.4
86 86
 	 * @param int $order_id
87 87
 	 */
88
-	public function change_subs_payment_method( $order_id ) {
88
+	public function change_subs_payment_method($order_id) {
89 89
 		try {
90
-			$subscription    = wc_get_order( $order_id );
90
+			$subscription    = wc_get_order($order_id);
91 91
 			$source_object   = $this->get_source_object();
92
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true );
92
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), true);
93 93
 
94 94
 			// Check if we don't allow prepaid credit cards.
95
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
96
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
97
-					$localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' );
98
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
95
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
96
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
97
+					$localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe');
98
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
99 99
 				}
100 100
 			}
101 101
 
102
-			if ( empty( $prepared_source->source ) ) {
103
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
104
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
102
+			if (empty($prepared_source->source)) {
103
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
104
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
105 105
 			}
106 106
 
107 107
 			// Store source to order meta.
108
-			$this->save_source( $subscription, $prepared_source );
108
+			$this->save_source($subscription, $prepared_source);
109 109
 
110 110
 			/*
111 111
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -114,41 +114,41 @@  discard block
 block discarded – undo
114 114
 			 * Note that if we need to save source, the original source must be first
115 115
 			 * attached to a customer in Stripe before it can be charged.
116 116
 			 */
117
-			if ( $this->is_3ds_required( $source_object ) ) {
117
+			if ($this->is_3ds_required($source_object)) {
118 118
 				$order    = $subscription->get_parent();
119
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
119
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
120 120
 
121
-				if ( ! empty( $response->error ) ) {
121
+				if ( ! empty($response->error)) {
122 122
 					$localized_message = $response->error->message;
123 123
 
124
-					$order->add_order_note( $localized_message );
124
+					$order->add_order_note($localized_message);
125 125
 
126
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
126
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
127 127
 				}
128 128
 
129 129
 				// Update order meta with 3DS source.
130
-				if ( WC_Stripe_Helper::is_pre_30() ) {
131
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
130
+				if (WC_Stripe_Helper::is_pre_30()) {
131
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
132 132
 				} else {
133
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
133
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
134 134
 					$subscription->save();
135 135
 				}
136 136
 
137
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
137
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
138 138
 
139 139
 				return array(
140 140
 					'result'   => 'success',
141
-					'redirect' => esc_url_raw( $response->redirect->url ),
141
+					'redirect' => esc_url_raw($response->redirect->url),
142 142
 				);
143 143
 			}
144 144
 
145 145
 			return array(
146 146
 				'result'   => 'success',
147
-				'redirect' => $this->get_return_url( $subscription ),
147
+				'redirect' => $this->get_return_url($subscription),
148 148
 			);
149
-		} catch ( WC_Stripe_Exception $e ) {
150
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
151
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
149
+		} catch (WC_Stripe_Exception $e) {
150
+			wc_add_notice($e->getLocalizedMessage(), 'error');
151
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
152 152
 		}
153 153
 	}
154 154
 
@@ -157,18 +157,18 @@  discard block
 block discarded – undo
157 157
 	 * @param  int $order_id
158 158
 	 * @return array
159 159
 	 */
160
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
161
-		if ( $this->has_subscription( $order_id ) ) {
162
-			if ( $this->is_subs_change_payment() ) {
163
-				return $this->change_subs_payment_method( $order_id );
160
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
161
+		if ($this->has_subscription($order_id)) {
162
+			if ($this->is_subs_change_payment()) {
163
+				return $this->change_subs_payment_method($order_id);
164 164
 			}
165 165
 
166 166
 			// Regular payment with force customer enabled
167
-			return parent::process_payment( $order_id, true, true );
168
-		} elseif ( $this->is_pre_order( $order_id ) ) {
169
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
167
+			return parent::process_payment($order_id, true, true);
168
+		} elseif ($this->is_pre_order($order_id)) {
169
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
170 170
 		} else {
171
-			return parent::process_payment( $order_id, $retry, $force_save_source );
171
+			return parent::process_payment($order_id, $retry, $force_save_source);
172 172
 		}
173 173
 	}
174 174
 
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 	 * @param array $metadata
180 180
 	 * @param object $order
181 181
 	 */
182
-	public function add_subscription_meta_data( $metadata, $order ) {
183
-		if ( ! $this->has_subscription( $order->get_id() ) ) {
182
+	public function add_subscription_meta_data($metadata, $order) {
183
+		if ( ! $this->has_subscription($order->get_id())) {
184 184
 			return $metadata;
185 185
 		}
186 186
 
187 187
 		return $metadata += array(
188 188
 			'payment_type'   => 'recurring',
189
-			'site_url'       => esc_url( get_site_url() ),
189
+			'site_url'       => esc_url(get_site_url()),
190 190
 		);
191 191
 	}
192 192
 
@@ -196,24 +196,24 @@  discard block
 block discarded – undo
196 196
 	 * @since 3.1.0
197 197
 	 * @version 4.0.0
198 198
 	 */
199
-	public function save_source( $order, $source ) {
200
-		parent::save_source( $order, $source );
199
+	public function save_source($order, $source) {
200
+		parent::save_source($order, $source);
201 201
 
202 202
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
203 203
 
204 204
 		// Also store it on the subscriptions being purchased or paid for in the order
205
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
206
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
207
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
208
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
205
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
206
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
207
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
208
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
209 209
 		} else {
210 210
 			$subscriptions = array();
211 211
 		}
212 212
 
213
-		foreach ( $subscriptions as $subscription ) {
213
+		foreach ($subscriptions as $subscription) {
214 214
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
215
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
216
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
215
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
216
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
217 217
 		}
218 218
 	}
219 219
 
@@ -224,36 +224,36 @@  discard block
 block discarded – undo
224 224
 	 * @param string $stripe_token (default: '')
225 225
 	 * @param  bool initial_payment
226 226
 	 */
227
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
228
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
227
+	public function process_subscription_payment($order = '', $amount = 0) {
228
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
229 229
 			/* translators: minimum amount */
230
-			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 ) ) );
230
+			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)));
231 231
 		}
232 232
 
233 233
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
234 234
 
235 235
 		// Get source from order
236
-		$prepared_source = $this->prepare_order_source( $order );
236
+		$prepared_source = $this->prepare_order_source($order);
237 237
 
238 238
 		// Or fail :(
239
-		if ( ! $prepared_source->customer ) {
240
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
239
+		if ( ! $prepared_source->customer) {
240
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
241 241
 		}
242 242
 
243
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
243
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
244 244
 
245 245
 		// Make the request
246
-		$request            = $this->generate_payment_request( $order, $prepared_source );
246
+		$request            = $this->generate_payment_request($order, $prepared_source);
247 247
 		$request['capture'] = 'true';
248
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
249
-		$response           = WC_Stripe_API::request( $request );
248
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
249
+		$response           = WC_Stripe_API::request($request);
250 250
 
251 251
 		// Process valid response
252
-		if ( ! empty( $response->error ) ) {
252
+		if ( ! empty($response->error)) {
253 253
 			return $response; // Default catch all errors.
254 254
 		}
255 255
 
256
-		$this->process_response( $response, $order );
256
+		$this->process_response($response, $order);
257 257
 
258 258
 		return $response;
259 259
 	}
@@ -268,60 +268,60 @@  discard block
 block discarded – undo
268 268
 	 * @param string $stripe_token (default: '')
269 269
 	 * @param  bool initial_payment
270 270
 	 */
271
-	public function retry_subscription_payment( $amount = 0, $renewal_order ) {
272
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
271
+	public function retry_subscription_payment($amount = 0, $renewal_order) {
272
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
273 273
 			/* translators: minimum amount */
274
-			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 ) ) );
274
+			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)));
275 275
 		}
276 276
 
277 277
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
278 278
 
279 279
 		// Get source from order
280
-		$prepared_source = $this->prepare_order_source( $renewal_order );
280
+		$prepared_source = $this->prepare_order_source($renewal_order);
281 281
 
282 282
 		// Or fail :(
283
-		if ( ! $prepared_source->customer ) {
284
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
283
+		if ( ! $prepared_source->customer) {
284
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
285 285
 		}
286 286
 
287 287
 		// Passing empty source with charge customer default.
288 288
 		$prepared_source->source = '';
289 289
 
290
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
290
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
291 291
 
292 292
 		// Make the request
293
-		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
293
+		$request             = $this->generate_payment_request($renewal_order, $prepared_source);
294 294
 		$request['capture']  = 'true';
295
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
296
-		$response            = WC_Stripe_API::request( $request );
295
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
296
+		$response            = WC_Stripe_API::request($request);
297 297
 
298
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
298
+		if ( ! empty($response->error) || is_wp_error($response)) {
299 299
 			/* translators: error message */
300
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
300
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
301 301
 		}
302 302
 
303
-		$this->process_response( $response, $renewal_order );
303
+		$this->process_response($response, $renewal_order);
304 304
 	}
305 305
 
306 306
 	/**
307 307
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
308 308
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
309 309
 	 */
310
-	public function delete_resubscribe_meta( $resubscribe_order ) {
311
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
312
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
310
+	public function delete_resubscribe_meta($resubscribe_order) {
311
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
312
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
313 313
 		// For BW compat will remove in future
314
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
315
-		$this->delete_renewal_meta( $resubscribe_order );
314
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
315
+		$this->delete_renewal_meta($resubscribe_order);
316 316
 	}
317 317
 
318 318
 	/**
319 319
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
320 320
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
321 321
 	 */
322
-	public function delete_renewal_meta( $renewal_order ) {
323
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
324
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
322
+	public function delete_renewal_meta($renewal_order) {
323
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
324
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
325 325
 		return $renewal_order;
326 326
 	}
327 327
 
@@ -331,21 +331,21 @@  discard block
 block discarded – undo
331 331
 	 * @param $amount_to_charge float The amount to charge.
332 332
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
333 333
 	 */
334
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
335
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
334
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
335
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
336 336
 
337
-		if ( is_wp_error( $response ) ) {
337
+		if (is_wp_error($response)) {
338 338
 			/* translators: error message */
339
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
339
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
340 340
 		}
341 341
 
342
-		if ( ! empty( $response->error ) ) {
342
+		if ( ! empty($response->error)) {
343 343
 			// This is a very generic error to listen for but worth a retry before total fail.
344
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
345
-				$this->retry_subscription_payment( $amount_to_charge, $renewal_order );
344
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
345
+				$this->retry_subscription_payment($amount_to_charge, $renewal_order);
346 346
 			} else {
347 347
 				/* translators: error message */
348
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
348
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
349 349
 			}
350 350
 		}
351 351
 	}
@@ -354,20 +354,20 @@  discard block
 block discarded – undo
354 354
 	 * Remove order meta
355 355
 	 * @param  object $order
356 356
 	 */
357
-	public function remove_order_source_before_retry( $order ) {
357
+	public function remove_order_source_before_retry($order) {
358 358
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
359
-		delete_post_meta( $order_id, '_stripe_source_id' );
359
+		delete_post_meta($order_id, '_stripe_source_id');
360 360
 		// For BW compat will remove in the future.
361
-		delete_post_meta( $order_id, '_stripe_card_id' );
361
+		delete_post_meta($order_id, '_stripe_card_id');
362 362
 	}
363 363
 
364 364
 	/**
365 365
 	 * Remove order meta
366 366
 	 * @param  object $order
367 367
 	 */
368
-	public function remove_order_customer_before_retry( $order ) {
368
+	public function remove_order_customer_before_retry($order) {
369 369
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
370
-		delete_post_meta( $order_id, '_stripe_customer_id' );
370
+		delete_post_meta($order_id, '_stripe_customer_id');
371 371
 	}
372 372
 
373 373
 	/**
@@ -379,14 +379,14 @@  discard block
 block discarded – undo
379 379
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
380 380
 	 * @return void
381 381
 	 */
382
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
383
-		if ( WC_Stripe_Helper::is_pre_30() ) {
384
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
385
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
382
+	public function update_failing_payment_method($subscription, $renewal_order) {
383
+		if (WC_Stripe_Helper::is_pre_30()) {
384
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
385
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
386 386
 
387 387
 		} else {
388
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
389
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
388
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
389
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
390 390
 		}
391 391
 	}
392 392
 
@@ -399,21 +399,21 @@  discard block
 block discarded – undo
399 399
 	 * @param WC_Subscription $subscription An instance of a subscription object
400 400
 	 * @return array
401 401
 	 */
402
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
403
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
402
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
403
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
404 404
 
405 405
 		// For BW compat will remove in future.
406
-		if ( empty( $source_id ) ) {
407
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
406
+		if (empty($source_id)) {
407
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
408 408
 
409 409
 			// Take this opportunity to update the key name.
410
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
410
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
411 411
 		}
412 412
 
413
-		$payment_meta[ $this->id ] = array(
413
+		$payment_meta[$this->id] = array(
414 414
 			'post_meta' => array(
415 415
 				'_stripe_customer_id' => array(
416
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
416
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
417 417
 					'label' => 'Stripe Customer ID',
418 418
 				),
419 419
 				'_stripe_source_id' => array(
@@ -436,22 +436,22 @@  discard block
 block discarded – undo
436 436
 	 * @param array $payment_meta associative array of meta data required for automatic payments
437 437
 	 * @return array
438 438
 	 */
439
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
440
-		if ( $this->id === $payment_method_id ) {
439
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
440
+		if ($this->id === $payment_method_id) {
441 441
 
442
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
443
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
444
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
445
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
442
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
443
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
444
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
445
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
446 446
 			}
447 447
 
448 448
 			if (
449
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
450
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
451
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
452
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
449
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
450
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
451
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
452
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
453 453
 
454
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
454
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
455 455
 			}
456 456
 		}
457 457
 	}
@@ -464,91 +464,91 @@  discard block
 block discarded – undo
464 464
 	 * @param WC_Subscription $subscription the subscription details
465 465
 	 * @return string the subscription payment method
466 466
 	 */
467
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
467
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
468 468
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
469 469
 
470 470
 		// bail for other payment methods
471
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
471
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
472 472
 			return $payment_method_to_display;
473 473
 		}
474 474
 
475
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
475
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
476 476
 
477 477
 		// For BW compat will remove in future.
478
-		if ( empty( $stripe_source_id ) ) {
479
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
478
+		if (empty($stripe_source_id)) {
479
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
480 480
 
481 481
 			// Take this opportunity to update the key name.
482
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
482
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
483 483
 		}
484 484
 
485 485
 		$stripe_customer    = new WC_Stripe_Customer();
486
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
486
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
487 487
 
488 488
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
489
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
489
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
490 490
 			$user_id            = $customer_user;
491
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
492
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
491
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
492
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
493 493
 
494 494
 			// For BW compat will remove in future.
495
-			if ( empty( $stripe_source_id ) ) {
496
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
495
+			if (empty($stripe_source_id)) {
496
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
497 497
 
498 498
 				// Take this opportunity to update the key name.
499
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
499
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
500 500
 			}
501 501
 		}
502 502
 
503 503
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
504
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
505
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
506
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
504
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
505
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
506
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_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_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
509
+			if (empty($stripe_source_id)) {
510
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
511 511
 
512 512
 				// Take this opportunity to update the key name.
513
-				WC_Stripe_Helper::is_pre_30() ? 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 );
513
+				WC_Stripe_Helper::is_pre_30() ? 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);
514 514
 			}
515 515
 		}
516 516
 
517
-		$stripe_customer->set_id( $stripe_customer_id );
517
+		$stripe_customer->set_id($stripe_customer_id);
518 518
 		$sources = $stripe_customer->get_sources();
519 519
 
520
-		if ( $sources ) {
520
+		if ($sources) {
521 521
 			$found_source = false;
522
-			foreach ( $sources as $source ) {
523
-				if ( isset( $source->type ) && 'card' === $source->type ) {
522
+			foreach ($sources as $source) {
523
+				if (isset($source->type) && 'card' === $source->type) {
524 524
 					$card = $source->card;
525
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
525
+				} elseif (isset($source->object) && 'card' === $source->object) {
526 526
 					$card = $source;
527 527
 				}
528 528
 
529
-				if ( $source->id === $stripe_source_id ) {
529
+				if ($source->id === $stripe_source_id) {
530 530
 					$found_source = true;
531 531
 
532
-					if ( $card ) {
532
+					if ($card) {
533 533
 						/* translators: 1) card brand 2) last 4 digits */
534
-						$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 );
534
+						$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);
535 535
 					} else {
536
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
536
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
537 537
 					}
538 538
 					break;
539 539
 				}
540 540
 			}
541 541
 
542
-			if ( ! $found_source ) {
543
-				if ( 'card' === $sources[0]->type ) {
542
+			if ( ! $found_source) {
543
+				if ('card' === $sources[0]->type) {
544 544
 					$card = $sources[0]->card;
545 545
 				}
546 546
 
547
-				if ( $card ) {
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
 				} else {
551
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
551
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
552 552
 				}
553 553
 			}
554 554
 		}
@@ -561,43 +561,43 @@  discard block
 block discarded – undo
561 561
 	 * @param int $order_id
562 562
 	 * @return array
563 563
 	 */
564
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
565
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
564
+	public function process_pre_order($order_id, $retry, $force_save_source) {
565
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
566 566
 			try {
567
-				$order = wc_get_order( $order_id );
567
+				$order = wc_get_order($order_id);
568 568
 
569
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
569
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
570 570
 					/* translators: minimum amount */
571
-					throw new Exception( 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 ) ) );
571
+					throw new Exception(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)));
572 572
 				}
573 573
 
574
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
574
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
575 575
 
576 576
 				// We need a source on file to continue.
577
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
578
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
577
+				if (empty($source->customer) || empty($source->source)) {
578
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
579 579
 				}
580 580
 
581 581
 				// Store source to order meta
582
-				$this->save_source( $order, $source );
582
+				$this->save_source($order, $source);
583 583
 
584 584
 				// Remove cart
585 585
 				WC()->cart->empty_cart();
586 586
 
587 587
 				// Is pre ordered!
588
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
588
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
589 589
 
590 590
 				// Return thank you page redirect
591 591
 				return array(
592 592
 					'result'   => 'success',
593
-					'redirect' => $this->get_return_url( $order ),
593
+					'redirect' => $this->get_return_url($order),
594 594
 				);
595
-			} catch ( Exception $e ) {
596
-				wc_add_notice( $e->getMessage(), 'error' );
595
+			} catch (Exception $e) {
596
+				wc_add_notice($e->getMessage(), 'error');
597 597
 				return;
598 598
 			}
599 599
 		} else {
600
-			return parent::process_payment( $order_id, $retry, $force_save_source );
600
+			return parent::process_payment($order_id, $retry, $force_save_source);
601 601
 		}
602 602
 	}
603 603
 
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 	 * @param WC_Order $order
607 607
 	 * @return void
608 608
 	 */
609
-	public function process_pre_order_release_payment( $order ) {
609
+	public function process_pre_order_release_payment($order) {
610 610
 		try {
611 611
 			// Define some callbacks if the first attempt fails.
612 612
 			$retry_callbacks = array(
@@ -614,33 +614,33 @@  discard block
 block discarded – undo
614 614
 				'remove_order_customer_before_retry',
615 615
 			);
616 616
 
617
-			while ( 1 ) {
618
-				$source   = $this->prepare_order_source( $order );
619
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
617
+			while (1) {
618
+				$source   = $this->prepare_order_source($order);
619
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
620 620
 
621
-				if ( ! empty( $response->error ) ) {
622
-					if ( 0 === sizeof( $retry_callbacks ) ) {
623
-						throw new Exception( $response->error->message );
621
+				if ( ! empty($response->error)) {
622
+					if (0 === sizeof($retry_callbacks)) {
623
+						throw new Exception($response->error->message);
624 624
 					} else {
625
-						$retry_callback = array_shift( $retry_callbacks );
626
-						call_user_func( array( $this, $retry_callback ), $order );
625
+						$retry_callback = array_shift($retry_callbacks);
626
+						call_user_func(array($this, $retry_callback), $order);
627 627
 					}
628 628
 				} else {
629 629
 					// Successful
630
-					$this->process_response( $response, $order );
630
+					$this->process_response($response, $order);
631 631
 					break;
632 632
 				}
633 633
 			}
634
-		} catch ( Exception $e ) {
634
+		} catch (Exception $e) {
635 635
 			/* translators: error message */
636
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
636
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
637 637
 
638 638
 			// Mark order as failed if not already set,
639 639
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
640
-			if ( ! $order->has_status( 'failed' ) ) {
641
-				$order->update_status( 'failed', $order_note );
640
+			if ( ! $order->has_status('failed')) {
641
+				$order->update_status('failed', $order_note);
642 642
 			} else {
643
-				$order->add_order_note( $order_note );
643
+				$order->add_order_note($order_note);
644 644
 			}
645 645
 		}
646 646
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -134,7 +134,6 @@  discard block
 block discarded – undo
134 134
 	 * process_subscription_payment function.
135 135
 	 * @param mixed $order
136 136
 	 * @param int $amount (default: 0)
137
-	 * @param string $stripe_token (default: '')
138 137
 	 * @param  bool initial_payment
139 138
 	 */
140 139
 	public function process_subscription_payment( $order = '', $amount = 0 ) {
@@ -178,7 +177,6 @@  discard block
 block discarded – undo
178 177
 	 *
179 178
 	 * @todo refactor to avoid DRY.
180 179
 	 * @param int $amount (default: 0)
181
-	 * @param mixed $order
182 180
 	 * @param bool initial_payment
183 181
 	 */
184 182
 	public function retry_subscription_payment( $amount = 0, $renewal_order ) {
@@ -230,7 +228,7 @@  discard block
 block discarded – undo
230 228
 
231 229
 	/**
232 230
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
233
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
231
+	 * @param integer $renewal_order
234 232
 	 */
235 233
 	public function delete_renewal_meta( $renewal_order ) {
236 234
 		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
@@ -463,6 +461,8 @@  discard block
 block discarded – undo
463 461
 	/**
464 462
 	 * Process the pre-order
465 463
 	 * @param int $order_id
464
+	 * @param boolean $retry
465
+	 * @param boolean $force_save_source
466 466
 	 * @return array
467 467
 	 */
468 468
 	public function process_pre_order( $order_id, $retry, $force_save_source ) {
Please login to merge, or discard this patch.
Spacing   +166 added lines, -166 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,24 +15,24 @@  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 );
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 23
 
24 24
 			// display the credit card used for a subscription in the "My Subscriptions" table
25
-			add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 );
25
+			add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2);
26 26
 
27 27
 			// allow store managers to manually set Stripe as the payment method on a subscription
28
-			add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 );
29
-			add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 );
30
-			add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) );
31
-			add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 );
28
+			add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2);
29
+			add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2);
30
+			add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox'));
31
+			add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2);
32 32
 		}
33 33
 
34
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
35
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
34
+		if (class_exists('WC_Pre_Orders_Order')) {
35
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
36 36
 		}
37 37
 	}
38 38
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @since 4.0.0
44 44
 	 * @version 4.0.0
45 45
 	 */
46
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
47
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
46
+	public function maybe_hide_save_checkbox($display_tokenization) {
47
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
48 48
 			return false;
49 49
 		}
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param  int  $order_id
57 57
 	 * @return boolean
58 58
 	 */
59
-	public function has_subscription( $order_id ) {
60
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
59
+	public function has_subscription($order_id) {
60
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
61 61
 	}
62 62
 
63 63
 	/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 * @param  int  $order_id
66 66
 	 * @return boolean
67 67
 	 */
68
-	protected function is_pre_order( $order_id ) {
69
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
68
+	protected function is_pre_order($order_id) {
69
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 	 * @param  int $order_id
75 75
 	 * @return array
76 76
 	 */
77
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
78
-		if ( $this->has_subscription( $order_id ) ) {
77
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
78
+		if ($this->has_subscription($order_id)) {
79 79
 			// Regular payment with force customer enabled
80
-			return parent::process_payment( $order_id, true, true );
81
-		} elseif ( $this->is_pre_order( $order_id ) ) {
82
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
80
+			return parent::process_payment($order_id, true, true);
81
+		} elseif ($this->is_pre_order($order_id)) {
82
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
83 83
 		} else {
84
-			return parent::process_payment( $order_id, $retry, $force_save_source );
84
+			return parent::process_payment($order_id, $retry, $force_save_source);
85 85
 		}
86 86
 	}
87 87
 
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	 * @param array $metadata
93 93
 	 * @param object $order
94 94
 	 */
95
-	public function add_subscription_meta_data( $metadata, $order ) {
96
-		if ( ! $this->has_subscription( $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription($order->get_id())) {
97 97
 			return $metadata;
98 98
 		}
99 99
 
100 100
 		return $metadata += array(
101 101
 			'payment_type'   => 'recurring',
102
-			'site_url'       => esc_url( get_site_url() ),
102
+			'site_url'       => esc_url(get_site_url()),
103 103
 		);
104 104
 	}
105 105
 
@@ -109,24 +109,24 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.1.0
110 110
 	 * @version 4.0.0
111 111
 	 */
112
-	public function save_source( $order, $source ) {
113
-		parent::save_source( $order, $source );
112
+	public function save_source($order, $source) {
113
+		parent::save_source($order, $source);
114 114
 
115
-		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
115
+		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
116 116
 
117 117
 		// Also store it on the subscriptions being purchased or paid for in the order
118
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
119
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
120
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
121
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
118
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
119
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
120
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
121
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
122 122
 		} else {
123 123
 			$subscriptions = array();
124 124
 		}
125 125
 
126
-		foreach ( $subscriptions as $subscription ) {
126
+		foreach ($subscriptions as $subscription) {
127 127
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
128
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
129
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
128
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
129
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
130 130
 		}
131 131
 	}
132 132
 
@@ -137,37 +137,37 @@  discard block
 block discarded – undo
137 137
 	 * @param string $stripe_token (default: '')
138 138
 	 * @param  bool initial_payment
139 139
 	 */
140
-	public function process_subscription_payment( $order = '', $amount = 0 ) {
141
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
140
+	public function process_subscription_payment($order = '', $amount = 0) {
141
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
142 142
 			/* translators: minimum amount */
143
-			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 ) ) );
143
+			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)));
144 144
 		}
145 145
 
146 146
 		$customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
147 147
 		$order_id    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
148 148
 
149 149
 		// Get source from order
150
-		$prepared_source = $this->prepare_order_source( $order );
150
+		$prepared_source = $this->prepare_order_source($order);
151 151
 
152 152
 		// Or fail :(
153
-		if ( ! $prepared_source->customer ) {
154
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
153
+		if ( ! $prepared_source->customer) {
154
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
155 155
 		}
156 156
 
157
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
157
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
158 158
 
159 159
 		// Make the request
160
-		$request             = $this->generate_payment_request( $order, $prepared_source );
160
+		$request             = $this->generate_payment_request($order, $prepared_source);
161 161
 		$request['capture']  = 'true';
162
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
163
-		$response            = WC_Stripe_API::request( $request );
162
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
163
+		$response            = WC_Stripe_API::request($request);
164 164
 
165 165
 		// Process valid response
166
-		if ( ! empty( $response->error ) ) {
166
+		if ( ! empty($response->error)) {
167 167
 			return $response; // Default catch all errors.
168 168
 		}
169 169
 
170
-		$this->process_response( $response, $order );
170
+		$this->process_response($response, $order);
171 171
 
172 172
 		return $response;
173 173
 	}
@@ -181,60 +181,60 @@  discard block
 block discarded – undo
181 181
 	 * @param mixed $order
182 182
 	 * @param bool initial_payment
183 183
 	 */
184
-	public function retry_subscription_payment( $amount = 0, $renewal_order ) {
185
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
184
+	public function retry_subscription_payment($amount = 0, $renewal_order) {
185
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
186 186
 			/* translators: minimum amount */
187
-			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 ) ) );
187
+			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)));
188 188
 		}
189 189
 
190 190
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
191 191
 
192 192
 		// Get source from order
193
-		$prepared_source = $this->prepare_order_source( $renewal_order );
193
+		$prepared_source = $this->prepare_order_source($renewal_order);
194 194
 
195 195
 		// Or fail :(
196
-		if ( ! $prepared_source->customer ) {
197
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
196
+		if ( ! $prepared_source->customer) {
197
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
198 198
 		}
199 199
 
200 200
 		// Passing empty source with charge customer default.
201 201
 		$prepared_source->source = '';
202 202
 
203
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
203
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
204 204
 
205 205
 		// Make the request
206
-		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
206
+		$request             = $this->generate_payment_request($renewal_order, $prepared_source);
207 207
 		$request['capture']  = 'true';
208
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
209
-		$response            = WC_Stripe_API::request( $request );
208
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
209
+		$response            = WC_Stripe_API::request($request);
210 210
 
211
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
211
+		if ( ! empty($response->error) || is_wp_error($response)) {
212 212
 			/* translators: error message */
213
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
213
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
214 214
 		}
215 215
 
216
-		$this->process_response( $response, $renewal_order );
216
+		$this->process_response($response, $renewal_order);
217 217
 	}
218 218
 
219 219
 	/**
220 220
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
221 221
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
222 222
 	 */
223
-	public function delete_resubscribe_meta( $resubscribe_order ) {
224
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
225
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
223
+	public function delete_resubscribe_meta($resubscribe_order) {
224
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
225
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
226 226
 		// For BW compat will remove in future
227
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
228
-		$this->delete_renewal_meta( $resubscribe_order );
227
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
228
+		$this->delete_renewal_meta($resubscribe_order);
229 229
 	}
230 230
 
231 231
 	/**
232 232
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
233 233
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
234 234
 	 */
235
-	public function delete_renewal_meta( $renewal_order ) {
236
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
237
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
235
+	public function delete_renewal_meta($renewal_order) {
236
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
237
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
238 238
 		return $renewal_order;
239 239
 	}
240 240
 
@@ -244,21 +244,21 @@  discard block
 block discarded – undo
244 244
 	 * @param $amount_to_charge float The amount to charge.
245 245
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
246 246
 	 */
247
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
248
-		$response = $this->process_subscription_payment( $renewal_order, $amount_to_charge );
247
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
248
+		$response = $this->process_subscription_payment($renewal_order, $amount_to_charge);
249 249
 
250
-		if ( is_wp_error( $response ) ) {
250
+		if (is_wp_error($response)) {
251 251
 			/* translators: error message */
252
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
252
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
253 253
 		}
254 254
 
255
-		if ( ! empty( $response->error ) ) {
255
+		if ( ! empty($response->error)) {
256 256
 			// This is a very generic error to listen for but worth a retry before total fail.
257
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
258
-				$this->retry_subscription_payment( $amount_to_charge, $renewal_order );
257
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
258
+				$this->retry_subscription_payment($amount_to_charge, $renewal_order);
259 259
 			} else {
260 260
 				/* translators: error message */
261
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
261
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
262 262
 			}
263 263
 		}
264 264
 	}
@@ -267,20 +267,20 @@  discard block
 block discarded – undo
267 267
 	 * Remove order meta
268 268
 	 * @param  object $order
269 269
 	 */
270
-	public function remove_order_source_before_retry( $order ) {
270
+	public function remove_order_source_before_retry($order) {
271 271
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
272
-		delete_post_meta( $order_id, '_stripe_source_id' );
272
+		delete_post_meta($order_id, '_stripe_source_id');
273 273
 		// For BW compat will remove in the future.
274
-		delete_post_meta( $order_id, '_stripe_card_id' );
274
+		delete_post_meta($order_id, '_stripe_card_id');
275 275
 	}
276 276
 
277 277
 	/**
278 278
 	 * Remove order meta
279 279
 	 * @param  object $order
280 280
 	 */
281
-	public function remove_order_customer_before_retry( $order ) {
281
+	public function remove_order_customer_before_retry($order) {
282 282
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
283
-		delete_post_meta( $order_id, '_stripe_customer_id' );
283
+		delete_post_meta($order_id, '_stripe_customer_id');
284 284
 	}
285 285
 
286 286
 	/**
@@ -292,14 +292,14 @@  discard block
 block discarded – undo
292 292
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
293 293
 	 * @return void
294 294
 	 */
295
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
296
-		if ( WC_Stripe_Helper::is_pre_30() ) {
297
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
298
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
295
+	public function update_failing_payment_method($subscription, $renewal_order) {
296
+		if (WC_Stripe_Helper::is_pre_30()) {
297
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
298
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
299 299
 
300 300
 		} else {
301
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
302
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
301
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
302
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
303 303
 		}
304 304
 	}
305 305
 
@@ -312,21 +312,21 @@  discard block
 block discarded – undo
312 312
 	 * @param WC_Subscription $subscription An instance of a subscription object
313 313
 	 * @return array
314 314
 	 */
315
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
316
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
315
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
316
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
317 317
 
318 318
 		// For BW compat will remove in future.
319
-		if ( empty( $source_id ) ) {
320
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
319
+		if (empty($source_id)) {
320
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
321 321
 
322 322
 			// Take this opportunity to update the key name.
323
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id );
323
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id);
324 324
 		}
325 325
 
326
-		$payment_meta[ $this->id ] = array(
326
+		$payment_meta[$this->id] = array(
327 327
 			'post_meta' => array(
328 328
 				'_stripe_customer_id' => array(
329
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
329
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
330 330
 					'label' => 'Stripe Customer ID',
331 331
 				),
332 332
 				'_stripe_source_id' => array(
@@ -347,17 +347,17 @@  discard block
 block discarded – undo
347 347
 	 * @param array $payment_meta associative array of meta data required for automatic payments
348 348
 	 * @return array
349 349
 	 */
350
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
351
-		if ( $this->id === $payment_method_id ) {
350
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
351
+		if ($this->id === $payment_method_id) {
352 352
 
353
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
354
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
355
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
356
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
353
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
354
+				throw new Exception('A "_stripe_customer_id" value is required.');
355
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
356
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
357 357
 			}
358 358
 
359
-			if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) {
360
-				throw new Exception( 'A "_stripe_source_id" value is required.' );
359
+			if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) {
360
+				throw new Exception('A "_stripe_source_id" value is required.');
361 361
 			}
362 362
 		}
363 363
 	}
@@ -370,89 +370,89 @@  discard block
 block discarded – undo
370 370
 	 * @param WC_Subscription $subscription the subscription details
371 371
 	 * @return string the subscription payment method
372 372
 	 */
373
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
373
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
374 374
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
375 375
 
376 376
 		// bail for other payment methods
377
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
377
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
378 378
 			return $payment_method_to_display;
379 379
 		}
380 380
 
381
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
381
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
382 382
 
383 383
 		// For BW compat will remove in future.
384
-		if ( empty( $stripe_source_id ) ) {
385
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
384
+		if (empty($stripe_source_id)) {
385
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
386 386
 
387 387
 			// Take this opportunity to update the key name.
388
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id );
388
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id);
389 389
 		}
390 390
 
391 391
 		$stripe_customer    = new WC_Stripe_Customer();
392
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
392
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
393 393
 
394 394
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
395
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
395
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
396 396
 			$user_id            = $customer_user;
397
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
398
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
397
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
398
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
399 399
 
400 400
 			// For BW compat will remove in future.
401
-			if ( empty( $stripe_source_id ) ) {
402
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
401
+			if (empty($stripe_source_id)) {
402
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
403 403
 
404 404
 				// Take this opportunity to update the key name.
405
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
405
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
406 406
 			}
407 407
 		}
408 408
 
409 409
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
410
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
411
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
412
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
410
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
411
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
412
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
413 413
 
414 414
 			// For BW compat will remove in future.
415
-			if ( empty( $stripe_source_id ) ) {
416
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
415
+			if (empty($stripe_source_id)) {
416
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
417 417
 
418 418
 				// Take this opportunity to update the key name.
419
-				WC_Stripe_Helper::is_pre_30() ? 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 );
419
+				WC_Stripe_Helper::is_pre_30() ? 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);
420 420
 			}
421 421
 		}
422 422
 
423
-		$stripe_customer->set_id( $stripe_customer_id );
423
+		$stripe_customer->set_id($stripe_customer_id);
424 424
 		$sources = $stripe_customer->get_sources();
425 425
 
426
-		if ( $sources ) {
426
+		if ($sources) {
427 427
 			$found_source = false;
428
-			foreach ( $sources as $source ) {
429
-				if ( isset( $source->type ) && 'card' === $source->type ) {
428
+			foreach ($sources as $source) {
429
+				if (isset($source->type) && 'card' === $source->type) {
430 430
 					$card = $source->card;
431 431
 				}
432 432
 
433
-				if ( $source->id === $stripe_source_id ) {
433
+				if ($source->id === $stripe_source_id) {
434 434
 					$found_source = true;
435 435
 
436
-					if ( $card ) {
436
+					if ($card) {
437 437
 						/* translators: 1) card brand 2) last 4 digits */
438
-						$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 );
438
+						$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);
439 439
 					} else {
440
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
440
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
441 441
 					}
442 442
 					break;
443 443
 				}
444 444
 			}
445 445
 
446
-			if ( ! $found_source ) {
447
-				if ( 'card' === $sources[0]->type ) {
446
+			if ( ! $found_source) {
447
+				if ('card' === $sources[0]->type) {
448 448
 					$card = $sources[0]->card;
449 449
 				}
450 450
 
451
-				if ( $card ) {
451
+				if ($card) {
452 452
 					/* translators: 1) card brand 2) last 4 digits */
453
-					$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 );
453
+					$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);
454 454
 				} else {
455
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
455
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
456 456
 				}
457 457
 			}
458 458
 		}
@@ -465,43 +465,43 @@  discard block
 block discarded – undo
465 465
 	 * @param int $order_id
466 466
 	 * @return array
467 467
 	 */
468
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
469
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
468
+	public function process_pre_order($order_id, $retry, $force_save_source) {
469
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
470 470
 			try {
471
-				$order = wc_get_order( $order_id );
471
+				$order = wc_get_order($order_id);
472 472
 
473
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
473
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
474 474
 					/* translators: minimum amount */
475
-					throw new Exception( 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 ) ) );
475
+					throw new Exception(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)));
476 476
 				}
477 477
 
478
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
478
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
479 479
 
480 480
 				// We need a source on file to continue.
481
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
482
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
481
+				if (empty($source->customer) || empty($source->source)) {
482
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
483 483
 				}
484 484
 
485 485
 				// Store source to order meta
486
-				$this->save_source( $order, $source );
486
+				$this->save_source($order, $source);
487 487
 
488 488
 				// Remove cart
489 489
 				WC()->cart->empty_cart();
490 490
 
491 491
 				// Is pre ordered!
492
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
492
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
493 493
 
494 494
 				// Return thank you page redirect
495 495
 				return array(
496 496
 					'result'   => 'success',
497
-					'redirect' => $this->get_return_url( $order ),
497
+					'redirect' => $this->get_return_url($order),
498 498
 				);
499
-			} catch ( Exception $e ) {
500
-				wc_add_notice( $e->getMessage(), 'error' );
499
+			} catch (Exception $e) {
500
+				wc_add_notice($e->getMessage(), 'error');
501 501
 				return;
502 502
 			}
503 503
 		} else {
504
-			return parent::process_payment( $order_id, $retry, $force_save_source );
504
+			return parent::process_payment($order_id, $retry, $force_save_source);
505 505
 		}
506 506
 	}
507 507
 
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 * @param WC_Order $order
511 511
 	 * @return void
512 512
 	 */
513
-	public function process_pre_order_release_payment( $order ) {
513
+	public function process_pre_order_release_payment($order) {
514 514
 		try {
515 515
 			// Define some callbacks if the first attempt fails.
516 516
 			$retry_callbacks = array(
@@ -518,33 +518,33 @@  discard block
 block discarded – undo
518 518
 				'remove_order_customer_before_retry',
519 519
 			);
520 520
 
521
-			while ( 1 ) {
522
-				$source   = $this->prepare_order_source( $order );
523
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
521
+			while (1) {
522
+				$source   = $this->prepare_order_source($order);
523
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
524 524
 
525
-				if ( ! empty( $response->error ) ) {
526
-					if ( 0 === sizeof( $retry_callbacks ) ) {
527
-						throw new Exception( $response->error->message );
525
+				if ( ! empty($response->error)) {
526
+					if (0 === sizeof($retry_callbacks)) {
527
+						throw new Exception($response->error->message);
528 528
 					} else {
529
-						$retry_callback = array_shift( $retry_callbacks );
530
-						call_user_func( array( $this, $retry_callback ), $order );
529
+						$retry_callback = array_shift($retry_callbacks);
530
+						call_user_func(array($this, $retry_callback), $order);
531 531
 					}
532 532
 				} else {
533 533
 					// Successful
534
-					$this->process_response( $response, $order );
534
+					$this->process_response($response, $order);
535 535
 					break;
536 536
 				}
537 537
 			}
538
-		} catch ( Exception $e ) {
538
+		} catch (Exception $e) {
539 539
 			/* translators: error message */
540
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
540
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
541 541
 
542 542
 			// Mark order as failed if not already set,
543 543
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
544
-			if ( ! $order->has_status( 'failed' ) ) {
545
-				$order->update_status( 'failed', $order_note );
544
+			if ( ! $order->has_status('failed')) {
545
+				$order->update_status('failed', $order_note);
546 546
 			} else {
547
-				$order->add_order_note( $order_note );
547
+				$order->add_order_note($order_note);
548 548
 			}
549 549
 		}
550 550
 	}
Please login to merge, or discard this patch.