Completed
Push — master ( d2c6b4...e94018 )
by Roy
02:15
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/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/compat/class-wc-stripe-compat.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
 	/**
316 316
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
317
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
317
+	 * @param integer $renewal_order
318 318
 	 */
319 319
 	public function delete_renewal_meta( $renewal_order ) {
320 320
 		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
@@ -556,6 +556,8 @@  discard block
 block discarded – undo
556 556
 	/**
557 557
 	 * Process the pre-order
558 558
 	 * @param int $order_id
559
+	 * @param boolean $retry
560
+	 * @param boolean $force_save_source
559 561
 	 * @return array
560 562
 	 */
561 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
 
@@ -223,35 +223,35 @@  discard block
 block discarded – undo
223 223
 	 * @param mixed $renewal_order
224 224
 	 * @param  bool initial_payment
225 225
 	 */
226
-	public function process_subscription_payment( $amount = 0.0, $renewal_order ) {
227
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
226
+	public function process_subscription_payment($amount = 0.0, $renewal_order) {
227
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
228 228
 			/* translators: minimum amount */
229
-			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 ) ) );
229
+			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 230
 		}
231 231
 
232 232
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
233 233
 
234 234
 		// Get source from order
235
-		$prepared_source = $this->prepare_order_source( $renewal_order );
235
+		$prepared_source = $this->prepare_order_source($renewal_order);
236 236
 
237
-		if ( ! $prepared_source->customer ) {
238
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
237
+		if ( ! $prepared_source->customer) {
238
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
239 239
 		}
240 240
 
241
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
241
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
242 242
 
243 243
 		// Make the request
244
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
244
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
245 245
 		$request['capture'] = 'true';
246
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
247
-		$response           = WC_Stripe_API::request( $request );
246
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
247
+		$response           = WC_Stripe_API::request($request);
248 248
 
249 249
 		// Process valid response
250
-		if ( ! empty( $response->error ) ) {
250
+		if ( ! empty($response->error)) {
251 251
 			return $response; // Default catch all errors.
252 252
 		}
253 253
 
254
-		$this->process_response( $response, $renewal_order );
254
+		$this->process_response($response, $renewal_order);
255 255
 
256 256
 		return $response;
257 257
 	}
@@ -265,59 +265,59 @@  discard block
 block discarded – undo
265 265
 	 * @param mixed $renewal_order
266 266
 	 * @param  bool initial_payment
267 267
 	 */
268
-	public function retry_subscription_payment( $amount = 0.0, $renewal_order ) {
269
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
268
+	public function retry_subscription_payment($amount = 0.0, $renewal_order) {
269
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
270 270
 			/* translators: minimum amount */
271
-			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 ) ) );
271
+			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)));
272 272
 		}
273 273
 
274 274
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
275 275
 
276 276
 		// Get source from order
277
-		$prepared_source = $this->prepare_order_source( $renewal_order );
277
+		$prepared_source = $this->prepare_order_source($renewal_order);
278 278
 
279
-		if ( ! $prepared_source->customer ) {
280
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
279
+		if ( ! $prepared_source->customer) {
280
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
281 281
 		}
282 282
 
283 283
 		// Passing empty source with charge customer default.
284 284
 		$prepared_source->source = '';
285 285
 
286
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
286
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
287 287
 
288 288
 		// Make the request
289
-		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
289
+		$request             = $this->generate_payment_request($renewal_order, $prepared_source);
290 290
 		$request['capture']  = 'true';
291
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
292
-		$response            = WC_Stripe_API::request( $request );
291
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
292
+		$response            = WC_Stripe_API::request($request);
293 293
 
294
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
294
+		if ( ! empty($response->error) || is_wp_error($response)) {
295 295
 			/* translators: error message */
296
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
296
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
297 297
 		}
298 298
 
299
-		$this->process_response( $response, $renewal_order );
299
+		$this->process_response($response, $renewal_order);
300 300
 	}
301 301
 
302 302
 	/**
303 303
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
304 304
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
305 305
 	 */
306
-	public function delete_resubscribe_meta( $resubscribe_order ) {
307
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
308
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
306
+	public function delete_resubscribe_meta($resubscribe_order) {
307
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
308
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
309 309
 		// For BW compat will remove in future
310
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
311
-		$this->delete_renewal_meta( $resubscribe_order );
310
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
311
+		$this->delete_renewal_meta($resubscribe_order);
312 312
 	}
313 313
 
314 314
 	/**
315 315
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
316 316
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
317 317
 	 */
318
-	public function delete_renewal_meta( $renewal_order ) {
319
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
320
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
318
+	public function delete_renewal_meta($renewal_order) {
319
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
320
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
321 321
 		return $renewal_order;
322 322
 	}
323 323
 
@@ -327,21 +327,21 @@  discard block
 block discarded – undo
327 327
 	 * @param $amount_to_charge float The amount to charge.
328 328
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
329 329
 	 */
330
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
331
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
330
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
331
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
332 332
 
333
-		if ( is_wp_error( $response ) ) {
333
+		if (is_wp_error($response)) {
334 334
 			/* translators: error message */
335
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
335
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
336 336
 		}
337 337
 
338
-		if ( ! empty( $response->error ) ) {
338
+		if ( ! empty($response->error)) {
339 339
 			// This is a very generic error to listen for but worth a retry before total fail.
340
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
341
-				$this->retry_subscription_payment( $amount_to_charge, $renewal_order );
340
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
341
+				$this->retry_subscription_payment($amount_to_charge, $renewal_order);
342 342
 			} else {
343 343
 				/* translators: error message */
344
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
344
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
345 345
 			}
346 346
 		}
347 347
 	}
@@ -350,20 +350,20 @@  discard block
 block discarded – undo
350 350
 	 * Remove order meta
351 351
 	 * @param object $order
352 352
 	 */
353
-	public function remove_order_source_before_retry( $order ) {
353
+	public function remove_order_source_before_retry($order) {
354 354
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
355
-		delete_post_meta( $order_id, '_stripe_source_id' );
355
+		delete_post_meta($order_id, '_stripe_source_id');
356 356
 		// For BW compat will remove in the future.
357
-		delete_post_meta( $order_id, '_stripe_card_id' );
357
+		delete_post_meta($order_id, '_stripe_card_id');
358 358
 	}
359 359
 
360 360
 	/**
361 361
 	 * Remove order meta
362 362
 	 * @param  object $order
363 363
 	 */
364
-	public function remove_order_customer_before_retry( $order ) {
364
+	public function remove_order_customer_before_retry($order) {
365 365
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
366
-		delete_post_meta( $order_id, '_stripe_customer_id' );
366
+		delete_post_meta($order_id, '_stripe_customer_id');
367 367
 	}
368 368
 
369 369
 	/**
@@ -375,14 +375,14 @@  discard block
 block discarded – undo
375 375
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
376 376
 	 * @return void
377 377
 	 */
378
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
379
-		if ( WC_Stripe_Helper::is_pre_30() ) {
380
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
381
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
378
+	public function update_failing_payment_method($subscription, $renewal_order) {
379
+		if (WC_Stripe_Helper::is_pre_30()) {
380
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
381
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
382 382
 
383 383
 		} else {
384
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
385
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
384
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
385
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
386 386
 		}
387 387
 	}
388 388
 
@@ -395,21 +395,21 @@  discard block
 block discarded – undo
395 395
 	 * @param WC_Subscription $subscription An instance of a subscription object
396 396
 	 * @return array
397 397
 	 */
398
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
399
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
398
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
399
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
400 400
 
401 401
 		// For BW compat will remove in future.
402
-		if ( empty( $source_id ) ) {
403
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
402
+		if (empty($source_id)) {
403
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
404 404
 
405 405
 			// Take this opportunity to update the key name.
406
-			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 );
406
+			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);
407 407
 		}
408 408
 
409
-		$payment_meta[ $this->id ] = array(
409
+		$payment_meta[$this->id] = array(
410 410
 			'post_meta' => array(
411 411
 				'_stripe_customer_id' => array(
412
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
412
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
413 413
 					'label' => 'Stripe Customer ID',
414 414
 				),
415 415
 				'_stripe_source_id' => array(
@@ -432,22 +432,22 @@  discard block
 block discarded – undo
432 432
 	 * @param array $payment_meta associative array of meta data required for automatic payments
433 433
 	 * @return array
434 434
 	 */
435
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
436
-		if ( $this->id === $payment_method_id ) {
435
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
436
+		if ($this->id === $payment_method_id) {
437 437
 
438
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
439
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
440
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
441
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
438
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
439
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
440
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
441
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
442 442
 			}
443 443
 
444 444
 			if (
445
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
446
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
447
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
448
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
445
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
446
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
447
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
448
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
449 449
 
450
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
450
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
451 451
 			}
452 452
 		}
453 453
 	}
@@ -460,91 +460,91 @@  discard block
 block discarded – undo
460 460
 	 * @param WC_Subscription $subscription the subscription details
461 461
 	 * @return string the subscription payment method
462 462
 	 */
463
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
463
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
464 464
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
465 465
 
466 466
 		// bail for other payment methods
467
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
467
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
468 468
 			return $payment_method_to_display;
469 469
 		}
470 470
 
471
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
471
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
472 472
 
473 473
 		// For BW compat will remove in future.
474
-		if ( empty( $stripe_source_id ) ) {
475
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
474
+		if (empty($stripe_source_id)) {
475
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
476 476
 
477 477
 			// Take this opportunity to update the key name.
478
-			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 );
478
+			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);
479 479
 		}
480 480
 
481 481
 		$stripe_customer    = new WC_Stripe_Customer();
482
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
482
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
483 483
 
484 484
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
485
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
485
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
486 486
 			$user_id            = $customer_user;
487
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
488
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
487
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
488
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
489 489
 
490 490
 			// For BW compat will remove in future.
491
-			if ( empty( $stripe_source_id ) ) {
492
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
491
+			if (empty($stripe_source_id)) {
492
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
493 493
 
494 494
 				// Take this opportunity to update the key name.
495
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
495
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
496 496
 			}
497 497
 		}
498 498
 
499 499
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
500
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
501
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
502
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
500
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
501
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
502
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
503 503
 
504 504
 			// For BW compat will remove in future.
505
-			if ( empty( $stripe_source_id ) ) {
506
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
505
+			if (empty($stripe_source_id)) {
506
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
507 507
 
508 508
 				// Take this opportunity to update the key name.
509
-				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 );
509
+				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);
510 510
 			}
511 511
 		}
512 512
 
513
-		$stripe_customer->set_id( $stripe_customer_id );
513
+		$stripe_customer->set_id($stripe_customer_id);
514 514
 		$sources = $stripe_customer->get_sources();
515 515
 
516
-		if ( $sources ) {
516
+		if ($sources) {
517 517
 			$found_source = false;
518
-			foreach ( $sources as $source ) {
519
-				if ( isset( $source->type ) && 'card' === $source->type ) {
518
+			foreach ($sources as $source) {
519
+				if (isset($source->type) && 'card' === $source->type) {
520 520
 					$card = $source->card;
521
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
521
+				} elseif (isset($source->object) && 'card' === $source->object) {
522 522
 					$card = $source;
523 523
 				}
524 524
 
525
-				if ( $source->id === $stripe_source_id ) {
525
+				if ($source->id === $stripe_source_id) {
526 526
 					$found_source = true;
527 527
 
528
-					if ( $card ) {
528
+					if ($card) {
529 529
 						/* translators: 1) card brand 2) last 4 digits */
530
-						$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 );
530
+						$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);
531 531
 					} else {
532
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
532
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
533 533
 					}
534 534
 					break;
535 535
 				}
536 536
 			}
537 537
 
538
-			if ( ! $found_source ) {
539
-				if ( 'card' === $sources[0]->type ) {
538
+			if ( ! $found_source) {
539
+				if ('card' === $sources[0]->type) {
540 540
 					$card = $sources[0]->card;
541 541
 				}
542 542
 
543
-				if ( $card ) {
543
+				if ($card) {
544 544
 					/* translators: 1) card brand 2) last 4 digits */
545
-					$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 );
545
+					$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);
546 546
 				} else {
547
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
547
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
548 548
 				}
549 549
 			}
550 550
 		}
@@ -557,43 +557,43 @@  discard block
 block discarded – undo
557 557
 	 * @param int $order_id
558 558
 	 * @return array
559 559
 	 */
560
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
561
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
560
+	public function process_pre_order($order_id, $retry, $force_save_source) {
561
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
562 562
 			try {
563
-				$order = wc_get_order( $order_id );
563
+				$order = wc_get_order($order_id);
564 564
 
565
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
565
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
566 566
 					/* translators: minimum amount */
567
-					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 ) ) );
567
+					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)));
568 568
 				}
569 569
 
570
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
570
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
571 571
 
572 572
 				// We need a source on file to continue.
573
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
574
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
573
+				if (empty($source->customer) || empty($source->source)) {
574
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
575 575
 				}
576 576
 
577 577
 				// Store source to order meta
578
-				$this->save_source( $order, $source );
578
+				$this->save_source($order, $source);
579 579
 
580 580
 				// Remove cart
581 581
 				WC()->cart->empty_cart();
582 582
 
583 583
 				// Is pre ordered!
584
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
584
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
585 585
 
586 586
 				// Return thank you page redirect
587 587
 				return array(
588 588
 					'result'   => 'success',
589
-					'redirect' => $this->get_return_url( $order ),
589
+					'redirect' => $this->get_return_url($order),
590 590
 				);
591
-			} catch ( Exception $e ) {
592
-				wc_add_notice( $e->getMessage(), 'error' );
591
+			} catch (Exception $e) {
592
+				wc_add_notice($e->getMessage(), 'error');
593 593
 				return;
594 594
 			}
595 595
 		} else {
596
-			return parent::process_payment( $order_id, $retry, $force_save_source );
596
+			return parent::process_payment($order_id, $retry, $force_save_source);
597 597
 		}
598 598
 	}
599 599
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 	 * @param WC_Order $order
603 603
 	 * @return void
604 604
 	 */
605
-	public function process_pre_order_release_payment( $order ) {
605
+	public function process_pre_order_release_payment($order) {
606 606
 		try {
607 607
 			// Define some callbacks if the first attempt fails.
608 608
 			$retry_callbacks = array(
@@ -610,33 +610,33 @@  discard block
 block discarded – undo
610 610
 				'remove_order_customer_before_retry',
611 611
 			);
612 612
 
613
-			while ( 1 ) {
614
-				$source   = $this->prepare_order_source( $order );
615
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
613
+			while (1) {
614
+				$source   = $this->prepare_order_source($order);
615
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
616 616
 
617
-				if ( ! empty( $response->error ) ) {
618
-					if ( 0 === sizeof( $retry_callbacks ) ) {
619
-						throw new Exception( $response->error->message );
617
+				if ( ! empty($response->error)) {
618
+					if (0 === sizeof($retry_callbacks)) {
619
+						throw new Exception($response->error->message);
620 620
 					} else {
621
-						$retry_callback = array_shift( $retry_callbacks );
622
-						call_user_func( array( $this, $retry_callback ), $order );
621
+						$retry_callback = array_shift($retry_callbacks);
622
+						call_user_func(array($this, $retry_callback), $order);
623 623
 					}
624 624
 				} else {
625 625
 					// Successful
626
-					$this->process_response( $response, $order );
626
+					$this->process_response($response, $order);
627 627
 					break;
628 628
 				}
629 629
 			}
630
-		} catch ( Exception $e ) {
630
+		} catch (Exception $e) {
631 631
 			/* translators: error message */
632
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
632
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
633 633
 
634 634
 			// Mark order as failed if not already set,
635 635
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
636
-			if ( ! $order->has_status( 'failed' ) ) {
637
-				$order->update_status( 'failed', $order_note );
636
+			if ( ! $order->has_status('failed')) {
637
+				$order->update_status('failed', $order_note);
638 638
 			} else {
639
-				$order->add_order_note( $order_note );
639
+				$order->add_order_note($order_note);
640 640
 			}
641 641
 		}
642 642
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
 	/**
316 316
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
317
-	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
317
+	 * @param integer $renewal_order
318 318
 	 */
319 319
 	public function delete_renewal_meta( $renewal_order ) {
320 320
 		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
@@ -556,6 +556,8 @@  discard block
 block discarded – undo
556 556
 	/**
557 557
 	 * Process the pre-order
558 558
 	 * @param int $order_id
559
+	 * @param boolean $retry
560
+	 * @param boolean $force_save_source
559 561
 	 * @return array
560 562
 	 */
561 563
 	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
 
@@ -136,35 +136,35 @@  discard block
 block discarded – undo
136 136
 	 * @param mixed $renewal_order
137 137
 	 * @param  bool initial_payment
138 138
 	 */
139
-	public function process_subscription_payment( $amount = 0.0, $renewal_order ) {
140
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
139
+	public function process_subscription_payment($amount = 0.0, $renewal_order) {
140
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
141 141
 			/* translators: minimum amount */
142
-			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 ) ) );
142
+			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 143
 		}
144 144
 
145 145
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
146 146
 
147 147
 		// Get source from order
148
-		$prepared_source = $this->prepare_order_source( $renewal_order );
148
+		$prepared_source = $this->prepare_order_source($renewal_order);
149 149
 
150
-		if ( ! $prepared_source->customer ) {
151
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
150
+		if ( ! $prepared_source->customer) {
151
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
152 152
 		}
153 153
 
154
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
154
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
155 155
 
156 156
 		// Make the request
157
-		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
157
+		$request             = $this->generate_payment_request($renewal_order, $prepared_source);
158 158
 		$request['capture']  = 'true';
159
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
160
-		$response            = WC_Stripe_API::request( $request );
159
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
160
+		$response            = WC_Stripe_API::request($request);
161 161
 
162 162
 		// Process valid response
163
-		if ( ! empty( $response->error ) ) {
163
+		if ( ! empty($response->error)) {
164 164
 			return $response; // Default catch all errors.
165 165
 		}
166 166
 
167
-		$this->process_response( $response, $renewal_order );
167
+		$this->process_response($response, $renewal_order);
168 168
 
169 169
 		return $response;
170 170
 	}
@@ -178,59 +178,59 @@  discard block
 block discarded – undo
178 178
 	 * @param mixed $renewal_order
179 179
 	 * @param bool initial_payment
180 180
 	 */
181
-	public function retry_subscription_payment( $amount = 0.0, $renewal_order ) {
182
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
181
+	public function retry_subscription_payment($amount = 0.0, $renewal_order) {
182
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
183 183
 			/* translators: minimum amount */
184
-			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 ) ) );
184
+			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)));
185 185
 		}
186 186
 
187 187
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
188 188
 
189 189
 		// Get source from order
190
-		$prepared_source = $this->prepare_order_source( $renewal_order );
190
+		$prepared_source = $this->prepare_order_source($renewal_order);
191 191
 
192
-		if ( ! $prepared_source->customer ) {
193
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
192
+		if ( ! $prepared_source->customer) {
193
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
194 194
 		}
195 195
 
196 196
 		// Passing empty source with charge customer default.
197 197
 		$prepared_source->source = '';
198 198
 
199
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
199
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
200 200
 
201 201
 		// Make the request
202
-		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
202
+		$request             = $this->generate_payment_request($renewal_order, $prepared_source);
203 203
 		$request['capture']  = 'true';
204
-		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
205
-		$response            = WC_Stripe_API::request( $request );
204
+		$request['amount']   = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
205
+		$response            = WC_Stripe_API::request($request);
206 206
 
207
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
207
+		if ( ! empty($response->error) || is_wp_error($response)) {
208 208
 			/* translators: error message */
209
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
209
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
210 210
 		}
211 211
 
212
-		$this->process_response( $response, $renewal_order );
212
+		$this->process_response($response, $renewal_order);
213 213
 	}
214 214
 
215 215
 	/**
216 216
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
217 217
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
218 218
 	 */
219
-	public function delete_resubscribe_meta( $resubscribe_order ) {
220
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
221
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
219
+	public function delete_resubscribe_meta($resubscribe_order) {
220
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
221
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
222 222
 		// For BW compat will remove in future
223
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
224
-		$this->delete_renewal_meta( $resubscribe_order );
223
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
224
+		$this->delete_renewal_meta($resubscribe_order);
225 225
 	}
226 226
 
227 227
 	/**
228 228
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
229 229
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
230 230
 	 */
231
-	public function delete_renewal_meta( $renewal_order ) {
232
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
233
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
231
+	public function delete_renewal_meta($renewal_order) {
232
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
233
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
234 234
 		return $renewal_order;
235 235
 	}
236 236
 
@@ -240,21 +240,21 @@  discard block
 block discarded – undo
240 240
 	 * @param $amount_to_charge float The amount to charge.
241 241
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
242 242
 	 */
243
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
244
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
243
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
244
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
245 245
 
246
-		if ( is_wp_error( $response ) ) {
246
+		if (is_wp_error($response)) {
247 247
 			/* translators: error message */
248
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
248
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
249 249
 		}
250 250
 
251
-		if ( ! empty( $response->error ) ) {
251
+		if ( ! empty($response->error)) {
252 252
 			// This is a very generic error to listen for but worth a retry before total fail.
253
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
254
-				$this->retry_subscription_payment( $amount_to_charge, $renewal_order );
253
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
254
+				$this->retry_subscription_payment($amount_to_charge, $renewal_order);
255 255
 			} else {
256 256
 				/* translators: error message */
257
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
257
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
258 258
 			}
259 259
 		}
260 260
 	}
@@ -263,20 +263,20 @@  discard block
 block discarded – undo
263 263
 	 * Remove order meta
264 264
 	 * @param  object $order
265 265
 	 */
266
-	public function remove_order_source_before_retry( $order ) {
266
+	public function remove_order_source_before_retry($order) {
267 267
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
268
-		delete_post_meta( $order_id, '_stripe_source_id' );
268
+		delete_post_meta($order_id, '_stripe_source_id');
269 269
 		// For BW compat will remove in the future.
270
-		delete_post_meta( $order_id, '_stripe_card_id' );
270
+		delete_post_meta($order_id, '_stripe_card_id');
271 271
 	}
272 272
 
273 273
 	/**
274 274
 	 * Remove order meta
275 275
 	 * @param object $order
276 276
 	 */
277
-	public function remove_order_customer_before_retry( $order ) {
277
+	public function remove_order_customer_before_retry($order) {
278 278
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
279
-		delete_post_meta( $order_id, '_stripe_customer_id' );
279
+		delete_post_meta($order_id, '_stripe_customer_id');
280 280
 	}
281 281
 
282 282
 	/**
@@ -288,14 +288,14 @@  discard block
 block discarded – undo
288 288
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
289 289
 	 * @return void
290 290
 	 */
291
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
292
-		if ( WC_Stripe_Helper::is_pre_30() ) {
293
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
294
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
291
+	public function update_failing_payment_method($subscription, $renewal_order) {
292
+		if (WC_Stripe_Helper::is_pre_30()) {
293
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
294
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
295 295
 
296 296
 		} else {
297
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
298
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
297
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
298
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
299 299
 		}
300 300
 	}
301 301
 
@@ -308,21 +308,21 @@  discard block
 block discarded – undo
308 308
 	 * @param WC_Subscription $subscription An instance of a subscription object
309 309
 	 * @return array
310 310
 	 */
311
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
312
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
311
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
312
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
313 313
 
314 314
 		// For BW compat will remove in future.
315
-		if ( empty( $source_id ) ) {
316
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
315
+		if (empty($source_id)) {
316
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
317 317
 
318 318
 			// Take this opportunity to update the key name.
319
-			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 );
319
+			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);
320 320
 		}
321 321
 
322
-		$payment_meta[ $this->id ] = array(
322
+		$payment_meta[$this->id] = array(
323 323
 			'post_meta' => array(
324 324
 				'_stripe_customer_id' => array(
325
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
325
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
326 326
 					'label' => 'Stripe Customer ID',
327 327
 				),
328 328
 				'_stripe_source_id' => array(
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
 	 * @param array $payment_meta associative array of meta data required for automatic payments
344 344
 	 * @return array
345 345
 	 */
346
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
347
-		if ( $this->id === $payment_method_id ) {
346
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
347
+		if ($this->id === $payment_method_id) {
348 348
 
349
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
350
-				throw new Exception( 'A "_stripe_customer_id" value is required.' );
351
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
352
-				throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' );
349
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
350
+				throw new Exception('A "_stripe_customer_id" value is required.');
351
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
352
+				throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".');
353 353
 			}
354 354
 
355
-			if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) {
356
-				throw new Exception( 'A "_stripe_source_id" value is required.' );
355
+			if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) {
356
+				throw new Exception('A "_stripe_source_id" value is required.');
357 357
 			}
358 358
 		}
359 359
 	}
@@ -366,89 +366,89 @@  discard block
 block discarded – undo
366 366
 	 * @param WC_Subscription $subscription the subscription details
367 367
 	 * @return string the subscription payment method
368 368
 	 */
369
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
369
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
370 370
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
371 371
 
372 372
 		// bail for other payment methods
373
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
373
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
374 374
 			return $payment_method_to_display;
375 375
 		}
376 376
 
377
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
377
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
378 378
 
379 379
 		// For BW compat will remove in future.
380
-		if ( empty( $stripe_source_id ) ) {
381
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
380
+		if (empty($stripe_source_id)) {
381
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
382 382
 
383 383
 			// Take this opportunity to update the key name.
384
-			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 );
384
+			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);
385 385
 		}
386 386
 
387 387
 		$stripe_customer    = new WC_Stripe_Customer();
388
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
388
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
389 389
 
390 390
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
391
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
391
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
392 392
 			$user_id            = $customer_user;
393
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
394
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
393
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
394
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
395 395
 
396 396
 			// For BW compat will remove in future.
397
-			if ( empty( $stripe_source_id ) ) {
398
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
397
+			if (empty($stripe_source_id)) {
398
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
399 399
 
400 400
 				// Take this opportunity to update the key name.
401
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
401
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
402 402
 			}
403 403
 		}
404 404
 
405 405
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
406
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
407
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
408
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
406
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
407
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
408
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
409 409
 
410 410
 			// For BW compat will remove in future.
411
-			if ( empty( $stripe_source_id ) ) {
412
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
411
+			if (empty($stripe_source_id)) {
412
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
413 413
 
414 414
 				// Take this opportunity to update the key name.
415
-				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 );
415
+				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);
416 416
 			}
417 417
 		}
418 418
 
419
-		$stripe_customer->set_id( $stripe_customer_id );
419
+		$stripe_customer->set_id($stripe_customer_id);
420 420
 		$sources = $stripe_customer->get_sources();
421 421
 
422
-		if ( $sources ) {
422
+		if ($sources) {
423 423
 			$found_source = false;
424
-			foreach ( $sources as $source ) {
425
-				if ( isset( $source->type ) && 'card' === $source->type ) {
424
+			foreach ($sources as $source) {
425
+				if (isset($source->type) && 'card' === $source->type) {
426 426
 					$card = $source->card;
427 427
 				}
428 428
 
429
-				if ( $source->id === $stripe_source_id ) {
429
+				if ($source->id === $stripe_source_id) {
430 430
 					$found_source = true;
431 431
 
432
-					if ( $card ) {
432
+					if ($card) {
433 433
 						/* translators: 1) card brand 2) last 4 digits */
434
-						$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 );
434
+						$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);
435 435
 					} else {
436
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
436
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
437 437
 					}
438 438
 					break;
439 439
 				}
440 440
 			}
441 441
 
442
-			if ( ! $found_source ) {
443
-				if ( 'card' === $sources[0]->type ) {
442
+			if ( ! $found_source) {
443
+				if ('card' === $sources[0]->type) {
444 444
 					$card = $sources[0]->card;
445 445
 				}
446 446
 
447
-				if ( $card ) {
447
+				if ($card) {
448 448
 					/* translators: 1) card brand 2) last 4 digits */
449
-					$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 );
449
+					$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);
450 450
 				} else {
451
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
451
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
452 452
 				}
453 453
 			}
454 454
 		}
@@ -461,43 +461,43 @@  discard block
 block discarded – undo
461 461
 	 * @param int $order_id
462 462
 	 * @return array
463 463
 	 */
464
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
465
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
464
+	public function process_pre_order($order_id, $retry, $force_save_source) {
465
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
466 466
 			try {
467
-				$order = wc_get_order( $order_id );
467
+				$order = wc_get_order($order_id);
468 468
 
469
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
469
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
470 470
 					/* translators: minimum amount */
471
-					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 ) ) );
471
+					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)));
472 472
 				}
473 473
 
474
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
474
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
475 475
 
476 476
 				// We need a source on file to continue.
477
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
478
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
477
+				if (empty($source->customer) || empty($source->source)) {
478
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
479 479
 				}
480 480
 
481 481
 				// Store source to order meta
482
-				$this->save_source( $order, $source );
482
+				$this->save_source($order, $source);
483 483
 
484 484
 				// Remove cart
485 485
 				WC()->cart->empty_cart();
486 486
 
487 487
 				// Is pre ordered!
488
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
488
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
489 489
 
490 490
 				// Return thank you page redirect
491 491
 				return array(
492 492
 					'result'   => 'success',
493
-					'redirect' => $this->get_return_url( $order ),
493
+					'redirect' => $this->get_return_url($order),
494 494
 				);
495
-			} catch ( Exception $e ) {
496
-				wc_add_notice( $e->getMessage(), 'error' );
495
+			} catch (Exception $e) {
496
+				wc_add_notice($e->getMessage(), 'error');
497 497
 				return;
498 498
 			}
499 499
 		} else {
500
-			return parent::process_payment( $order_id, $retry, $force_save_source );
500
+			return parent::process_payment($order_id, $retry, $force_save_source);
501 501
 		}
502 502
 	}
503 503
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 	 * @param WC_Order $order
507 507
 	 * @return void
508 508
 	 */
509
-	public function process_pre_order_release_payment( $order ) {
509
+	public function process_pre_order_release_payment($order) {
510 510
 		try {
511 511
 			// Define some callbacks if the first attempt fails.
512 512
 			$retry_callbacks = array(
@@ -514,33 +514,33 @@  discard block
 block discarded – undo
514 514
 				'remove_order_customer_before_retry',
515 515
 			);
516 516
 
517
-			while ( 1 ) {
518
-				$source   = $this->prepare_order_source( $order );
519
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
517
+			while (1) {
518
+				$source   = $this->prepare_order_source($order);
519
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
520 520
 
521
-				if ( ! empty( $response->error ) ) {
522
-					if ( 0 === sizeof( $retry_callbacks ) ) {
523
-						throw new Exception( $response->error->message );
521
+				if ( ! empty($response->error)) {
522
+					if (0 === sizeof($retry_callbacks)) {
523
+						throw new Exception($response->error->message);
524 524
 					} else {
525
-						$retry_callback = array_shift( $retry_callbacks );
526
-						call_user_func( array( $this, $retry_callback ), $order );
525
+						$retry_callback = array_shift($retry_callbacks);
526
+						call_user_func(array($this, $retry_callback), $order);
527 527
 					}
528 528
 				} else {
529 529
 					// Successful
530
-					$this->process_response( $response, $order );
530
+					$this->process_response($response, $order);
531 531
 					break;
532 532
 				}
533 533
 			}
534
-		} catch ( Exception $e ) {
534
+		} catch (Exception $e) {
535 535
 			/* translators: error message */
536
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
536
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
537 537
 
538 538
 			// Mark order as failed if not already set,
539 539
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
540
-			if ( ! $order->has_status( 'failed' ) ) {
541
-				$order->update_status( 'failed', $order_note );
540
+			if ( ! $order->has_status('failed')) {
541
+				$order->update_status('failed', $order_note);
542 542
 			} else {
543
-				$order->add_order_note( $order_note );
543
+				$order->add_order_note($order_note);
544 544
 			}
545 545
 		}
546 546
 	}
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +274 added lines, -274 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,39 +56,39 @@  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
 
91
-		add_action( 'woocommerce_init', array( $this, 'init' ), 100 );
91
+		add_action('woocommerce_init', array($this, 'init'), 100);
92 92
 	}
93 93
 
94 94
 	/**
@@ -98,40 +98,40 @@  discard block
 block discarded – undo
98 98
 	 * @version 4.0.0
99 99
 	 */
100 100
 	public function init() {
101
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
101
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
102 102
 
103 103
 		/*
104 104
 		 * In order to display the Payment Request button in the correct position,
105 105
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
106 106
 		 * CSS is used to position the button.
107 107
 		 */
108
-		if ( WC_Stripe_Helper::is_pre_30() ) {
109
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
110
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
108
+		if (WC_Stripe_Helper::is_pre_30()) {
109
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
110
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
111 111
 		} else {
112
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
113
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
112
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
113
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
114 114
 		}
115 115
 
116
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
117
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
116
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
117
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
118 118
 
119
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
120
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
119
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
120
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
121 121
 
122
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
123
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
124
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
125
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
126
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
127
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
128
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
129
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
122
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
123
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
124
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
125
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
126
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
127
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
128
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
129
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
130 130
 
131
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
132
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
131
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
132
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
133 133
 
134
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 );
134
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3);
135 135
 	}
136 136
 
137 137
 	/**
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * @return string
143 143
 	 */
144 144
 	public function get_button_type() {
145
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
145
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
146 146
 	}
147 147
 
148 148
 	/**
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return string
154 154
 	 */
155 155
 	public function get_button_theme() {
156
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
156
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
157 157
 	}
158 158
 
159 159
 	/**
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @return string
165 165
 	 */
166 166
 	public function get_button_height() {
167
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
167
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
168 168
 	}
169 169
 
170 170
 	/**
@@ -174,40 +174,40 @@  discard block
 block discarded – undo
174 174
 	 * @version 4.0.0
175 175
 	 */
176 176
 	public function get_product_data() {
177
-		if ( ! is_product() ) {
177
+		if ( ! is_product()) {
178 178
 			return false;
179 179
 		}
180 180
 
181 181
 		global $post;
182 182
 
183
-		$product = wc_get_product( $post->ID );
183
+		$product = wc_get_product($post->ID);
184 184
 
185 185
 		$data  = array();
186 186
 		$items = array();
187 187
 
188 188
 		$items[] = array(
189 189
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
190
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
190
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
191 191
 		);
192 192
 
193
-		if ( wc_tax_enabled() ) {
193
+		if (wc_tax_enabled()) {
194 194
 			$items[] = array(
195
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
195
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
196 196
 				'amount'  => 0,
197 197
 				'pending' => true,
198 198
 			);
199 199
 		}
200 200
 
201
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
201
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
202 202
 			$items[] = array(
203
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
203
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
204 204
 				'amount'  => 0,
205 205
 				'pending' => true,
206 206
 			);
207 207
 
208
-			$data['shippingOptions']  = array(
208
+			$data['shippingOptions'] = array(
209 209
 				'id'     => 'pending',
210
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
210
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
211 211
 				'detail' => '',
212 212
 				'amount' => 0,
213 213
 			);
@@ -215,41 +215,41 @@  discard block
 block discarded – undo
215 215
 
216 216
 		$data['displayItems'] = $items;
217 217
 		$data['total'] = array(
218
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
219
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
218
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
219
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
220 220
 			'pending' => true,
221 221
 		);
222 222
 
223
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
224
-		$data['currency']        = strtolower( get_woocommerce_currency() );
225
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
223
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
224
+		$data['currency']        = strtolower(get_woocommerce_currency());
225
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
226 226
 
227
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
227
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
228 228
 	}
229 229
 
230 230
 	/**
231 231
 	 * Filters the gateway title to reflect Payment Request type
232 232
 	 *
233 233
 	 */
234
-	public function filter_gateway_title( $title, $id ) {
234
+	public function filter_gateway_title($title, $id) {
235 235
 		global $post;
236 236
 
237
-		if ( ! is_object( $post ) ) {
237
+		if ( ! is_object($post)) {
238 238
 			return $title;
239 239
 		}
240 240
 
241
-		if ( WC_Stripe_Helper::is_pre_30() ) {
242
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
241
+		if (WC_Stripe_Helper::is_pre_30()) {
242
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
243 243
 		} else {
244
-			$order        = wc_get_order( $post->ID );
245
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
244
+			$order        = wc_get_order($post->ID);
245
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
246 246
 		}
247 247
 
248
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
248
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
249 249
 			return $method_title;
250 250
 		}
251 251
 
252
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
252
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
253 253
 			return $method_title;
254 254
 		}
255 255
 
@@ -262,16 +262,16 @@  discard block
 block discarded – undo
262 262
 	 * @since 3.1.4
263 263
 	 * @version 4.0.0
264 264
 	 */
265
-	public function postal_code_validation( $valid, $postcode, $country ) {
265
+	public function postal_code_validation($valid, $postcode, $country) {
266 266
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
267 267
 
268
-		if ( ! isset( $gateways['stripe'] ) ) {
268
+		if ( ! isset($gateways['stripe'])) {
269 269
 			return $valid;
270 270
 		}
271 271
 
272
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
272
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
273 273
 
274
-		if ( 'apple_pay' !== $payment_request_type ) {
274
+		if ('apple_pay' !== $payment_request_type) {
275 275
 			return $valid;
276 276
 		}
277 277
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
282 282
 		 * Note that this only works with shipping providers that don't validate full postal codes.
283 283
 		 */
284
-		if ( 'GB' === $country || 'CA' === $country ) {
284
+		if ('GB' === $country || 'CA' === $country) {
285 285
 			return true;
286 286
 		}
287 287
 
@@ -297,27 +297,27 @@  discard block
 block discarded – undo
297 297
 	 * @param array $posted_data The posted data from checkout form.
298 298
 	 * @param object $order
299 299
 	 */
300
-	public function add_order_meta( $order_id, $posted_data, $order ) {
301
-		if ( empty( $_POST['payment_request_type'] ) ) {
300
+	public function add_order_meta($order_id, $posted_data, $order) {
301
+		if (empty($_POST['payment_request_type'])) {
302 302
 			return;
303 303
 		}
304 304
 
305
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
305
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
306 306
 
307
-		if ( 'apple_pay' === $payment_request_type ) {
308
-			if ( WC_Stripe_Helper::is_pre_30() ) {
309
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
307
+		if ('apple_pay' === $payment_request_type) {
308
+			if (WC_Stripe_Helper::is_pre_30()) {
309
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
310 310
 			} else {
311
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
311
+				$order->set_payment_method_title('Apple Pay (Stripe)');
312 312
 				$order->save();
313 313
 			}
314 314
 		}
315 315
 
316
-		if ( 'payment_request_api' === $payment_request_type ) {
317
-			if ( WC_Stripe_Helper::is_pre_30() ) {
318
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
316
+		if ('payment_request_api' === $payment_request_type) {
317
+			if (WC_Stripe_Helper::is_pre_30()) {
318
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
319 319
 			} else {
320
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
320
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
321 321
 				$order->save();
322 322
 			}
323 323
 		}
@@ -331,11 +331,11 @@  discard block
 block discarded – undo
331 331
 	 * @return array
332 332
 	 */
333 333
 	public function supported_product_types() {
334
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
334
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
335 335
 			'simple',
336 336
 			'variable',
337 337
 			'variation',
338
-		) );
338
+		));
339 339
 	}
340 340
 
341 341
 	/**
@@ -346,15 +346,15 @@  discard block
 block discarded – undo
346 346
 	 * @return bool
347 347
 	 */
348 348
 	public function allowed_items_in_cart() {
349
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
350
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
349
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
350
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
351 351
 
352
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
352
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
353 353
 				return false;
354 354
 			}
355 355
 
356 356
 			// Pre Orders compatbility where we don't support charge upon release.
357
-			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() ) ) {
357
+			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())) {
358 358
 				return false;
359 359
 			}
360 360
 		}
@@ -369,71 +369,71 @@  discard block
 block discarded – undo
369 369
 	 * @version 4.0.0
370 370
 	 */
371 371
 	public function scripts() {
372
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
372
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
373 373
 			return;
374 374
 		}
375 375
 
376
-		if ( is_product() ) {
376
+		if (is_product()) {
377 377
 			global $post;
378 378
 
379
-			$product = wc_get_product( $post->ID );
379
+			$product = wc_get_product($post->ID);
380 380
 
381
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
381
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
382 382
 				return;
383 383
 			}
384 384
 
385
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
385
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
386 386
 				return;
387 387
 			}
388 388
 		}
389 389
 
390
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
390
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
391 391
 
392
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
393
-		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 );
392
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
393
+		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);
394 394
 
395 395
 		wp_localize_script(
396 396
 			'wc_stripe_payment_request',
397 397
 			'wc_stripe_payment_request_params',
398 398
 			array(
399
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
399
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
400 400
 				'stripe'   => array(
401 401
 					'key'                => $this->publishable_key,
402
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
402
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
403 403
 				),
404 404
 				'nonce'    => array(
405
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
406
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
407
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
408
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
409
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
410
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
411
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
412
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
405
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
406
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
407
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
408
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
409
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
410
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
411
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
412
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
413 413
 				),
414 414
 				'i18n'     => array(
415
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
415
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
416 416
 					/* translators: Do not translate the [option] placeholder */
417
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
417
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
418 418
 				),
419 419
 				'checkout' => array(
420 420
 					'url'            => wc_get_checkout_url(),
421
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
422
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
421
+					'currency_code'  => strtolower(get_woocommerce_currency()),
422
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
423 423
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
424 424
 				),
425 425
 				'button' => array(
426 426
 					'type'   => $this->get_button_type(),
427 427
 					'theme'  => $this->get_button_theme(),
428 428
 					'height' => $this->get_button_height(),
429
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
429
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
430 430
 				),
431 431
 				'is_product_page' => is_product(),
432 432
 				'product'         => $this->get_product_data(),
433 433
 			)
434 434
 		);
435 435
 
436
-		wp_enqueue_script( 'wc_stripe_payment_request' );
436
+		wp_enqueue_script('wc_stripe_payment_request');
437 437
 	}
438 438
 
439 439
 	/**
@@ -445,39 +445,39 @@  discard block
 block discarded – undo
445 445
 	public function display_payment_request_button_html() {
446 446
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
447 447
 
448
-		if ( ! isset( $gateways['stripe'] ) ) {
448
+		if ( ! isset($gateways['stripe'])) {
449 449
 			return;
450 450
 		}
451 451
 
452
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
452
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
453 453
 			return;
454 454
 		}
455 455
 
456
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
456
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
457 457
 			return;
458 458
 		}
459 459
 
460
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
460
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
461 461
 			return;
462 462
 		}
463 463
 
464
-		if ( is_product() ) {
464
+		if (is_product()) {
465 465
 			global $post;
466 466
 
467
-			$product = wc_get_product( $post->ID );
467
+			$product = wc_get_product($post->ID);
468 468
 
469
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
469
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
470 470
 				return;
471 471
 			}
472 472
 
473 473
 			// Pre Orders charge upon release not supported.
474
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
475
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
474
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
475
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
476 476
 				return;
477 477
 			}
478 478
 		} else {
479
-			if ( ! $this->allowed_items_in_cart() ) {
480
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
479
+			if ( ! $this->allowed_items_in_cart()) {
480
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
481 481
 				return;
482 482
 			}
483 483
 		}
@@ -499,44 +499,44 @@  discard block
 block discarded – undo
499 499
 	public function display_payment_request_button_separator_html() {
500 500
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
501 501
 
502
-		if ( ! isset( $gateways['stripe'] ) ) {
502
+		if ( ! isset($gateways['stripe'])) {
503 503
 			return;
504 504
 		}
505 505
 
506
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
506
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
507 507
 			return;
508 508
 		}
509 509
 
510
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
510
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
511 511
 			return;
512 512
 		}
513 513
 
514
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
514
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
515 515
 			return;
516 516
 		}
517 517
 
518
-		if ( is_product() ) {
518
+		if (is_product()) {
519 519
 			global $post;
520 520
 
521
-			$product = wc_get_product( $post->ID );
521
+			$product = wc_get_product($post->ID);
522 522
 
523
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
523
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
524 524
 				return;
525 525
 			}
526 526
 
527 527
 			// Pre Orders charge upon release not supported.
528
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
529
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
528
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
529
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
530 530
 				return;
531 531
 			}
532 532
 		} else {
533
-			if ( ! $this->allowed_items_in_cart() ) {
534
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
533
+			if ( ! $this->allowed_items_in_cart()) {
534
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
535 535
 				return;
536 536
 			}
537 537
 		}
538 538
 		?>
539
-		<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>
539
+		<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>
540 540
 		<?php
541 541
 	}
542 542
 
@@ -547,11 +547,11 @@  discard block
 block discarded – undo
547 547
 	 * @version 4.0.0
548 548
 	 */
549 549
 	public function ajax_log_errors() {
550
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
550
+		check_ajax_referer('wc-stripe-log-errors', 'security');
551 551
 
552
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
552
+		$errors = wc_clean(stripslashes($_POST['errors']));
553 553
 
554
-		WC_Stripe_Logger::log( $errors );
554
+		WC_Stripe_Logger::log($errors);
555 555
 
556 556
 		exit;
557 557
 	}
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 	 * @version 4.0.0
564 564
 	 */
565 565
 	public function ajax_clear_cart() {
566
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
566
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
567 567
 
568 568
 		WC()->cart->empty_cart();
569 569
 		exit;
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
 	 * Get cart details.
574 574
 	 */
575 575
 	public function ajax_get_cart_details() {
576
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
576
+		check_ajax_referer('wc-stripe-payment-request', 'security');
577 577
 
578
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
579
-			define( 'WOOCOMMERCE_CART', true );
578
+		if ( ! defined('WOOCOMMERCE_CART')) {
579
+			define('WOOCOMMERCE_CART', true);
580 580
 		}
581 581
 
582 582
 		WC()->cart->calculate_totals();
@@ -587,14 +587,14 @@  discard block
 block discarded – undo
587 587
 		$data = array(
588 588
 			'shipping_required' => WC()->cart->needs_shipping(),
589 589
 			'order_data'        => array(
590
-				'currency'        => strtolower( $currency ),
591
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
590
+				'currency'        => strtolower($currency),
591
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
592 592
 			),
593 593
 		);
594 594
 
595 595
 		$data['order_data'] += $this->build_display_items();
596 596
 
597
-		wp_send_json( $data );
597
+		wp_send_json($data);
598 598
 	}
599 599
 
600 600
 	/**
@@ -605,47 +605,47 @@  discard block
 block discarded – undo
605 605
 	 * @see WC_Shipping::get_packages().
606 606
 	 */
607 607
 	public function ajax_get_shipping_options() {
608
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
608
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
609 609
 
610 610
 		try {
611 611
 			// Set the shipping package.
612
-			$posted = filter_input_array( INPUT_POST, array(
612
+			$posted = filter_input_array(INPUT_POST, array(
613 613
 				'country'   => FILTER_SANITIZE_STRING,
614 614
 				'state'     => FILTER_SANITIZE_STRING,
615 615
 				'postcode'  => FILTER_SANITIZE_STRING,
616 616
 				'city'      => FILTER_SANITIZE_STRING,
617 617
 				'address'   => FILTER_SANITIZE_STRING,
618 618
 				'address_2' => FILTER_SANITIZE_STRING,
619
-			) );
619
+			));
620 620
 
621
-			$this->calculate_shipping( $posted );
621
+			$this->calculate_shipping($posted);
622 622
 
623 623
 			// Set the shipping options.
624 624
 			$data     = array();
625 625
 			$packages = WC()->shipping->get_packages();
626 626
 
627
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
628
-				foreach ( $packages as $package_key => $package ) {
629
-					if ( empty( $package['rates'] ) ) {
630
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
627
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
628
+				foreach ($packages as $package_key => $package) {
629
+					if (empty($package['rates'])) {
630
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
631 631
 					}
632 632
 
633
-					foreach ( $package['rates'] as $key => $rate ) {
633
+					foreach ($package['rates'] as $key => $rate) {
634 634
 						$data['shipping_options'][] = array(
635 635
 							'id'       => $rate->id,
636 636
 							'label'    => $rate->label,
637 637
 							'detail'   => '',
638
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
638
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
639 639
 						);
640 640
 					}
641 641
 				}
642 642
 			} else {
643
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
643
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
644 644
 			}
645 645
 
646
-			if ( isset( $data[0] ) ) {
646
+			if (isset($data[0])) {
647 647
 				// Auto select the first shipping method.
648
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
648
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
649 649
 			}
650 650
 
651 651
 			WC()->cart->calculate_totals();
@@ -653,12 +653,12 @@  discard block
 block discarded – undo
653 653
 			$data += $this->build_display_items();
654 654
 			$data['result'] = 'success';
655 655
 
656
-			wp_send_json( $data );
657
-		} catch ( Exception $e ) {
656
+			wp_send_json($data);
657
+		} catch (Exception $e) {
658 658
 			$data += $this->build_display_items();
659 659
 			$data['result'] = 'invalid_shipping_address';
660 660
 
661
-			wp_send_json( $data );
661
+			wp_send_json($data);
662 662
 		}
663 663
 	}
664 664
 
@@ -666,22 +666,22 @@  discard block
 block discarded – undo
666 666
 	 * Update shipping method.
667 667
 	 */
668 668
 	public function ajax_update_shipping_method() {
669
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
669
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
670 670
 
671
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
672
-			define( 'WOOCOMMERCE_CART', true );
671
+		if ( ! defined('WOOCOMMERCE_CART')) {
672
+			define('WOOCOMMERCE_CART', true);
673 673
 		}
674 674
 
675
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
676
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
675
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
676
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
677 677
 
678
-		if ( is_array( $shipping_method ) ) {
679
-			foreach ( $shipping_method as $i => $value ) {
680
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
678
+		if (is_array($shipping_method)) {
679
+			foreach ($shipping_method as $i => $value) {
680
+				$chosen_shipping_methods[$i] = wc_clean($value);
681 681
 			}
682 682
 		}
683 683
 
684
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
684
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
685 685
 
686 686
 		WC()->cart->calculate_totals();
687 687
 
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 		$data += $this->build_display_items();
690 690
 		$data['result'] = 'success';
691 691
 
692
-		wp_send_json( $data );
692
+		wp_send_json($data);
693 693
 	}
694 694
 
695 695
 	/**
@@ -700,31 +700,31 @@  discard block
 block discarded – undo
700 700
 	 * @return array $data
701 701
 	 */
702 702
 	public function ajax_get_selected_product_data() {
703
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
703
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
704 704
 
705
-		$product_id = absint( $_POST['product_id'] );
706
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
705
+		$product_id = absint($_POST['product_id']);
706
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
707 707
 
708
-		$product = wc_get_product( $product_id );
708
+		$product = wc_get_product($product_id);
709 709
 
710
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
711
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
710
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
711
+			$attributes = array_map('wc_clean', $_POST['attributes']);
712 712
 
713
-			if ( WC_Stripe_Helper::is_pre_30() ) {
714
-				$variation_id = $product->get_matching_variation( $attributes );
713
+			if (WC_Stripe_Helper::is_pre_30()) {
714
+				$variation_id = $product->get_matching_variation($attributes);
715 715
 			} else {
716
-				$data_store = WC_Data_Store::load( 'product' );
717
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
716
+				$data_store = WC_Data_Store::load('product');
717
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
718 718
 			}
719 719
 
720
-			if ( ! empty( $variation_id ) ) {
721
-				$product = wc_get_product( $variation_id );
720
+			if ( ! empty($variation_id)) {
721
+				$product = wc_get_product($variation_id);
722 722
 			}
723
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
724
-			$product = wc_get_product( $product_id );
723
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
724
+			$product = wc_get_product($product_id);
725 725
 		}
726 726
 
727
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
727
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
728 728
 
729 729
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
730 730
 
@@ -732,28 +732,28 @@  discard block
 block discarded – undo
732 732
 		$items = array();
733 733
 
734 734
 		$items[] = array(
735
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
736
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
735
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
736
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
737 737
 		);
738 738
 
739
-		if ( wc_tax_enabled() ) {
739
+		if (wc_tax_enabled()) {
740 740
 			$items[] = array(
741
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
741
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
742 742
 				'amount'  => 0,
743 743
 				'pending' => true,
744 744
 			);
745 745
 		}
746 746
 
747
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
747
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
748 748
 			$items[] = array(
749
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
749
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
750 750
 				'amount'  => 0,
751 751
 				'pending' => true,
752 752
 			);
753 753
 
754
-			$data['shippingOptions']  = array(
754
+			$data['shippingOptions'] = array(
755 755
 				'id'     => 'pending',
756
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
756
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
757 757
 				'detail' => '',
758 758
 				'amount' => 0,
759 759
 			);
@@ -762,15 +762,15 @@  discard block
 block discarded – undo
762 762
 		$data['displayItems'] = $items;
763 763
 		$data['total'] = array(
764 764
 			'label'   => $this->total_label,
765
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
765
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
766 766
 			'pending' => true,
767 767
 		);
768 768
 
769
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
770
-		$data['currency']        = strtolower( get_woocommerce_currency() );
771
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
769
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
770
+		$data['currency']        = strtolower(get_woocommerce_currency());
771
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
772 772
 
773
-		wp_send_json( $data );
773
+		wp_send_json($data);
774 774
 	}
775 775
 
776 776
 	/**
@@ -781,37 +781,37 @@  discard block
 block discarded – undo
781 781
 	 * @return array $data
782 782
 	 */
783 783
 	public function ajax_add_to_cart() {
784
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
784
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
785 785
 
786
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
787
-			define( 'WOOCOMMERCE_CART', true );
786
+		if ( ! defined('WOOCOMMERCE_CART')) {
787
+			define('WOOCOMMERCE_CART', true);
788 788
 		}
789 789
 
790 790
 		WC()->shipping->reset_shipping();
791 791
 
792
-		$product_id = absint( $_POST['product_id'] );
793
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
792
+		$product_id = absint($_POST['product_id']);
793
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
794 794
 
795
-		$product = wc_get_product( $product_id );
795
+		$product = wc_get_product($product_id);
796 796
 
797 797
 		// First empty the cart to prevent wrong calculation.
798 798
 		WC()->cart->empty_cart();
799 799
 
800
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
801
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
800
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
801
+			$attributes = array_map('wc_clean', $_POST['attributes']);
802 802
 
803
-			if ( WC_Stripe_Helper::is_pre_30() ) {
804
-				$variation_id = $product->get_matching_variation( $attributes );
803
+			if (WC_Stripe_Helper::is_pre_30()) {
804
+				$variation_id = $product->get_matching_variation($attributes);
805 805
 			} else {
806
-				$data_store = WC_Data_Store::load( 'product' );
807
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
806
+				$data_store = WC_Data_Store::load('product');
807
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
808 808
 			}
809 809
 
810
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
810
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
811 811
 		}
812 812
 
813
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
814
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
813
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
814
+			WC()->cart->add_to_cart($product->get_id(), $qty);
815 815
 		}
816 816
 
817 817
 		WC()->cart->calculate_totals();
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 		$data += $this->build_display_items();
821 821
 		$data['result'] = 'success';
822 822
 
823
-		wp_send_json( $data );
823
+		wp_send_json($data);
824 824
 	}
825 825
 
826 826
 	/**
@@ -833,31 +833,31 @@  discard block
 block discarded – undo
833 833
 	 * @version 4.0.0
834 834
 	 */
835 835
 	public function normalize_state() {
836
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
837
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
838
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
839
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
836
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
837
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
838
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
839
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
840 840
 
841
-		if ( $billing_state && $billing_country ) {
842
-			$valid_states = WC()->countries->get_states( $billing_country );
841
+		if ($billing_state && $billing_country) {
842
+			$valid_states = WC()->countries->get_states($billing_country);
843 843
 
844 844
 			// Valid states found for country.
845
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
846
-				foreach ( $valid_states as $state_abbr => $state ) {
847
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
845
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
846
+				foreach ($valid_states as $state_abbr => $state) {
847
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
848 848
 						$_POST['billing_state'] = $state_abbr;
849 849
 					}
850 850
 				}
851 851
 			}
852 852
 		}
853 853
 
854
-		if ( $shipping_state && $shipping_country ) {
855
-			$valid_states = WC()->countries->get_states( $shipping_country );
854
+		if ($shipping_state && $shipping_country) {
855
+			$valid_states = WC()->countries->get_states($shipping_country);
856 856
 
857 857
 			// Valid states found for country.
858
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
859
-				foreach ( $valid_states as $state_abbr => $state ) {
860
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
858
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
859
+				foreach ($valid_states as $state_abbr => $state) {
860
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
861 861
 						$_POST['shipping_state'] = $state_abbr;
862 862
 					}
863 863
 				}
@@ -872,19 +872,19 @@  discard block
 block discarded – undo
872 872
 	 * @version 4.0.0
873 873
 	 */
874 874
 	public function ajax_create_order() {
875
-		if ( WC()->cart->is_empty() ) {
876
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
875
+		if (WC()->cart->is_empty()) {
876
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
877 877
 		}
878 878
 
879
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
880
-			define( 'WOOCOMMERCE_CHECKOUT', true );
879
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
880
+			define('WOOCOMMERCE_CHECKOUT', true);
881 881
 		}
882 882
 
883 883
 		$this->normalize_state();
884 884
 
885 885
 		WC()->checkout()->process_checkout();
886 886
 
887
-		die( 0 );
887
+		die(0);
888 888
 	}
889 889
 
890 890
 	/**
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 	 * @version 4.0.0
895 895
 	 * @param array $address
896 896
 	 */
897
-	protected function calculate_shipping( $address = array() ) {
897
+	protected function calculate_shipping($address = array()) {
898 898
 		global $states;
899 899
 
900 900
 		$country   = $address['country'];
@@ -911,28 +911,28 @@  discard block
 block discarded – undo
911 911
 		 * In some versions of Chrome, state can be a full name. So we need
912 912
 		 * to convert that to abbreviation as WC is expecting that.
913 913
 		 */
914
-		if ( 2 < strlen( $state ) ) {
915
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
914
+		if (2 < strlen($state)) {
915
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
916 916
 		}
917 917
 
918 918
 		WC()->shipping->reset_shipping();
919 919
 
920
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
921
-			$postcode = wc_format_postcode( $postcode, $country );
920
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
921
+			$postcode = wc_format_postcode($postcode, $country);
922 922
 		}
923 923
 
924
-		if ( $country ) {
925
-			WC()->customer->set_location( $country, $state, $postcode, $city );
926
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
924
+		if ($country) {
925
+			WC()->customer->set_location($country, $state, $postcode, $city);
926
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
927 927
 		} else {
928 928
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
929 929
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
930 930
 		}
931 931
 
932
-		if ( WC_Stripe_Helper::is_pre_30() ) {
933
-			WC()->customer->calculated_shipping( true );
932
+		if (WC_Stripe_Helper::is_pre_30()) {
933
+			WC()->customer->calculated_shipping(true);
934 934
 		} else {
935
-			WC()->customer->set_calculated_shipping( true );
935
+			WC()->customer->set_calculated_shipping(true);
936 936
 			WC()->customer->save();
937 937
 		}
938 938
 
@@ -949,17 +949,17 @@  discard block
 block discarded – undo
949 949
 		$packages[0]['destination']['address']   = $address_1;
950 950
 		$packages[0]['destination']['address_2'] = $address_2;
951 951
 
952
-		foreach ( WC()->cart->get_cart() as $item ) {
953
-			if ( $item['data']->needs_shipping() ) {
954
-				if ( isset( $item['line_total'] ) ) {
952
+		foreach (WC()->cart->get_cart() as $item) {
953
+			if ($item['data']->needs_shipping()) {
954
+				if (isset($item['line_total'])) {
955 955
 					$packages[0]['contents_cost'] += $item['line_total'];
956 956
 				}
957 957
 			}
958 958
 		}
959 959
 
960
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
960
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
961 961
 
962
-		WC()->shipping->calculate_shipping( $packages );
962
+		WC()->shipping->calculate_shipping($packages);
963 963
 	}
964 964
 
965 965
 	/**
@@ -968,19 +968,19 @@  discard block
 block discarded – undo
968 968
 	 * @since 3.1.0
969 969
 	 * @version 4.0.0
970 970
 	 */
971
-	protected function build_shipping_methods( $shipping_methods ) {
972
-		if ( empty( $shipping_methods ) ) {
971
+	protected function build_shipping_methods($shipping_methods) {
972
+		if (empty($shipping_methods)) {
973 973
 			return array();
974 974
 		}
975 975
 
976 976
 		$shipping = array();
977 977
 
978
-		foreach ( $shipping_methods as $method ) {
978
+		foreach ($shipping_methods as $method) {
979 979
 			$shipping[] = array(
980 980
 				'id'         => $method['id'],
981 981
 				'label'      => $method['label'],
982 982
 				'detail'     => '',
983
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
983
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
984 984
 			);
985 985
 		}
986 986
 
@@ -994,69 +994,69 @@  discard block
 block discarded – undo
994 994
 	 * @version 4.0.0
995 995
 	 */
996 996
 	protected function build_display_items() {
997
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
998
-			define( 'WOOCOMMERCE_CART', true );
997
+		if ( ! defined('WOOCOMMERCE_CART')) {
998
+			define('WOOCOMMERCE_CART', true);
999 999
 		}
1000 1000
 
1001 1001
 		$items    = array();
1002 1002
 		$subtotal = 0;
1003 1003
 
1004 1004
 		// Default show only subtotal instead of itemization.
1005
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1006
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1005
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1006
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1007 1007
 				$amount         = $cart_item['line_subtotal'];
1008
-				$subtotal       += $cart_item['line_subtotal'];
1008
+				$subtotal += $cart_item['line_subtotal'];
1009 1009
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1010 1010
 
1011 1011
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1012 1012
 
1013 1013
 				$item = array(
1014 1014
 					'label'  => $product_name . $quantity_label,
1015
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1015
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1016 1016
 				);
1017 1017
 
1018 1018
 				$items[] = $item;
1019 1019
 			}
1020 1020
 		}
1021 1021
 
1022
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1023
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1024
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1025
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1026
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1022
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1023
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1024
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1025
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1026
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1027 1027
 
1028
-		if ( wc_tax_enabled() ) {
1028
+		if (wc_tax_enabled()) {
1029 1029
 			$items[] = array(
1030
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1031
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1030
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1031
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1032 1032
 			);
1033 1033
 		}
1034 1034
 
1035
-		if ( WC()->cart->needs_shipping() ) {
1035
+		if (WC()->cart->needs_shipping()) {
1036 1036
 			$items[] = array(
1037
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1038
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1037
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1038
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1039 1039
 			);
1040 1040
 		}
1041 1041
 
1042
-		if ( WC()->cart->has_discount() ) {
1042
+		if (WC()->cart->has_discount()) {
1043 1043
 			$items[] = array(
1044
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1045
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1044
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1045
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1046 1046
 			);
1047 1047
 		}
1048 1048
 
1049
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1049
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1050 1050
 			$cart_fees = WC()->cart->fees;
1051 1051
 		} else {
1052 1052
 			$cart_fees = WC()->cart->get_fees();
1053 1053
 		}
1054 1054
 
1055 1055
 		// Include fees and taxes as display items.
1056
-		foreach ( $cart_fees as $key => $fee ) {
1056
+		foreach ($cart_fees as $key => $fee) {
1057 1057
 			$items[] = array(
1058 1058
 				'label'  => $fee->name,
1059
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1059
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1060 1060
 			);
1061 1061
 		}
1062 1062
 
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 			'displayItems' => $items,
1065 1065
 			'total'      => array(
1066 1066
 				'label'   => $this->total_label,
1067
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1067
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1068 1068
 				'pending' => false,
1069 1069
 			),
1070 1070
 		);
Please login to merge, or discard this patch.