Completed
Push — master ( 129907...e3a5fe )
by Roy
02:04
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +179 added lines, -179 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
 
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 	public function __construct() {
114 114
 		$this->retry_interval       = 1;
115 115
 		$this->id                   = 'stripe';
116
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
116
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
117 117
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
118
-		$this->method_description   = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
118
+		$this->method_description   = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
119 119
 		$this->has_fields           = true;
120 120
 		$this->supports             = array(
121 121
 			'products',
@@ -142,33 +142,33 @@  discard block
 block discarded – undo
142 142
 		$this->init_settings();
143 143
 
144 144
 		// Get setting values.
145
-		$this->title                       = $this->get_option( 'title' );
146
-		$this->description                 = $this->get_option( 'description' );
147
-		$this->enabled                     = $this->get_option( 'enabled' );
148
-		$this->testmode                    = 'yes' === $this->get_option( 'testmode' );
149
-		$this->inline_cc_form              = 'yes' === $this->get_option( 'inline_cc_form' );
150
-		$this->capture                     = 'yes' === $this->get_option( 'capture', 'yes' );
151
-		$this->statement_descriptor        = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
152
-		$this->three_d_secure              = 'yes' === $this->get_option( 'three_d_secure' );
153
-		$this->stripe_checkout             = 'yes' === $this->get_option( 'stripe_checkout' );
154
-		$this->stripe_checkout_image       = $this->get_option( 'stripe_checkout_image', '' );
155
-		$this->stripe_checkout_description = $this->get_option( 'stripe_checkout_description' );
156
-		$this->saved_cards                 = 'yes' === $this->get_option( 'saved_cards' );
157
-		$this->secret_key                  = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
158
-		$this->publishable_key             = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
159
-		$this->bitcoin                     = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
160
-		$this->payment_request             = 'yes' === $this->get_option( 'payment_request', 'yes' );
161
-
162
-		if ( $this->stripe_checkout ) {
163
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
145
+		$this->title                       = $this->get_option('title');
146
+		$this->description                 = $this->get_option('description');
147
+		$this->enabled                     = $this->get_option('enabled');
148
+		$this->testmode                    = 'yes' === $this->get_option('testmode');
149
+		$this->inline_cc_form              = 'yes' === $this->get_option('inline_cc_form');
150
+		$this->capture                     = 'yes' === $this->get_option('capture', 'yes');
151
+		$this->statement_descriptor        = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
152
+		$this->three_d_secure              = 'yes' === $this->get_option('three_d_secure');
153
+		$this->stripe_checkout             = 'yes' === $this->get_option('stripe_checkout');
154
+		$this->stripe_checkout_image       = $this->get_option('stripe_checkout_image', '');
155
+		$this->stripe_checkout_description = $this->get_option('stripe_checkout_description');
156
+		$this->saved_cards                 = 'yes' === $this->get_option('saved_cards');
157
+		$this->secret_key                  = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
158
+		$this->publishable_key             = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
159
+		$this->bitcoin                     = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
160
+		$this->payment_request             = 'yes' === $this->get_option('payment_request', 'yes');
161
+
162
+		if ($this->stripe_checkout) {
163
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
164 164
 		}
165 165
 
166
-		WC_Stripe_API::set_secret_key( $this->secret_key );
166
+		WC_Stripe_API::set_secret_key($this->secret_key);
167 167
 
168 168
 		// Hooks.
169
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
170
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
171
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
169
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
170
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
171
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
172 172
 	}
173 173
 
174 174
 	/**
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @return bool
179 179
 	 */
180 180
 	public function are_keys_set() {
181
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
181
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
182 182
 			return false;
183 183
 		}
184 184
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 * @since 4.0.2
192 192
 	 */
193 193
 	public function is_available() {
194
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
194
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
195 195
 			return false;
196 196
 		}
197 197
 
@@ -214,24 +214,24 @@  discard block
 block discarded – undo
214 214
 		$icons_str .= $icons['amex'];
215 215
 		$icons_str .= $icons['mastercard'];
216 216
 
217
-		if ( 'USD' === get_woocommerce_currency() ) {
217
+		if ('USD' === get_woocommerce_currency()) {
218 218
 			$icons_str .= $icons['discover'];
219 219
 			$icons_str .= $icons['jcb'];
220 220
 			$icons_str .= $icons['diners'];
221 221
 		}
222 222
 
223
-		if ( $this->bitcoin && $this->stripe_checkout ) {
223
+		if ($this->bitcoin && $this->stripe_checkout) {
224 224
 			$icons_str .= $icons['bitcoin'];
225 225
 		}
226 226
 
227
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
227
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
228 228
 	}
229 229
 
230 230
 	/**
231 231
 	 * Initialise Gateway Settings Form Fields
232 232
 	 */
233 233
 	public function init_form_fields() {
234
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
234
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
235 235
 	}
236 236
 
237 237
 	/**
@@ -239,68 +239,68 @@  discard block
 block discarded – undo
239 239
 	 */
240 240
 	public function payment_fields() {
241 241
 		$user                 = wp_get_current_user();
242
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
242
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
243 243
 		$total                = WC()->cart->total;
244 244
 		$user_email           = '';
245 245
 
246 246
 		// If paying from order, we need to get total from order not cart.
247
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
248
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
247
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
248
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
249 249
 			$total      = $order->get_total();
250 250
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
251 251
 		} else {
252
-			if ( $user->ID ) {
253
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
252
+			if ($user->ID) {
253
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
254 254
 				$user_email = $user_email ? $user_email : $user->user_email;
255 255
 			}
256 256
 		}
257 257
 
258
-		if ( is_add_payment_method_page() ) {
259
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
260
-			$total        = '';
258
+		if (is_add_payment_method_page()) {
259
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
260
+			$total = '';
261 261
 		} else {
262 262
 			$pay_button_text = '';
263 263
 		}
264 264
 
265 265
 		echo '<div
266 266
 			id="stripe-payment-data"
267
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
268
-			data-description="'. esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '"
269
-			data-email="' . esc_attr( $user_email ) . '"
270
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
271
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
272
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
273
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
274
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
275
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
276
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
277
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
278
-
279
-		if ( $this->description ) {
280
-			if ( $this->testmode ) {
267
+			data-panel-label="' . esc_attr($pay_button_text) . '"
268
+			data-description="'. esc_attr(strip_tags($this->stripe_checkout_description)) . '"
269
+			data-email="' . esc_attr($user_email) . '"
270
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
271
+			data-name="' . esc_attr($this->statement_descriptor) . '"
272
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
273
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
274
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
275
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
276
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
277
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
278
+
279
+		if ($this->description) {
280
+			if ($this->testmode) {
281 281
 				/* translators: link to Stripe testing page */
282
-				$this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
283
-				$this->description  = trim( $this->description );
282
+				$this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
283
+				$this->description  = trim($this->description);
284 284
 			}
285
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
285
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
286 286
 		}
287 287
 
288
-		if ( $display_tokenization ) {
288
+		if ($display_tokenization) {
289 289
 			$this->tokenization_script();
290 290
 			$this->saved_payment_methods();
291 291
 		}
292 292
 
293
-		if ( ! $this->stripe_checkout ) {
294
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
293
+		if ( ! $this->stripe_checkout) {
294
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
295 295
 				$this->elements_form();
296 296
 			} else {
297
-				WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' );
297
+				WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!');
298 298
 				$this->form();
299 299
 				echo '<div class="stripe-source-errors" role="alert"></div>';
300 300
 			}
301 301
 		}
302 302
 
303
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
303
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
304 304
 			$this->save_payment_method_checkbox();
305 305
 		}
306 306
 
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 	 */
316 316
 	public function elements_form() {
317 317
 		?>
318
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
319
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
318
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
319
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
320 320
 
321
-			<?php if ( $this->inline_cc_form ) { ?>
321
+			<?php if ($this->inline_cc_form) { ?>
322 322
 				<label for="card-element">
323
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
323
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
324 324
 				</label>
325 325
 
326 326
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 				</div>
329 329
 			<?php } else { ?>
330 330
 				<div class="form-row form-row-wide">
331
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
331
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
332 332
 
333 333
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
334 334
 					<!-- a Stripe Element will be inserted here. -->
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 				</div>
337 337
 
338 338
 				<div class="form-row form-row-first">
339
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
339
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
340 340
 
341 341
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
342 342
 					<!-- a Stripe Element will be inserted here. -->
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 				</div>
345 345
 
346 346
 				<div class="form-row form-row-last">
347
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
347
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
348 348
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
349 349
 				<!-- a Stripe Element will be inserted here. -->
350 350
 				</div>
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 
355 355
 			<!-- Used to display form errors -->
356 356
 			<div class="stripe-source-errors" role="alert"></div>
357
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
357
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
358 358
 			<div class="clear"></div>
359 359
 		</fieldset>
360 360
 		<?php
@@ -367,13 +367,13 @@  discard block
 block discarded – undo
367 367
 	 * @version 3.1.0
368 368
 	 */
369 369
 	public function admin_scripts() {
370
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
370
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
371 371
 			return;
372 372
 		}
373 373
 
374
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
374
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
375 375
 
376
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
376
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
377 377
 	}
378 378
 
379 379
 	/**
@@ -385,46 +385,46 @@  discard block
 block discarded – undo
385 385
 	 * @version 4.0.0
386 386
 	 */
387 387
 	public function payment_scripts() {
388
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
388
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
389 389
 			return;
390 390
 		}
391 391
 
392 392
 		// If Stripe is not enabled bail.
393
-		if ( 'no' === $this->enabled ) {
393
+		if ('no' === $this->enabled) {
394 394
 			return;
395 395
 		}
396 396
 
397 397
 		// If keys are not set bail.
398
-		if ( ! $this->are_keys_set() ) {
399
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
398
+		if ( ! $this->are_keys_set()) {
399
+			WC_Stripe_Logger::log('Keys are not set correctly.');
400 400
 			return;
401 401
 		}
402 402
 
403 403
 		// If no SSL bail.
404
-		if ( ! $this->testmode && ! is_ssl() ) {
405
-			WC_Stripe_Logger::log( 'Stripe requires SSL.' );
404
+		if ( ! $this->testmode && ! is_ssl()) {
405
+			WC_Stripe_Logger::log('Stripe requires SSL.');
406 406
 			return;
407 407
 		}
408 408
 
409
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
409
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
410 410
 
411
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
412
-		wp_enqueue_style( 'stripe_paymentfonts' );
413
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
414
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
415
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
416
-		wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true );
411
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
412
+		wp_enqueue_style('stripe_paymentfonts');
413
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
414
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
415
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
416
+		wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true);
417 417
 
418 418
 		$stripe_params = array(
419 419
 			'key'                  => $this->publishable_key,
420
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
421
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
420
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
421
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
422 422
 		);
423 423
 
424 424
 		// If we're on the pay page we need to pass stripe.js the address of the order.
425
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
426
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
427
-			$order    = wc_get_order( $order_id );
425
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
426
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
427
+			$order    = wc_get_order($order_id);
428 428
 
429 429
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
430 430
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -436,39 +436,39 @@  discard block
 block discarded – undo
436 436
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
437 437
 		}
438 438
 
439
-		$stripe_params['no_prepaid_card_msg']                     = __( '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' );
440
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
441
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
442
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
443
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
439
+		$stripe_params['no_prepaid_card_msg']                     = __('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');
440
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
441
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
442
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
443
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
444 444
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
445
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
446
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no';
445
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
446
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no';
447 447
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
448
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
449
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
448
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
449
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
450 450
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
451
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
452
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
451
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
452
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
453 453
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
454
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
455
-		$stripe_params['is_pay_for_order_page']                   = isset( $_GET['pay_for_order'] ) ? 'yes' : 'no';
456
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_modal_checkout', false ) ? 'yes' : 'no';
457
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
458
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
454
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
455
+		$stripe_params['is_pay_for_order_page']                   = isset($_GET['pay_for_order']) ? 'yes' : 'no';
456
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_modal_checkout', false) ? 'yes' : 'no';
457
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
458
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
459 459
 
460 460
 		// merge localized messages to be use in JS
461
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
461
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
462 462
 
463
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
464
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
463
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
464
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
465 465
 
466
-		if ( $this->stripe_checkout ) {
467
-			wp_enqueue_script( 'stripe_checkout' );
466
+		if ($this->stripe_checkout) {
467
+			wp_enqueue_script('stripe_checkout');
468 468
 		}
469 469
 
470 470
 		$this->tokenization_script();
471
-		wp_enqueue_script( 'woocommerce_stripe' );
471
+		wp_enqueue_script('woocommerce_stripe');
472 472
 	}
473 473
 
474 474
 	/**
@@ -484,41 +484,41 @@  discard block
 block discarded – undo
484 484
 	 *
485 485
 	 * @return array|void
486 486
 	 */
487
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
487
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
488 488
 		try {
489
-			$order = wc_get_order( $order_id );
489
+			$order = wc_get_order($order_id);
490 490
 
491 491
 			// This comes from the create account checkbox in the checkout page.
492
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
492
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
493 493
 
494
-			if ( $create_account ) {
494
+			if ($create_account) {
495 495
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
496
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
496
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
497 497
 				$new_stripe_customer->create_customer();
498 498
 			}
499 499
 
500
-			$prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source );
500
+			$prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source);
501 501
 			$source_object   = $prepared_source->source_object;
502 502
 
503 503
 			// Check if we don't allow prepaid credit cards.
504
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) {
505
-				$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' );
506
-				throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
504
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) {
505
+				$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');
506
+				throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
507 507
 			}
508 508
 
509
-			if ( empty( $prepared_source->source ) ) {
510
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
511
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
509
+			if (empty($prepared_source->source)) {
510
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
511
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
512 512
 			}
513 513
 
514
-			$this->save_source_to_order( $order, $prepared_source );
514
+			$this->save_source_to_order($order, $prepared_source);
515 515
 
516 516
 			// Result from Stripe API request.
517 517
 			$response = null;
518 518
 
519
-			if ( $order->get_total() > 0 ) {
519
+			if ($order->get_total() > 0) {
520 520
 				// This will throw exception if not valid.
521
-				$this->validate_minimum_order_amount( $order );
521
+				$this->validate_minimum_order_amount($order);
522 522
 
523 523
 				/*
524 524
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -527,105 +527,105 @@  discard block
 block discarded – undo
527 527
 				 * Note that if we need to save source, the original source must be first
528 528
 				 * attached to a customer in Stripe before it can be charged.
529 529
 				 */
530
-				if ( $this->is_3ds_required( $source_object ) ) {
531
-					$response = $this->create_3ds_source( $order, $source_object );
530
+				if ($this->is_3ds_required($source_object)) {
531
+					$response = $this->create_3ds_source($order, $source_object);
532 532
 
533
-					if ( ! empty( $response->error ) ) {
533
+					if ( ! empty($response->error)) {
534 534
 						$localized_message = $response->error->message;
535 535
 
536
-						$order->add_order_note( $localized_message );
536
+						$order->add_order_note($localized_message);
537 537
 
538
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
538
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
539 539
 					}
540 540
 
541 541
 					// Update order meta with 3DS source.
542
-					if ( WC_Stripe_Helper::is_pre_30() ) {
543
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
542
+					if (WC_Stripe_Helper::is_pre_30()) {
543
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
544 544
 					} else {
545
-						$order->update_meta_data( '_stripe_source_id', $response->id );
545
+						$order->update_meta_data('_stripe_source_id', $response->id);
546 546
 						$order->save();
547 547
 					}
548 548
 
549
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
549
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
550 550
 
551 551
 					return array(
552 552
 						'result'   => 'success',
553
-						'redirect' => esc_url_raw( $response->redirect->url ),
553
+						'redirect' => esc_url_raw($response->redirect->url),
554 554
 					);
555 555
 				}
556 556
 
557
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
557
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
558 558
 
559 559
 				/* If we're doing a retry and source is chargeable, we need to pass
560 560
 				 * a different idempotency key and retry for success.
561 561
 				 */
562
-				if ( 1 < $this->retry_interval && ! empty( $source_object ) && 'chargeable' === $source_object->status ) {
563
-					add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
562
+				if (1 < $this->retry_interval && ! empty($source_object) && 'chargeable' === $source_object->status) {
563
+					add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
564 564
 				}
565 565
 
566 566
 				// Make the request.
567
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
567
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
568 568
 
569
-				if ( ! empty( $response->error ) ) {
569
+				if ( ! empty($response->error)) {
570 570
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
571
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
572
-						if ( WC_Stripe_Helper::is_pre_30() ) {
573
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
574
-							delete_post_meta( $order_id, '_stripe_customer_id' );
571
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
572
+						if (WC_Stripe_Helper::is_pre_30()) {
573
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
574
+							delete_post_meta($order_id, '_stripe_customer_id');
575 575
 						} else {
576
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
577
-							$order->delete_meta_data( '_stripe_customer_id' );
576
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
577
+							$order->delete_meta_data('_stripe_customer_id');
578 578
 							$order->save();
579 579
 						}
580 580
 
581
-						return $this->process_payment( $order_id, false, $force_save_source );
582
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
581
+						return $this->process_payment($order_id, false, $force_save_source);
582
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
583 583
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
584
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
584
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
585 585
 						$wc_token->delete();
586
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
587
-						$order->add_order_note( $localized_message );
588
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
586
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
587
+						$order->add_order_note($localized_message);
588
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
589 589
 					}
590 590
 
591 591
 					// We want to retry.
592
-					if ( $this->is_retryable_error( $response->error ) ) {
593
-						if ( $retry ) {
592
+					if ($this->is_retryable_error($response->error)) {
593
+						if ($retry) {
594 594
 							// Don't do anymore retries after this.
595
-							if ( 5 <= $this->retry_interval ) {
595
+							if (5 <= $this->retry_interval) {
596 596
 
597
-								return $this->process_payment( $order_id, false, $force_save_source );
597
+								return $this->process_payment($order_id, false, $force_save_source);
598 598
 							}
599 599
 
600
-							sleep( $this->retry_interval );
600
+							sleep($this->retry_interval);
601 601
 
602 602
 							$this->retry_interval++;
603 603
 
604
-							return $this->process_payment( $order_id, true, $force_save_source );
604
+							return $this->process_payment($order_id, true, $force_save_source);
605 605
 						} else {
606
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
607
-							$order->add_order_note( $localized_message );
608
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
606
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
607
+							$order->add_order_note($localized_message);
608
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
609 609
 						}
610 610
 					}
611 611
 
612 612
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
613 613
 
614
-					if ( 'card_error' === $response->error->type ) {
615
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
614
+					if ('card_error' === $response->error->type) {
615
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
616 616
 					} else {
617
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
617
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
618 618
 					}
619 619
 
620
-					$order->add_order_note( $localized_message );
620
+					$order->add_order_note($localized_message);
621 621
 
622
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
622
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
623 623
 				}
624 624
 
625
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
625
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
626 626
 
627 627
 				// Process valid response.
628
-				$this->process_response( $response, $order );
628
+				$this->process_response($response, $order);
629 629
 			} else {
630 630
 				$order->payment_complete();
631 631
 			}
@@ -636,20 +636,20 @@  discard block
 block discarded – undo
636 636
 			// Return thank you page redirect.
637 637
 			return array(
638 638
 				'result'   => 'success',
639
-				'redirect' => $this->get_return_url( $order ),
639
+				'redirect' => $this->get_return_url($order),
640 640
 			);
641 641
 
642
-		} catch ( WC_Stripe_Exception $e ) {
643
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
644
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
642
+		} catch (WC_Stripe_Exception $e) {
643
+			wc_add_notice($e->getLocalizedMessage(), 'error');
644
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
645 645
 
646
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
646
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
647 647
 
648 648
 			/* translators: error message */
649
-			$order->update_status( 'failed' );
649
+			$order->update_status('failed');
650 650
 
651
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
652
-				$this->send_failed_order_email( $order_id );
651
+			if ($order->has_status(array('pending', 'failed'))) {
652
+				$this->send_failed_order_email($order_id);
653 653
 			}
654 654
 
655 655
 			return array(
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
  *
16 16
  */
17 17
 
18
-if ( ! defined( 'ABSPATH' ) ) {
18
+if ( ! defined('ABSPATH')) {
19 19
 	exit;
20 20
 }
21 21
 
22
-if ( ! class_exists( 'WC_Stripe' ) ) :
22
+if ( ! class_exists('WC_Stripe')) :
23 23
 	/**
24 24
 	 * Required minimums and constants
25 25
 	 */
26
-	define( 'WC_STRIPE_VERSION', '4.0.7' );
27
-	define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' );
28
-	define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' );
29
-	define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
30
-	define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
31
-	define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
26
+	define('WC_STRIPE_VERSION', '4.0.7');
27
+	define('WC_STRIPE_MIN_PHP_VER', '5.6.0');
28
+	define('WC_STRIPE_MIN_WC_VER', '2.6.0');
29
+	define('WC_STRIPE_MAIN_FILE', __FILE__);
30
+	define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
31
+	define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
32 32
 
33 33
 	class WC_Stripe {
34 34
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		 * @return Singleton The *Singleton* instance.
49 49
 		 */
50 50
 		public static function get_instance() {
51
-			if ( null === self::$instance ) {
51
+			if (null === self::$instance) {
52 52
 				self::$instance = new self();
53 53
 			}
54 54
 			return self::$instance;
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 		 * *Singleton* via the `new` operator from outside of this class.
82 82
 		 */
83 83
 		private function __construct() {
84
-			add_action( 'admin_init', array( $this, 'check_environment' ) );
85
-			add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
86
-			add_action( 'plugins_loaded', array( $this, 'init' ) );
87
-			add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
84
+			add_action('admin_init', array($this, 'check_environment'));
85
+			add_action('admin_notices', array($this, 'admin_notices'), 15);
86
+			add_action('plugins_loaded', array($this, 'init'));
87
+			add_action('wp_loaded', array($this, 'hide_notices'));
88 88
 		}
89 89
 
90 90
 		/**
@@ -94,44 +94,44 @@  discard block
 block discarded – undo
94 94
 		 * @version 4.0.0
95 95
 		 */
96 96
 		public function init() {
97
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' );
98
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' );
99
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' );
100
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
97
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php');
98
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php');
99
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php');
100
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
101 101
 
102 102
 			// Don't hook anything else in the plugin if we're in an incompatible environment.
103
-			if ( self::get_environment_warning() ) {
103
+			if (self::get_environment_warning()) {
104 104
 				return;
105 105
 			}
106 106
 
107
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
108
-
109
-			require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' );
110
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' );
111
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' );
112
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php' );
113
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
114
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' );
115
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' );
116
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' );
117
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' );
118
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' );
119
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' );
120
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' );
121
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' );
122
-			require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' );
123
-			require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' );
124
-			require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' );
125
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' );
126
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' );
127
-			require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
107
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
108
+
109
+			require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php');
110
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php');
111
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php');
112
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php');
113
+			require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
114
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php');
115
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php');
116
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php');
117
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php');
118
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php');
119
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php');
120
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php');
121
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php');
122
+			require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php');
123
+			require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php');
124
+			require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php');
125
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php');
126
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php');
127
+			require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
128 128
 
129 129
 			// REMOVE IN THE FUTURE.
130
-			require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' );
130
+			require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php');
131 131
 
132
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
133
-			add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
134
-			add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) );
132
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
133
+			add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
134
+			add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin'));
135 135
 		}
136 136
 
137 137
 		/**
@@ -141,23 +141,23 @@  discard block
 block discarded – undo
141 141
 		 * @version 4.0.0
142 142
 		 */
143 143
 		public function hide_notices() {
144
-			if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) {
145
-				if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) {
146
-					wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) );
144
+			if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) {
145
+				if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) {
146
+					wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe'));
147 147
 				}
148 148
 
149
-				if ( ! current_user_can( 'manage_woocommerce' ) ) {
150
-					wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
149
+				if ( ! current_user_can('manage_woocommerce')) {
150
+					wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
151 151
 				}
152 152
 
153
-				$notice = wc_clean( $_GET['wc-stripe-hide-notice'] );
153
+				$notice = wc_clean($_GET['wc-stripe-hide-notice']);
154 154
 
155
-				switch ( $notice ) {
155
+				switch ($notice) {
156 156
 					case 'ssl':
157
-						update_option( 'wc_stripe_show_ssl_notice', 'no' );
157
+						update_option('wc_stripe_show_ssl_notice', 'no');
158 158
 						break;
159 159
 					case 'keys':
160
-						update_option( 'wc_stripe_show_keys_notice', 'no' );
160
+						update_option('wc_stripe_show_keys_notice', 'no');
161 161
 						break;
162 162
 				}
163 163
 			}
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 		 * @since 1.0.0
170 170
 		 * @version 4.0.0
171 171
 		 */
172
-		public function add_admin_notice( $slug, $class, $message, $dismissible = false ) {
173
-			$this->notices[ $slug ] = array(
172
+		public function add_admin_notice($slug, $class, $message, $dismissible = false) {
173
+			$this->notices[$slug] = array(
174 174
 				'class'       => $class,
175 175
 				'message'     => $message,
176 176
 				'dismissible' => $dismissible,
@@ -184,21 +184,21 @@  discard block
 block discarded – undo
184 184
 		 * @version 4.0.0
185 185
 		 */
186 186
 		public function admin_notices() {
187
-			if ( ! current_user_can( 'manage_woocommerce' ) ) {
187
+			if ( ! current_user_can('manage_woocommerce')) {
188 188
 				return;
189 189
 			}
190 190
 
191
-			foreach ( (array) $this->notices as $notice_key => $notice ) {
192
-				echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">';
191
+			foreach ((array) $this->notices as $notice_key => $notice) {
192
+				echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">';
193 193
 
194
-				if ( $notice['dismissible'] ) {
194
+				if ($notice['dismissible']) {
195 195
 				?>
196
-					<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a>
196
+					<a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a>
197 197
 				<?php
198 198
 				}
199 199
 
200 200
 				echo '<p>';
201
-				echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
201
+				echo wp_kses($notice['message'], array('a' => array('href' => array())));
202 202
 				echo '</p></div>';
203 203
 			}
204 204
 		}
@@ -211,26 +211,26 @@  discard block
 block discarded – undo
211 211
 		 * @version 4.0.0
212 212
 		 */
213 213
 		public function get_environment_warning() {
214
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
214
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
215 215
 				/* translators: 1) int version 2) int version */
216
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
216
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
217 217
 
218
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
218
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
219 219
 			}
220 220
 
221
-			if ( ! defined( 'WC_VERSION' ) ) {
222
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
221
+			if ( ! defined('WC_VERSION')) {
222
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
223 223
 			}
224 224
 
225
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
225
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
226 226
 				/* translators: 1) int version 2) int version */
227
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
227
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
228 228
 
229
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
229
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
230 230
 			}
231 231
 
232
-			if ( ! function_exists( 'curl_init' ) ) {
233
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
232
+			if ( ! function_exists('curl_init')) {
233
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
234 234
 			}
235 235
 
236 236
 			return false;
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
 		 * @return string Setting link
245 245
 		 */
246 246
 		public function get_setting_link() {
247
-			$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
247
+			$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
248 248
 
249
-			$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
249
+			$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
250 250
 
251
-			return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
251
+			return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
252 252
 		}
253 253
 
254 254
 		/**
@@ -259,65 +259,65 @@  discard block
 block discarded – undo
259 259
 		 * @version 4.0.0
260 260
 		 */
261 261
 		public function check_environment() {
262
-			if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) {
262
+			if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) {
263 263
 				$this->install();
264 264
 
265
-				do_action( 'woocommerce_stripe_updated' );
265
+				do_action('woocommerce_stripe_updated');
266 266
 			}
267 267
 
268 268
 			$environment_warning = $this->get_environment_warning();
269 269
 
270
-			if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
271
-				$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
270
+			if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
271
+				$this->add_admin_notice('bad_environment', 'error', $environment_warning);
272 272
 			}
273 273
 
274
-			$show_ssl_notice  = get_option( 'wc_stripe_show_ssl_notice' );
275
-			$show_keys_notice = get_option( 'wc_stripe_show_keys_notice' );
276
-			$options          = get_option( 'woocommerce_stripe_settings' );
277
-			$testmode         = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false;
278
-			$test_pub_key     = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : '';
279
-			$test_secret_key  = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : '';
280
-			$live_pub_key     = isset( $options['publishable_key'] ) ? $options['publishable_key'] : '';
281
-			$live_secret_key  = isset( $options['secret_key'] ) ? $options['secret_key'] : '';
274
+			$show_ssl_notice  = get_option('wc_stripe_show_ssl_notice');
275
+			$show_keys_notice = get_option('wc_stripe_show_keys_notice');
276
+			$options          = get_option('woocommerce_stripe_settings');
277
+			$testmode         = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false;
278
+			$test_pub_key     = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : '';
279
+			$test_secret_key  = isset($options['test_secret_key']) ? $options['test_secret_key'] : '';
280
+			$live_pub_key     = isset($options['publishable_key']) ? $options['publishable_key'] : '';
281
+			$live_secret_key  = isset($options['secret_key']) ? $options['secret_key'] : '';
282 282
 
283
-			if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) {
284
-				$secret  = WC_Stripe_API::get_secret_key();
283
+			if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) {
284
+				$secret = WC_Stripe_API::get_secret_key();
285 285
 
286
-				if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
286
+				if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
287 287
 					$setting_link = $this->get_setting_link();
288 288
 					/* translators: 1) link */
289
-					$this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
289
+					$this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
290 290
 				}
291 291
 
292 292
 				// Check if keys are entered properly per live/test mode.
293
-				if ( $testmode ) {
293
+				if ($testmode) {
294 294
 					if (
295
-						! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key )
296
-						|| ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key )
297
-						&& ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) )
295
+						! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key)
296
+						|| ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key)
297
+						&& ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) )
298 298
 					{
299 299
 						$setting_link = $this->get_setting_link();
300 300
 						/* translators: 1) link */
301
-						$this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
301
+						$this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
302 302
 					}
303 303
 				} else {
304 304
 					if (
305
-						! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key )
306
-						|| ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key )
307
-						&& ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) )
305
+						! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key)
306
+						|| ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key)
307
+						&& ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) )
308 308
 					{
309 309
 						$setting_link = $this->get_setting_link();
310 310
 						/* translators: 1) link */
311
-						$this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
311
+						$this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
312 312
 					}
313 313
 				}
314 314
 			}
315 315
 
316
-			if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) {
316
+			if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) {
317 317
 				// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
318
-				if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
318
+				if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
319 319
 					/* translators: 1) link 2) link */
320
-					$this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true );
320
+					$this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true);
321 321
 				}
322 322
 			}
323 323
 		}
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 		 * @version 4.0.0
330 330
 		 */
331 331
 		public function update_plugin_version() {
332
-			delete_option( 'wc_stripe_version' );
333
-			update_option( 'wc_stripe_version', WC_STRIPE_VERSION );
332
+			delete_option('wc_stripe_version');
333
+			update_option('wc_stripe_version', WC_STRIPE_VERSION);
334 334
 		}
335 335
 
336 336
 		/**
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
 		 * @version 3.1.0
341 341
 		 */
342 342
 		public function install() {
343
-			if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) {
344
-				define( 'WC_STRIPE_INSTALLING', true );
343
+			if ( ! defined('WC_STRIPE_INSTALLING')) {
344
+				define('WC_STRIPE_INSTALLING', true);
345 345
 			}
346 346
 
347 347
 			$this->update_plugin_version();
@@ -353,13 +353,13 @@  discard block
 block discarded – undo
353 353
 		 * @since 1.0.0
354 354
 		 * @version 4.0.0
355 355
 		 */
356
-		public function plugin_action_links( $links ) {
356
+		public function plugin_action_links($links) {
357 357
 			$plugin_links = array(
358
-				'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
359
-				'<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
360
-				'<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
358
+				'<a href="admin.php?page=wc-settings&tab=checkout&section=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>',
359
+				'<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>',
360
+				'<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>',
361 361
 			);
362
-			return array_merge( $plugin_links, $links );
362
+			return array_merge($plugin_links, $links);
363 363
 		}
364 364
 
365 365
 		/**
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
 		 * @since 1.0.0
369 369
 		 * @version 4.0.0
370 370
 		 */
371
-		public function add_gateways( $methods ) {
372
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) {
371
+		public function add_gateways($methods) {
372
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) {
373 373
 				$methods[] = 'WC_Stripe_Compat';
374 374
 				$methods[] = 'WC_Stripe_Sepa_Compat';
375 375
 			} else {
@@ -394,26 +394,26 @@  discard block
 block discarded – undo
394 394
 		 * @since 4.0.0
395 395
 		 * @version 4.0.0
396 396
 		 */
397
-		public function filter_gateway_order_admin( $sections ) {
398
-			unset( $sections['stripe'] );
399
-			unset( $sections['stripe_bancontact'] );
400
-			unset( $sections['stripe_sofort'] );
401
-			unset( $sections['stripe_giropay'] );
402
-			unset( $sections['stripe_ideal'] );
403
-			unset( $sections['stripe_p24'] );
404
-			unset( $sections['stripe_alipay'] );
405
-			unset( $sections['stripe_sepa'] );
406
-			unset( $sections['stripe_bitcoin'] );
397
+		public function filter_gateway_order_admin($sections) {
398
+			unset($sections['stripe']);
399
+			unset($sections['stripe_bancontact']);
400
+			unset($sections['stripe_sofort']);
401
+			unset($sections['stripe_giropay']);
402
+			unset($sections['stripe_ideal']);
403
+			unset($sections['stripe_p24']);
404
+			unset($sections['stripe_alipay']);
405
+			unset($sections['stripe_sepa']);
406
+			unset($sections['stripe_bitcoin']);
407 407
 
408 408
 			$sections['stripe']            = 'Stripe';
409
-			$sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' );
410
-			$sections['stripe_sofort']     = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' );
411
-			$sections['stripe_giropay']    = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' );
412
-			$sections['stripe_ideal']      = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' );
413
-			$sections['stripe_p24']        = __( 'Stripe P24', 'woocommerce-gateway-stripe' );
414
-			$sections['stripe_alipay']     = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' );
415
-			$sections['stripe_sepa']       = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' );
416
-			$sections['stripe_bitcoin']    = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
409
+			$sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe');
410
+			$sections['stripe_sofort']     = __('Stripe SOFORT', 'woocommerce-gateway-stripe');
411
+			$sections['stripe_giropay']    = __('Stripe Giropay', 'woocommerce-gateway-stripe');
412
+			$sections['stripe_ideal']      = __('Stripe iDeal', 'woocommerce-gateway-stripe');
413
+			$sections['stripe_p24']        = __('Stripe P24', 'woocommerce-gateway-stripe');
414
+			$sections['stripe_alipay']     = __('Stripe Alipay', 'woocommerce-gateway-stripe');
415
+			$sections['stripe_sepa']       = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe');
416
+			$sections['stripe_bitcoin']    = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
417 417
 
418 418
 			return $sections;
419 419
 		}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-compat.php 1 patch
Spacing   +183 added lines, -183 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,23 +15,23 @@  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' ) );
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 31
 		}
32 32
 
33
-		if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
34
-			add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) );
33
+		if (class_exists('WC_Pre_Orders_Order')) {
34
+			add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment'));
35 35
 		}
36 36
 	}
37 37
 
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @since 4.0.0
43 43
 	 * @version 4.0.0
44 44
 	 */
45
-	public function maybe_hide_save_checkbox( $display_tokenization ) {
46
-		if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
45
+	public function maybe_hide_save_checkbox($display_tokenization) {
46
+		if (WC_Subscriptions_Cart::cart_contains_subscription()) {
47 47
 			return false;
48 48
 		}
49 49
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 	 * @param  int  $order_id
56 56
 	 * @return boolean
57 57
 	 */
58
-	public function has_subscription( $order_id ) {
59
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
58
+	public function has_subscription($order_id) {
59
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return bool
67 67
 	 */
68 68
 	public function is_subs_change_payment() {
69
-		return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) );
69
+		return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method']));
70 70
 	}
71 71
 
72 72
 	/**
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @param  int  $order_id
75 75
 	 * @return boolean
76 76
 	 */
77
-	public function is_pre_order( $order_id ) {
78
-		return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) );
77
+	public function is_pre_order($order_id) {
78
+		return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id));
79 79
 	}
80 80
 
81 81
 	/**
@@ -84,24 +84,24 @@  discard block
 block discarded – undo
84 84
 	 * @since 4.0.4
85 85
 	 * @param int $order_id
86 86
 	 */
87
-	public function change_subs_payment_method( $order_id ) {
87
+	public function change_subs_payment_method($order_id) {
88 88
 		try {
89
-			$subscription    = wc_get_order( $order_id );
90
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
89
+			$subscription    = wc_get_order($order_id);
90
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
91 91
 			$source_object   = $prepared_source->source_object;
92 92
 
93 93
 			// Check if we don't allow prepaid credit cards.
94
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) {
95
-				$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' );
96
-				throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
94
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) {
95
+				$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');
96
+				throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
97 97
 			}
98 98
 
99
-			if ( empty( $prepared_source->source ) ) {
100
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
101
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
99
+			if (empty($prepared_source->source)) {
100
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
101
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
102 102
 			}
103 103
 
104
-			$this->save_source_to_order( $subscription, $prepared_source );
104
+			$this->save_source_to_order($subscription, $prepared_source);
105 105
 
106 106
 			/*
107 107
 			 * Check if card 3DS is required or optional with 3DS setting.
@@ -110,41 +110,41 @@  discard block
 block discarded – undo
110 110
 			 * Note that if we need to save source, the original source must be first
111 111
 			 * attached to a customer in Stripe before it can be charged.
112 112
 			 */
113
-			if ( $this->is_3ds_required( $source_object ) ) {
113
+			if ($this->is_3ds_required($source_object)) {
114 114
 				$order    = $subscription->get_parent();
115
-				$response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() );
115
+				$response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url());
116 116
 
117
-				if ( ! empty( $response->error ) ) {
117
+				if ( ! empty($response->error)) {
118 118
 					$localized_message = $response->error->message;
119 119
 
120
-					$order->add_order_note( $localized_message );
120
+					$order->add_order_note($localized_message);
121 121
 
122
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
122
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
123 123
 				}
124 124
 
125 125
 				// Update order meta with 3DS source.
126
-				if ( WC_Stripe_Helper::is_pre_30() ) {
127
-					update_post_meta( $order_id, '_stripe_source_id', $response->id );
126
+				if (WC_Stripe_Helper::is_pre_30()) {
127
+					update_post_meta($order_id, '_stripe_source_id', $response->id);
128 128
 				} else {
129
-					$subscription->update_meta_data( '_stripe_source_id', $response->id );
129
+					$subscription->update_meta_data('_stripe_source_id', $response->id);
130 130
 					$subscription->save();
131 131
 				}
132 132
 
133
-				WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
133
+				WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
134 134
 
135 135
 				return array(
136 136
 					'result'   => 'success',
137
-					'redirect' => esc_url_raw( $response->redirect->url ),
137
+					'redirect' => esc_url_raw($response->redirect->url),
138 138
 				);
139 139
 			}
140 140
 
141 141
 			return array(
142 142
 				'result'   => 'success',
143
-				'redirect' => $this->get_return_url( $subscription ),
143
+				'redirect' => $this->get_return_url($subscription),
144 144
 			);
145
-		} catch ( WC_Stripe_Exception $e ) {
146
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
147
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
145
+		} catch (WC_Stripe_Exception $e) {
146
+			wc_add_notice($e->getLocalizedMessage(), 'error');
147
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
148 148
 		}
149 149
 	}
150 150
 
@@ -153,18 +153,18 @@  discard block
 block discarded – undo
153 153
 	 * @param  int $order_id
154 154
 	 * @return array
155 155
 	 */
156
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
157
-		if ( $this->has_subscription( $order_id ) ) {
158
-			if ( $this->is_subs_change_payment() ) {
159
-				return $this->change_subs_payment_method( $order_id );
156
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
157
+		if ($this->has_subscription($order_id)) {
158
+			if ($this->is_subs_change_payment()) {
159
+				return $this->change_subs_payment_method($order_id);
160 160
 			}
161 161
 
162 162
 			// Regular payment with force customer enabled
163
-			return parent::process_payment( $order_id, true, true );
164
-		} elseif ( $this->is_pre_order( $order_id ) ) {
165
-			return $this->process_pre_order( $order_id, $retry, $force_save_source );
163
+			return parent::process_payment($order_id, true, true);
164
+		} elseif ($this->is_pre_order($order_id)) {
165
+			return $this->process_pre_order($order_id, $retry, $force_save_source);
166 166
 		} else {
167
-			return parent::process_payment( $order_id, $retry, $force_save_source );
167
+			return parent::process_payment($order_id, $retry, $force_save_source);
168 168
 		}
169 169
 	}
170 170
 
@@ -174,24 +174,24 @@  discard block
 block discarded – undo
174 174
 	 * @since 3.1.0
175 175
 	 * @version 4.0.0
176 176
 	 */
177
-	public function save_source_to_order( $order, $source ) {
178
-		parent::save_source_to_order( $order, $source );
177
+	public function save_source_to_order($order, $source) {
178
+		parent::save_source_to_order($order, $source);
179 179
 
180 180
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
181 181
 
182 182
 		// Also store it on the subscriptions being purchased or paid for in the order
183
-		if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) {
184
-			$subscriptions = wcs_get_subscriptions_for_order( $order_id );
185
-		} elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) {
186
-			$subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id );
183
+		if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) {
184
+			$subscriptions = wcs_get_subscriptions_for_order($order_id);
185
+		} elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) {
186
+			$subscriptions = wcs_get_subscriptions_for_renewal_order($order_id);
187 187
 		} else {
188 188
 			$subscriptions = array();
189 189
 		}
190 190
 
191
-		foreach ( $subscriptions as $subscription ) {
191
+		foreach ($subscriptions as $subscription) {
192 192
 			$subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id();
193
-			update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer );
194
-			update_post_meta( $subscription_id, '_stripe_source_id', $source->source );
193
+			update_post_meta($subscription_id, '_stripe_customer_id', $source->customer);
194
+			update_post_meta($subscription_id, '_stripe_source_id', $source->source);
195 195
 		}
196 196
 	}
197 197
 
@@ -204,45 +204,45 @@  discard block
 block discarded – undo
204 204
 	 * @param mixed $renewal_order
205 205
 	 * @param bool $is_retry Is this a retry process.
206 206
 	 */
207
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
208
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
207
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
208
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
209 209
 			/* translators: minimum amount */
210
-			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 ) ) );
210
+			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)));
211 211
 		}
212 212
 
213 213
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
214 214
 
215 215
 		// Get source from order
216
-		$prepared_source = $this->prepare_order_source( $renewal_order );
216
+		$prepared_source = $this->prepare_order_source($renewal_order);
217 217
 
218
-		if ( ! $prepared_source->customer ) {
219
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
218
+		if ( ! $prepared_source->customer) {
219
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
220 220
 		}
221 221
 
222
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
222
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
223 223
 
224
-		if ( $is_retry ) {
224
+		if ($is_retry) {
225 225
 			// Passing empty source with charge customer default.
226 226
 			$prepared_source->source = '';
227 227
 		}
228 228
 
229
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
229
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
230 230
 		$request['capture'] = 'true';
231
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
232
-		$response           = WC_Stripe_API::request( $request );
231
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
232
+		$response           = WC_Stripe_API::request($request);
233 233
 
234
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
235
-			if ( $is_retry ) {
234
+		if ( ! empty($response->error) || is_wp_error($response)) {
235
+			if ($is_retry) {
236 236
 				/* translators: error message */
237
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
237
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
238 238
 			}
239 239
 
240 240
 			return $response; // Default catch all errors.
241 241
 		}
242 242
 
243
-		$this->process_response( $response, $renewal_order );
243
+		$this->process_response($response, $renewal_order);
244 244
 
245
-		if ( ! $is_retry ) {
245
+		if ( ! $is_retry) {
246 246
 			return $response;
247 247
 		}
248 248
 	}
@@ -251,21 +251,21 @@  discard block
 block discarded – undo
251 251
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
252 252
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
253 253
 	 */
254
-	public function delete_resubscribe_meta( $resubscribe_order ) {
255
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
256
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
254
+	public function delete_resubscribe_meta($resubscribe_order) {
255
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
256
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
257 257
 		// For BW compat will remove in future
258
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
259
-		$this->delete_renewal_meta( $resubscribe_order );
258
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
259
+		$this->delete_renewal_meta($resubscribe_order);
260 260
 	}
261 261
 
262 262
 	/**
263 263
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
264 264
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
265 265
 	 */
266
-	public function delete_renewal_meta( $renewal_order ) {
267
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
268
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
266
+	public function delete_renewal_meta($renewal_order) {
267
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
268
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
269 269
 		return $renewal_order;
270 270
 	}
271 271
 
@@ -275,21 +275,21 @@  discard block
 block discarded – undo
275 275
 	 * @param $amount_to_charge float The amount to charge.
276 276
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
277 277
 	 */
278
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
279
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
278
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
279
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
280 280
 
281
-		if ( is_wp_error( $response ) ) {
281
+		if (is_wp_error($response)) {
282 282
 			/* translators: error message */
283
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
283
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
284 284
 		}
285 285
 
286
-		if ( ! empty( $response->error ) ) {
286
+		if ( ! empty($response->error)) {
287 287
 			// This is a very generic error to listen for but worth a retry before total fail.
288
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
289
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
288
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
289
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
290 290
 			} else {
291 291
 				/* translators: error message */
292
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
292
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
293 293
 			}
294 294
 		}
295 295
 	}
@@ -298,20 +298,20 @@  discard block
 block discarded – undo
298 298
 	 * Remove order meta
299 299
 	 * @param object $order
300 300
 	 */
301
-	public function remove_order_source_before_retry( $order ) {
301
+	public function remove_order_source_before_retry($order) {
302 302
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
303
-		delete_post_meta( $order_id, '_stripe_source_id' );
303
+		delete_post_meta($order_id, '_stripe_source_id');
304 304
 		// For BW compat will remove in the future.
305
-		delete_post_meta( $order_id, '_stripe_card_id' );
305
+		delete_post_meta($order_id, '_stripe_card_id');
306 306
 	}
307 307
 
308 308
 	/**
309 309
 	 * Remove order meta
310 310
 	 * @param  object $order
311 311
 	 */
312
-	public function remove_order_customer_before_retry( $order ) {
312
+	public function remove_order_customer_before_retry($order) {
313 313
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
314
-		delete_post_meta( $order_id, '_stripe_customer_id' );
314
+		delete_post_meta($order_id, '_stripe_customer_id');
315 315
 	}
316 316
 
317 317
 	/**
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
324 324
 	 * @return void
325 325
 	 */
326
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
327
-		if ( WC_Stripe_Helper::is_pre_30() ) {
328
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
329
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
326
+	public function update_failing_payment_method($subscription, $renewal_order) {
327
+		if (WC_Stripe_Helper::is_pre_30()) {
328
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
329
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
330 330
 
331 331
 		} else {
332
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
333
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
332
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
333
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
334 334
 		}
335 335
 	}
336 336
 
@@ -343,21 +343,21 @@  discard block
 block discarded – undo
343 343
 	 * @param WC_Subscription $subscription An instance of a subscription object
344 344
 	 * @return array
345 345
 	 */
346
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
347
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
346
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
347
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
348 348
 
349 349
 		// For BW compat will remove in future.
350
-		if ( empty( $source_id ) ) {
351
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
350
+		if (empty($source_id)) {
351
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
352 352
 
353 353
 			// Take this opportunity to update the key name.
354
-			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 );
354
+			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);
355 355
 		}
356 356
 
357
-		$payment_meta[ $this->id ] = array(
357
+		$payment_meta[$this->id] = array(
358 358
 			'post_meta' => array(
359 359
 				'_stripe_customer_id' => array(
360
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
360
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
361 361
 					'label' => 'Stripe Customer ID',
362 362
 				),
363 363
 				'_stripe_source_id' => array(
@@ -380,22 +380,22 @@  discard block
 block discarded – undo
380 380
 	 * @param array $payment_meta associative array of meta data required for automatic payments
381 381
 	 * @return array
382 382
 	 */
383
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
384
-		if ( $this->id === $payment_method_id ) {
383
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
384
+		if ($this->id === $payment_method_id) {
385 385
 
386
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
387
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
388
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
389
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
386
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
387
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
388
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
389
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
390 390
 			}
391 391
 
392 392
 			if (
393
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
394
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
395
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
396
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
393
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
394
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
395
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
396
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
397 397
 
398
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
398
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
399 399
 			}
400 400
 		}
401 401
 	}
@@ -408,92 +408,92 @@  discard block
 block discarded – undo
408 408
 	 * @param WC_Subscription $subscription the subscription details
409 409
 	 * @return string the subscription payment method
410 410
 	 */
411
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
411
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
412 412
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
413 413
 
414 414
 		// bail for other payment methods
415
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
415
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
416 416
 			return $payment_method_to_display;
417 417
 		}
418 418
 
419
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
419
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
420 420
 
421 421
 		// For BW compat will remove in future.
422
-		if ( empty( $stripe_source_id ) ) {
423
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
422
+		if (empty($stripe_source_id)) {
423
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
424 424
 
425 425
 			// Take this opportunity to update the key name.
426
-			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 );
426
+			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);
427 427
 		}
428 428
 
429 429
 		$stripe_customer    = new WC_Stripe_Customer();
430
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
430
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
431 431
 
432 432
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
433
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
433
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
434 434
 			$user_id            = $customer_user;
435
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
436
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
435
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
436
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
437 437
 
438 438
 			// For BW compat will remove in future.
439
-			if ( empty( $stripe_source_id ) ) {
440
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
439
+			if (empty($stripe_source_id)) {
440
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
441 441
 
442 442
 				// Take this opportunity to update the key name.
443
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
443
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
444 444
 			}
445 445
 		}
446 446
 
447 447
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
448
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
449
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
450
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
448
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
449
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
450
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
451 451
 
452 452
 			// For BW compat will remove in future.
453
-			if ( empty( $stripe_source_id ) ) {
454
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
453
+			if (empty($stripe_source_id)) {
454
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
455 455
 
456 456
 				// Take this opportunity to update the key name.
457
-				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 );
457
+				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);
458 458
 			}
459 459
 		}
460 460
 
461
-		$stripe_customer->set_id( $stripe_customer_id );
461
+		$stripe_customer->set_id($stripe_customer_id);
462 462
 		$sources = $stripe_customer->get_sources();
463 463
 
464
-		if ( $sources ) {
464
+		if ($sources) {
465 465
 			$card         = false;
466 466
 			$found_source = false;
467
-			foreach ( $sources as $source ) {
468
-				if ( isset( $source->type ) && 'card' === $source->type ) {
467
+			foreach ($sources as $source) {
468
+				if (isset($source->type) && 'card' === $source->type) {
469 469
 					$card = $source->card;
470
-				} elseif ( isset( $source->object ) && 'card' === $source->object ) {
470
+				} elseif (isset($source->object) && 'card' === $source->object) {
471 471
 					$card = $source;
472 472
 				}
473 473
 
474
-				if ( $source->id === $stripe_source_id ) {
474
+				if ($source->id === $stripe_source_id) {
475 475
 					$found_source = true;
476 476
 
477
-					if ( $card ) {
477
+					if ($card) {
478 478
 						/* translators: 1) card brand 2) last 4 digits */
479
-						$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 );
479
+						$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);
480 480
 					} else {
481
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
481
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
482 482
 					}
483 483
 					break;
484 484
 				}
485 485
 			}
486 486
 
487
-			if ( ! $found_source ) {
488
-				if ( 'card' === $sources[0]->type ) {
487
+			if ( ! $found_source) {
488
+				if ('card' === $sources[0]->type) {
489 489
 					$card = $sources[0]->card;
490 490
 				}
491 491
 
492
-				if ( $card ) {
492
+				if ($card) {
493 493
 					/* translators: 1) card brand 2) last 4 digits */
494
-					$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 );
494
+					$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);
495 495
 				} else {
496
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
496
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
497 497
 				}
498 498
 			}
499 499
 		}
@@ -506,42 +506,42 @@  discard block
 block discarded – undo
506 506
 	 * @param int $order_id
507 507
 	 * @return array
508 508
 	 */
509
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
510
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
509
+	public function process_pre_order($order_id, $retry, $force_save_source) {
510
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
511 511
 			try {
512
-				$order = wc_get_order( $order_id );
512
+				$order = wc_get_order($order_id);
513 513
 
514
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
514
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
515 515
 					/* translators: minimum amount */
516
-					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 ) ) );
516
+					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)));
517 517
 				}
518 518
 
519
-				$prepared_source = $this->prepare_source( get_current_user_id(), true );
519
+				$prepared_source = $this->prepare_source(get_current_user_id(), true);
520 520
 
521 521
 				// We need a source on file to continue.
522
-				if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) {
523
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
522
+				if (empty($prepared_source->customer) || empty($prepared_source->source)) {
523
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
524 524
 				}
525 525
 
526
-				$this->save_source_to_order( $order, $prepared_source );
526
+				$this->save_source_to_order($order, $prepared_source);
527 527
 
528 528
 				// Remove cart
529 529
 				WC()->cart->empty_cart();
530 530
 
531 531
 				// Is pre ordered!
532
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
532
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
533 533
 
534 534
 				// Return thank you page redirect
535 535
 				return array(
536 536
 					'result'   => 'success',
537
-					'redirect' => $this->get_return_url( $order ),
537
+					'redirect' => $this->get_return_url($order),
538 538
 				);
539
-			} catch ( Exception $e ) {
540
-				wc_add_notice( $e->getMessage(), 'error' );
539
+			} catch (Exception $e) {
540
+				wc_add_notice($e->getMessage(), 'error');
541 541
 				return;
542 542
 			}
543 543
 		} else {
544
-			return parent::process_payment( $order_id, $retry, $force_save_source );
544
+			return parent::process_payment($order_id, $retry, $force_save_source);
545 545
 		}
546 546
 	}
547 547
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 	 * @param WC_Order $order
551 551
 	 * @return void
552 552
 	 */
553
-	public function process_pre_order_release_payment( $order ) {
553
+	public function process_pre_order_release_payment($order) {
554 554
 		try {
555 555
 			// Define some callbacks if the first attempt fails.
556 556
 			$retry_callbacks = array(
@@ -558,33 +558,33 @@  discard block
 block discarded – undo
558 558
 				'remove_order_customer_before_retry',
559 559
 			);
560 560
 
561
-			while ( 1 ) {
562
-				$source   = $this->prepare_order_source( $order );
563
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
561
+			while (1) {
562
+				$source   = $this->prepare_order_source($order);
563
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
564 564
 
565
-				if ( ! empty( $response->error ) ) {
566
-					if ( 0 === sizeof( $retry_callbacks ) ) {
567
-						throw new Exception( $response->error->message );
565
+				if ( ! empty($response->error)) {
566
+					if (0 === sizeof($retry_callbacks)) {
567
+						throw new Exception($response->error->message);
568 568
 					} else {
569
-						$retry_callback = array_shift( $retry_callbacks );
570
-						call_user_func( array( $this, $retry_callback ), $order );
569
+						$retry_callback = array_shift($retry_callbacks);
570
+						call_user_func(array($this, $retry_callback), $order);
571 571
 					}
572 572
 				} else {
573 573
 					// Successful
574
-					$this->process_response( $response, $order );
574
+					$this->process_response($response, $order);
575 575
 					break;
576 576
 				}
577 577
 			}
578
-		} catch ( Exception $e ) {
578
+		} catch (Exception $e) {
579 579
 			/* translators: error message */
580
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
580
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
581 581
 
582 582
 			// Mark order as failed if not already set,
583 583
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
584
-			if ( ! $order->has_status( 'failed' ) ) {
585
-				$order->update_status( 'failed', $order_note );
584
+			if ( ! $order->has_status('failed')) {
585
+				$order->update_status('failed', $order_note);
586 586
 			} else {
587
-				$order->add_order_note( $order_note );
587
+				$order->add_order_note($order_note);
588 588
 			}
589 589
 		}
590 590
 	}
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 1 patch
Spacing   +154 added lines, -154 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( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
95
+	public function add_subscription_meta_data($metadata, $order) {
96
+		if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $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_to_order( $order, $source ) {
113
-		parent::save_source_to_order( $order, $source );
112
+	public function save_source_to_order($order, $source) {
113
+		parent::save_source_to_order($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
 
@@ -139,45 +139,45 @@  discard block
 block discarded – undo
139 139
 	 * @param mixed $renewal_order
140 140
 	 * @param bool $is_retry Is this a retry process.
141 141
 	 */
142
-	public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) {
143
-		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
142
+	public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) {
143
+		if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) {
144 144
 			/* translators: minimum amount */
145
-			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 ) ) );
145
+			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)));
146 146
 		}
147 147
 
148 148
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
149 149
 
150 150
 		// Get source from order.
151
-		$prepared_source = $this->prepare_order_source( $renewal_order );
151
+		$prepared_source = $this->prepare_order_source($renewal_order);
152 152
 
153
-		if ( ! $prepared_source->customer ) {
154
-			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
153
+		if ( ! $prepared_source->customer) {
154
+			return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe'));
155 155
 		}
156 156
 
157
-		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
157
+		WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}");
158 158
 
159
-		if ( $is_retry ) {
159
+		if ($is_retry) {
160 160
 			// Passing empty source with charge customer default.
161 161
 			$prepared_source->source = '';
162 162
 		}
163 163
 
164
-		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
164
+		$request            = $this->generate_payment_request($renewal_order, $prepared_source);
165 165
 		$request['capture'] = 'true';
166
-		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
167
-		$response           = WC_Stripe_API::request( $request );
166
+		$request['amount']  = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']);
167
+		$response           = WC_Stripe_API::request($request);
168 168
 
169
-		if ( ! empty( $response->error ) || is_wp_error( $response ) ) {
170
-			if ( $is_retry ) {
169
+		if ( ! empty($response->error) || is_wp_error($response)) {
170
+			if ($is_retry) {
171 171
 				/* translators: error message */
172
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
172
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
173 173
 			}
174 174
 
175 175
 			return $response; // Default catch all errors.
176 176
 		}
177 177
 
178
-		$this->process_response( $response, $renewal_order );
178
+		$this->process_response($response, $renewal_order);
179 179
 
180
-		if ( ! $is_retry ) {
180
+		if ( ! $is_retry) {
181 181
 			return $response;
182 182
 		}
183 183
 	}
@@ -186,21 +186,21 @@  discard block
 block discarded – undo
186 186
 	 * Don't transfer Stripe customer/token meta to resubscribe orders.
187 187
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
188 188
 	 */
189
-	public function delete_resubscribe_meta( $resubscribe_order ) {
190
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' );
191
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' );
189
+	public function delete_resubscribe_meta($resubscribe_order) {
190
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id');
191
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id');
192 192
 		// For BW compat will remove in future
193
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' );
194
-		$this->delete_renewal_meta( $resubscribe_order );
193
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id');
194
+		$this->delete_renewal_meta($resubscribe_order);
195 195
 	}
196 196
 
197 197
 	/**
198 198
 	 * Don't transfer Stripe fee/ID meta to renewal orders.
199 199
 	 * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription
200 200
 	 */
201
-	public function delete_renewal_meta( $renewal_order ) {
202
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' );
203
-		delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' );
201
+	public function delete_renewal_meta($renewal_order) {
202
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee');
203
+		delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe');
204 204
 		return $renewal_order;
205 205
 	}
206 206
 
@@ -210,21 +210,21 @@  discard block
 block discarded – undo
210 210
 	 * @param $amount_to_charge float The amount to charge.
211 211
 	 * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment.
212 212
 	 */
213
-	public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
214
-		$response = $this->process_subscription_payment( $amount_to_charge, $renewal_order );
213
+	public function scheduled_subscription_payment($amount_to_charge, $renewal_order) {
214
+		$response = $this->process_subscription_payment($amount_to_charge, $renewal_order);
215 215
 
216
-		if ( is_wp_error( $response ) ) {
216
+		if (is_wp_error($response)) {
217 217
 			/* translators: error message */
218
-			$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
218
+			$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message()));
219 219
 		}
220 220
 
221
-		if ( ! empty( $response->error ) ) {
221
+		if ( ! empty($response->error)) {
222 222
 			// This is a very generic error to listen for but worth a retry before total fail.
223
-			if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
224
-				$this->process_subscription_payment( $amount_to_charge, $renewal_order, true );
223
+			if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) {
224
+				$this->process_subscription_payment($amount_to_charge, $renewal_order, true);
225 225
 			} else {
226 226
 				/* translators: error message */
227
-				$renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) );
227
+				$renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message));
228 228
 			}
229 229
 		}
230 230
 	}
@@ -233,20 +233,20 @@  discard block
 block discarded – undo
233 233
 	 * Remove order meta
234 234
 	 * @param  object $order
235 235
 	 */
236
-	public function remove_order_source_before_retry( $order ) {
236
+	public function remove_order_source_before_retry($order) {
237 237
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
238
-		delete_post_meta( $order_id, '_stripe_source_id' );
238
+		delete_post_meta($order_id, '_stripe_source_id');
239 239
 		// For BW compat will remove in the future.
240
-		delete_post_meta( $order_id, '_stripe_card_id' );
240
+		delete_post_meta($order_id, '_stripe_card_id');
241 241
 	}
242 242
 
243 243
 	/**
244 244
 	 * Remove order meta
245 245
 	 * @param object $order
246 246
 	 */
247
-	public function remove_order_customer_before_retry( $order ) {
247
+	public function remove_order_customer_before_retry($order) {
248 248
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
249
-		delete_post_meta( $order_id, '_stripe_customer_id' );
249
+		delete_post_meta($order_id, '_stripe_customer_id');
250 250
 	}
251 251
 
252 252
 	/**
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 	 * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
259 259
 	 * @return void
260 260
 	 */
261
-	public function update_failing_payment_method( $subscription, $renewal_order ) {
262
-		if ( WC_Stripe_Helper::is_pre_30() ) {
263
-			update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id );
264
-			update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id );
261
+	public function update_failing_payment_method($subscription, $renewal_order) {
262
+		if (WC_Stripe_Helper::is_pre_30()) {
263
+			update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id);
264
+			update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id);
265 265
 
266 266
 		} else {
267
-			update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) );
268
-			update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) );
267
+			update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true));
268
+			update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true));
269 269
 		}
270 270
 	}
271 271
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 	 * @param WC_Subscription $subscription An instance of a subscription object
279 279
 	 * @return array
280 280
 	 */
281
-	public function add_subscription_payment_meta( $payment_meta, $subscription ) {
282
-		$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
281
+	public function add_subscription_payment_meta($payment_meta, $subscription) {
282
+		$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
283 283
 
284 284
 		// For BW compat will remove in future.
285
-		if ( empty( $source_id ) ) {
286
-			$source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
285
+		if (empty($source_id)) {
286
+			$source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
287 287
 
288 288
 			// Take this opportunity to update the key name.
289
-			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 );
289
+			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);
290 290
 		}
291 291
 
292
-		$payment_meta[ $this->id ] = array(
292
+		$payment_meta[$this->id] = array(
293 293
 			'post_meta' => array(
294 294
 				'_stripe_customer_id' => array(
295
-					'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ),
295
+					'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true),
296 296
 					'label' => 'Stripe Customer ID',
297 297
 				),
298 298
 				'_stripe_source_id' => array(
@@ -313,22 +313,22 @@  discard block
 block discarded – undo
313 313
 	 * @param array $payment_meta associative array of meta data required for automatic payments
314 314
 	 * @return array
315 315
 	 */
316
-	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
317
-		if ( $this->id === $payment_method_id ) {
316
+	public function validate_subscription_payment_meta($payment_method_id, $payment_meta) {
317
+		if ($this->id === $payment_method_id) {
318 318
 
319
-			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
320
-				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
321
-			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
322
-				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
319
+			if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) {
320
+				throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe'));
321
+			} elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) {
322
+				throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe'));
323 323
 			}
324 324
 
325 325
 			if (
326
-				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
327
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
328
-				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
329
-				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
326
+				( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
327
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_'))
328
+				&& ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value'])
329
+				&& 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) {
330 330
 
331
-				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
331
+				throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe'));
332 332
 			}
333 333
 		}
334 334
 	}
@@ -341,67 +341,67 @@  discard block
 block discarded – undo
341 341
 	 * @param WC_Subscription $subscription the subscription details
342 342
 	 * @return string the subscription payment method
343 343
 	 */
344
-	public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) {
344
+	public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) {
345 345
 		$customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id();
346 346
 
347 347
 		// bail for other payment methods
348
-		if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) {
348
+		if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) {
349 349
 			return $payment_method_to_display;
350 350
 		}
351 351
 
352
-		$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true );
352
+		$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true);
353 353
 
354 354
 		// For BW compat will remove in future.
355
-		if ( empty( $stripe_source_id ) ) {
356
-			$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true );
355
+		if (empty($stripe_source_id)) {
356
+			$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true);
357 357
 
358 358
 			// Take this opportunity to update the key name.
359
-			WC_Stripe_Helper::is_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 );
359
+			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);
360 360
 		}
361 361
 
362 362
 		$stripe_customer    = new WC_Stripe_Customer();
363
-		$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true );
363
+		$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true);
364 364
 
365 365
 		// If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data.
366
-		if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) {
366
+		if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) {
367 367
 			$user_id            = $customer_user;
368
-			$stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
369
-			$stripe_source_id   = get_user_meta( $user_id, '_stripe_source_id', true );
368
+			$stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true);
369
+			$stripe_source_id   = get_user_meta($user_id, '_stripe_source_id', true);
370 370
 
371 371
 			// For BW compat will remove in future.
372
-			if ( empty( $stripe_source_id ) ) {
373
-				$stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true );
372
+			if (empty($stripe_source_id)) {
373
+				$stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true);
374 374
 
375 375
 				// Take this opportunity to update the key name.
376
-				update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id );
376
+				update_user_meta($user_id, '_stripe_source_id', $stripe_source_id);
377 377
 			}
378 378
 		}
379 379
 
380 380
 		// If we couldn't find a Stripe customer linked to the account, fallback to the order meta data.
381
-		if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) {
382
-			$stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true );
383
-			$stripe_source_id   = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true );
381
+		if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) {
382
+			$stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true);
383
+			$stripe_source_id   = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true);
384 384
 
385 385
 			// For BW compat will remove in future.
386
-			if ( empty( $stripe_source_id ) ) {
387
-				$stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true );
386
+			if (empty($stripe_source_id)) {
387
+				$stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true);
388 388
 
389 389
 				// Take this opportunity to update the key name.
390
-				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 );
390
+				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);
391 391
 			}
392 392
 		}
393 393
 
394
-		$stripe_customer->set_id( $stripe_customer_id );
394
+		$stripe_customer->set_id($stripe_customer_id);
395 395
 		$sources = $stripe_customer->get_sources();
396 396
 
397
-		if ( $sources ) {
398
-			foreach ( $sources as $source ) {
399
-				if ( $source->id === $stripe_source_id ) {
400
-					if ( $source->sepa_debit ) {
397
+		if ($sources) {
398
+			foreach ($sources as $source) {
399
+				if ($source->id === $stripe_source_id) {
400
+					if ($source->sepa_debit) {
401 401
 						/* translators: 1) last 4 digits of SEPA Direct Debit */
402
-						$payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 );
402
+						$payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4);
403 403
 					} else {
404
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
404
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
405 405
 					}
406 406
 					break;
407 407
 				}
@@ -416,42 +416,42 @@  discard block
 block discarded – undo
416 416
 	 * @param int $order_id
417 417
 	 * @return array
418 418
 	 */
419
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
420
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
419
+	public function process_pre_order($order_id, $retry, $force_save_source) {
420
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
421 421
 			try {
422
-				$order = wc_get_order( $order_id );
422
+				$order = wc_get_order($order_id);
423 423
 
424
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
424
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
425 425
 					/* translators: minimum amount */
426
-					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 ) ) );
426
+					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)));
427 427
 				}
428 428
 
429
-				$prepared_source = $this->prepare_source( get_current_user_id(), true );
429
+				$prepared_source = $this->prepare_source(get_current_user_id(), true);
430 430
 
431 431
 				// We need a source on file to continue.
432
-				if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) {
433
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
432
+				if (empty($prepared_source->customer) || empty($prepared_source->source)) {
433
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
434 434
 				}
435 435
 
436
-				$this->save_source_to_order( $order, $prepared_source );
436
+				$this->save_source_to_order($order, $prepared_source);
437 437
 
438 438
 				// Remove cart
439 439
 				WC()->cart->empty_cart();
440 440
 
441 441
 				// Is pre ordered!
442
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
442
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
443 443
 
444 444
 				// Return thank you page redirect
445 445
 				return array(
446 446
 					'result'   => 'success',
447
-					'redirect' => $this->get_return_url( $order ),
447
+					'redirect' => $this->get_return_url($order),
448 448
 				);
449
-			} catch ( Exception $e ) {
450
-				wc_add_notice( $e->getMessage(), 'error' );
449
+			} catch (Exception $e) {
450
+				wc_add_notice($e->getMessage(), 'error');
451 451
 				return;
452 452
 			}
453 453
 		} else {
454
-			return parent::process_payment( $order_id, $retry, $force_save_source );
454
+			return parent::process_payment($order_id, $retry, $force_save_source);
455 455
 		}
456 456
 	}
457 457
 
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 	 * @param WC_Order $order
461 461
 	 * @return void
462 462
 	 */
463
-	public function process_pre_order_release_payment( $order ) {
463
+	public function process_pre_order_release_payment($order) {
464 464
 		try {
465 465
 			// Define some callbacks if the first attempt fails.
466 466
 			$retry_callbacks = array(
@@ -468,33 +468,33 @@  discard block
 block discarded – undo
468 468
 				'remove_order_customer_before_retry',
469 469
 			);
470 470
 
471
-			while ( 1 ) {
472
-				$source   = $this->prepare_order_source( $order );
473
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
471
+			while (1) {
472
+				$source   = $this->prepare_order_source($order);
473
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
474 474
 
475
-				if ( ! empty( $response->error ) ) {
476
-					if ( 0 === sizeof( $retry_callbacks ) ) {
477
-						throw new Exception( $response->error->message );
475
+				if ( ! empty($response->error)) {
476
+					if (0 === sizeof($retry_callbacks)) {
477
+						throw new Exception($response->error->message);
478 478
 					} else {
479
-						$retry_callback = array_shift( $retry_callbacks );
480
-						call_user_func( array( $this, $retry_callback ), $order );
479
+						$retry_callback = array_shift($retry_callbacks);
480
+						call_user_func(array($this, $retry_callback), $order);
481 481
 					}
482 482
 				} else {
483 483
 					// Successful
484
-					$this->process_response( $response, $order );
484
+					$this->process_response($response, $order);
485 485
 					break;
486 486
 				}
487 487
 			}
488
-		} catch ( Exception $e ) {
488
+		} catch (Exception $e) {
489 489
 			/* translators: error message */
490
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
490
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
491 491
 
492 492
 			// Mark order as failed if not already set,
493 493
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
494
-			if ( ! $order->has_status( 'failed' ) ) {
495
-				$order->update_status( 'failed', $order_note );
494
+			if ( ! $order->has_status('failed')) {
495
+				$order->update_status('failed', $order_note);
496 496
 			} else {
497
-				$order->add_order_note( $order_note );
497
+				$order->add_order_note($order_note);
498 498
 			}
499 499
 		}
500 500
 	}
Please login to merge, or discard this patch.
includes/class-wc-stripe-payment-tokens.php 1 patch
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 	public function __construct() {
22 22
 		self::$_this = $this;
23 23
 
24
-		add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
25
-		add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 );
26
-		add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) );
27
-		add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
28
-		add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
24
+		add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
25
+		add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2);
26
+		add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label'));
27
+		add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
28
+		add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	 * @param string $label
47 47
 	 * @return string $label
48 48
 	 */
49
-	public function normalize_sepa_label( $label ) {
50
-		if ( 'sepa iban' === strtolower( $label ) ) {
49
+	public function normalize_sepa_label($label) {
50
+		if ('sepa iban' === strtolower($label)) {
51 51
 			return 'SEPA IBAN';
52 52
 		}
53 53
 
@@ -62,67 +62,67 @@  discard block
 block discarded – undo
62 62
 	 * @param array $tokens
63 63
 	 * @return array
64 64
 	 */
65
-	public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) {
66
-		if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) {
65
+	public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) {
66
+		if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) {
67 67
 			$stored_tokens = array();
68 68
 
69
-			foreach ( $tokens as $token ) {
69
+			foreach ($tokens as $token) {
70 70
 				$stored_tokens[] = $token->get_token();
71 71
 			}
72 72
 
73
-			if ( 'stripe' === $gateway_id ) {
74
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
73
+			if ('stripe' === $gateway_id) {
74
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
75 75
 				$stripe_sources  = $stripe_customer->get_sources();
76 76
 
77
-				foreach ( $stripe_sources as $source ) {
78
-					if ( isset( $source->type ) && 'card' === $source->type ) {
79
-						if ( ! in_array( $source->id, $stored_tokens ) ) {
77
+				foreach ($stripe_sources as $source) {
78
+					if (isset($source->type) && 'card' === $source->type) {
79
+						if ( ! in_array($source->id, $stored_tokens)) {
80 80
 							$token = new WC_Payment_Token_CC();
81
-							$token->set_token( $source->id );
82
-							$token->set_gateway_id( 'stripe' );
83
-
84
-							if ( 'source' === $source->object && 'card' === $source->type ) {
85
-								$token->set_card_type( strtolower( $source->card->brand ) );
86
-								$token->set_last4( $source->card->last4 );
87
-								$token->set_expiry_month( $source->card->exp_month );
88
-								$token->set_expiry_year( $source->card->exp_year );
81
+							$token->set_token($source->id);
82
+							$token->set_gateway_id('stripe');
83
+
84
+							if ('source' === $source->object && 'card' === $source->type) {
85
+								$token->set_card_type(strtolower($source->card->brand));
86
+								$token->set_last4($source->card->last4);
87
+								$token->set_expiry_month($source->card->exp_month);
88
+								$token->set_expiry_year($source->card->exp_year);
89 89
 							}
90 90
 
91
-							$token->set_user_id( $customer_id );
91
+							$token->set_user_id($customer_id);
92 92
 							$token->save();
93
-							$tokens[ $token->get_id() ] = $token;
93
+							$tokens[$token->get_id()] = $token;
94 94
 						}
95 95
 					} else {
96
-						if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) {
96
+						if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) {
97 97
 							$token = new WC_Payment_Token_CC();
98
-							$token->set_token( $source->id );
99
-							$token->set_gateway_id( 'stripe' );
100
-							$token->set_card_type( strtolower( $source->brand ) );
101
-							$token->set_last4( $source->last4 );
102
-							$token->set_expiry_month( $source->exp_month );
103
-							$token->set_expiry_year( $source->exp_year );
104
-							$token->set_user_id( $customer_id );
98
+							$token->set_token($source->id);
99
+							$token->set_gateway_id('stripe');
100
+							$token->set_card_type(strtolower($source->brand));
101
+							$token->set_last4($source->last4);
102
+							$token->set_expiry_month($source->exp_month);
103
+							$token->set_expiry_year($source->exp_year);
104
+							$token->set_user_id($customer_id);
105 105
 							$token->save();
106
-							$tokens[ $token->get_id() ] = $token;
106
+							$tokens[$token->get_id()] = $token;
107 107
 						}
108 108
 					}
109 109
 				}
110 110
 			}
111 111
 
112
-			if ( 'stripe_sepa' === $gateway_id ) {
113
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
112
+			if ('stripe_sepa' === $gateway_id) {
113
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
114 114
 				$stripe_sources  = $stripe_customer->get_sources();
115 115
 
116
-				foreach ( $stripe_sources as $source ) {
117
-					if ( isset( $source->type ) && 'sepa_debit' === $source->type ) {
118
-						if ( ! in_array( $source->id, $stored_tokens ) ) {
116
+				foreach ($stripe_sources as $source) {
117
+					if (isset($source->type) && 'sepa_debit' === $source->type) {
118
+						if ( ! in_array($source->id, $stored_tokens)) {
119 119
 							$token = new WC_Payment_Token_SEPA();
120
-							$token->set_token( $source->id );
121
-							$token->set_gateway_id( 'stripe_sepa' );
122
-							$token->set_last4( $source->sepa_debit->last4 );
123
-							$token->set_user_id( $customer_id );
120
+							$token->set_token($source->id);
121
+							$token->set_gateway_id('stripe_sepa');
122
+							$token->set_last4($source->sepa_debit->last4);
123
+							$token->set_user_id($customer_id);
124 124
 							$token->save();
125
-							$tokens[ $token->get_id() ] = $token;
125
+							$tokens[$token->get_id()] = $token;
126 126
 						}
127 127
 					}
128 128
 				}
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 	 * @param  WC_Payment_Token $payment_token The payment token associated with this method entry
142 142
 	 * @return array                           Filtered item
143 143
 	 */
144
-	public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) {
145
-		if ( 'sepa' === strtolower( $payment_token->get_type() ) ) {
144
+	public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) {
145
+		if ('sepa' === strtolower($payment_token->get_type())) {
146 146
 			$item['method']['last4'] = $payment_token->get_last4();
147
-			$item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' );
147
+			$item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe');
148 148
 		}
149 149
 
150 150
 		return $item;
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
 	 * @since 3.1.0
157 157
 	 * @version 4.0.0
158 158
 	 */
159
-	public function woocommerce_payment_token_deleted( $token_id, $token ) {
160
-		if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) {
161
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
162
-			$stripe_customer->delete_source( $token->get_token() );
159
+	public function woocommerce_payment_token_deleted($token_id, $token) {
160
+		if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) {
161
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
162
+			$stripe_customer->delete_source($token->get_token());
163 163
 		}
164 164
 	}
165 165
 
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
 	 * @since 3.1.0
170 170
 	 * @version 4.0.0
171 171
 	 */
172
-	public function woocommerce_payment_token_set_default( $token_id ) {
173
-		$token = WC_Payment_Tokens::get( $token_id );
172
+	public function woocommerce_payment_token_set_default($token_id) {
173
+		$token = WC_Payment_Tokens::get($token_id);
174 174
 
175
-		if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) {
176
-			$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
177
-			$stripe_customer->set_default_source( $token->get_token() );
175
+		if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) {
176
+			$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
177
+			$stripe_customer->set_default_source($token->get_token());
178 178
 		}
179 179
 	}
180 180
 }
Please login to merge, or discard this patch.
includes/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +224 added lines, -225 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @since 4.0.5
22 22
 	 * @param array $error
23 23
 	 */
24
-	public function is_retryable_error( $error ) {
24
+	public function is_retryable_error($error) {
25 25
 		return (
26 26
 			'invalid_request_error' === $error->type ||
27 27
 			'idempotency_error' === $error->type ||
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	 * Check if this gateway is enabled
36 36
 	 */
37 37
 	public function is_available() {
38
-		if ( 'yes' === $this->enabled ) {
39
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
38
+		if ('yes' === $this->enabled) {
39
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
40 40
 				return false;
41 41
 			}
42
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
42
+			if ( ! $this->secret_key || ! $this->publishable_key) {
43 43
 				return false;
44 44
 			}
45 45
 			return true;
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	 * @since 4.0.0
55 55
 	 * @version 4.0.0
56 56
 	 */
57
-	public function add_admin_notice( $slug, $class, $message ) {
58
-		$this->notices[ $slug ] = array(
57
+	public function add_admin_notice($slug, $class, $message) {
58
+		$this->notices[$slug] = array(
59 59
 			'class'   => $class,
60 60
 			'message' => $message,
61 61
 		);
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 	 * @version 4.0.0
69 69
 	 */
70 70
 	public function remove_admin_notice() {
71
-		if ( did_action( 'woocommerce_update_options' ) ) {
72
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
71
+		if (did_action('woocommerce_update_options')) {
72
+			remove_action('admin_notices', array($this, 'check_environment'));
73 73
 		}
74 74
 	}
75 75
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @return array
82 82
 	 */
83 83
 	public function payment_icons() {
84
-		return apply_filters( 'wc_stripe_payment_icons', array(
84
+		return apply_filters('wc_stripe_payment_icons', array(
85 85
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
86 86
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
87 87
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
99 99
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
100 100
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
101
-		) );
101
+		));
102 102
 	}
103 103
 
104 104
 	/**
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 	 * @version 4.0.0
110 110
 	 * @param object $order
111 111
 	 */
112
-	public function validate_minimum_order_amount( $order ) {
113
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
112
+	public function validate_minimum_order_amount($order) {
113
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
114 114
 			/* translators: 1) dollar amount */
115
-			throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
115
+			throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100)));
116 116
 		}
117 117
 	}
118 118
 
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 	 * @since 4.0.0
123 123
 	 * @version 4.0.0
124 124
 	 */
125
-	public function get_transaction_url( $order ) {
126
-		if ( $this->testmode ) {
125
+	public function get_transaction_url($order) {
126
+		if ($this->testmode) {
127 127
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
128 128
 		} else {
129 129
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
130 130
 		}
131 131
 
132
-		return parent::get_transaction_url( $order );
132
+		return parent::get_transaction_url($order);
133 133
 	}
134 134
 
135 135
 	/**
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 	 * @since 4.0.0
139 139
 	 * @version 4.0.0
140 140
 	 */
141
-	public function get_stripe_customer_id( $order ) {
142
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
141
+	public function get_stripe_customer_id($order) {
142
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
143 143
 
144
-		if ( empty( $customer ) ) {
144
+		if (empty($customer)) {
145 145
 			// Try to get it via the order.
146
-			if ( WC_Stripe_Helper::is_pre_30() ) {
147
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
146
+			if (WC_Stripe_Helper::is_pre_30()) {
147
+				return get_post_meta($order->id, '_stripe_customer_id', true);
148 148
 			} else {
149
-				return $order->get_meta( '_stripe_customer_id', true );
149
+				return $order->get_meta('_stripe_customer_id', true);
150 150
 			}
151 151
 		} else {
152 152
 			return $customer;
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 	 * @param object $order
164 164
 	 * @param int $id Stripe session id.
165 165
 	 */
166
-	public function get_stripe_return_url( $order = null, $id = null ) {
167
-		if ( is_object( $order ) ) {
168
-			if ( empty( $id ) ) {
166
+	public function get_stripe_return_url($order = null, $id = null) {
167
+		if (is_object($order)) {
168
+			if (empty($id)) {
169 169
 				$id = uniqid();
170 170
 			}
171 171
 
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 				'order_id'       => $order_id,
177 177
 			);
178 178
 
179
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
179
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
180 180
 		}
181 181
 
182
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
182
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
183 183
 	}
184 184
 
185 185
 	/**
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	 * @param  int  $order_id
188 188
 	 * @return boolean
189 189
 	 */
190
-	public function has_subscription( $order_id ) {
191
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
190
+	public function has_subscription($order_id) {
191
+		return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id)));
192 192
 	}
193 193
 
194 194
 	/**
@@ -200,34 +200,33 @@  discard block
 block discarded – undo
200 200
 	 * @param  object $prepared_source
201 201
 	 * @return array()
202 202
 	 */
203
-	public function generate_payment_request( $order, $prepared_source ) {
204
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
205
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
206
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
203
+	public function generate_payment_request($order, $prepared_source) {
204
+		$settings                          = get_option('woocommerce_stripe_settings', array());
205
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
206
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
207 207
 		$post_data                         = array();
208
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
209
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
208
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
209
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
210 210
 		/* translators: 1) blog name 2) order number */
211
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
211
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
212 212
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
213 213
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
214 214
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
215 215
 
216
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
216
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
217 217
 			$post_data['receipt_email'] = $billing_email;
218 218
 		}
219 219
 
220
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
221
-			case 'stripe':
222
-				if ( ! empty( $statement_descriptor ) ) {
223
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
220
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
221
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
222
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
224 223
 				}
225 224
 
226 225
 				$post_data['capture'] = $capture ? 'true' : 'false';
227 226
 				break;
228 227
 			case 'stripe_sepa':
229
-				if ( ! empty( $statement_descriptor ) ) {
230
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
228
+				if ( ! empty($statement_descriptor)) {
229
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
231 230
 				}
232 231
 				break;
233 232
 		}
@@ -235,25 +234,25 @@  discard block
 block discarded – undo
235 234
 		$post_data['expand[]'] = 'balance_transaction';
236 235
 
237 236
 		$metadata = array(
238
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
239
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
237
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
238
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
240 239
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
241 240
 		);
242 241
 
243
-		if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
242
+		if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
244 243
 			$metadata += array(
245 244
 				'payment_type' => 'recurring',
246
-				'site_url'     => esc_url( get_site_url() ),
245
+				'site_url'     => esc_url(get_site_url()),
247 246
 			);
248 247
 		}
249 248
 
250
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source );
249
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source);
251 250
 
252
-		if ( $prepared_source->customer ) {
251
+		if ($prepared_source->customer) {
253 252
 			$post_data['customer'] = $prepared_source->customer;
254 253
 		}
255 254
 
256
-		if ( $prepared_source->source ) {
255
+		if ($prepared_source->source) {
257 256
 			$post_data['source'] = $prepared_source->source;
258 257
 		}
259 258
 
@@ -265,79 +264,79 @@  discard block
 block discarded – undo
265 264
 		 * @param WC_Order $order
266 265
 		 * @param object $source
267 266
 		 */
268
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source );
267
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source);
269 268
 	}
270 269
 
271 270
 	/**
272 271
 	 * Store extra meta data for an order from a Stripe Response.
273 272
 	 */
274
-	public function process_response( $response, $order ) {
275
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
273
+	public function process_response($response, $order) {
274
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
276 275
 
277 276
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
278 277
 
279
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
278
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
280 279
 
281 280
 		// Store charge data.
282
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
281
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
283 282
 
284 283
 		// Store other data such as fees.
285
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
284
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
286 285
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
287 286
 			// values are in the local currency of the Stripe account, not from WC.
288
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
289
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
290
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
291
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
287
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
288
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
289
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
290
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
292 291
 		}
293 292
 
294
-		if ( 'yes' === $captured ) {
293
+		if ('yes' === $captured) {
295 294
 			/**
296 295
 			 * Charge can be captured but in a pending state. Payment methods
297 296
 			 * that are asynchronous may take couple days to clear. Webhook will
298 297
 			 * take care of the status changes.
299 298
 			 */
300
-			if ( 'pending' === $response->status ) {
301
-				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true );
299
+			if ('pending' === $response->status) {
300
+				$order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true);
302 301
 
303
-				if ( ! $order_stock_reduced ) {
304
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
302
+				if ( ! $order_stock_reduced) {
303
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
305 304
 				}
306 305
 
307
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
306
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
308 307
 				/* translators: transaction id */
309
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
308
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
310 309
 			}
311 310
 
312
-			if ( 'succeeded' === $response->status ) {
313
-				$order->payment_complete( $response->id );
311
+			if ('succeeded' === $response->status) {
312
+				$order->payment_complete($response->id);
314 313
 
315 314
 				/* translators: transaction id */
316
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
317
-				$order->add_order_note( $message );
315
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
316
+				$order->add_order_note($message);
318 317
 			}
319 318
 
320
-			if ( 'failed' === $response->status ) {
321
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
322
-				$order->add_order_note( $localized_message );
323
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
319
+			if ('failed' === $response->status) {
320
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
321
+				$order->add_order_note($localized_message);
322
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
324 323
 			}
325 324
 		} else {
326
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
325
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
327 326
 
328
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
329
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
327
+			if ($order->has_status(array('pending', 'failed'))) {
328
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
330 329
 			}
331 330
 
332 331
 			/* translators: transaction id */
333
-			$order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) );
332
+			$order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id));
334 333
 		}
335 334
 
336
-		if ( is_callable( array( $order, 'save' ) ) ) {
335
+		if (is_callable(array($order, 'save'))) {
337 336
 			$order->save();
338 337
 		}
339 338
 
340
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
339
+		do_action('wc_gateway_stripe_process_response', $response, $order);
341 340
 
342 341
 		return $response;
343 342
 	}
@@ -350,10 +349,10 @@  discard block
 block discarded – undo
350 349
 	 * @param int $order_id
351 350
 	 * @return null
352 351
 	 */
353
-	public function send_failed_order_email( $order_id ) {
352
+	public function send_failed_order_email($order_id) {
354 353
 		$emails = WC()->mailer()->get_emails();
355
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
356
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
354
+		if ( ! empty($emails) && ! empty($order_id)) {
355
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
357 356
 		}
358 357
 	}
359 358
 
@@ -365,7 +364,7 @@  discard block
 block discarded – undo
365 364
 	 * @param object $order
366 365
 	 * @return object $details
367 366
 	 */
368
-	public function get_owner_details( $order ) {
367
+	public function get_owner_details($order) {
369 368
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
370 369
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
371 370
 
@@ -375,15 +374,15 @@  discard block
 block discarded – undo
375 374
 		$email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
376 375
 		$phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
377 376
 
378
-		if ( ! empty( $phone ) ) {
377
+		if ( ! empty($phone)) {
379 378
 			$details['phone'] = $phone;
380 379
 		}
381 380
 
382
-		if ( ! empty( $name ) ) {
381
+		if ( ! empty($name)) {
383 382
 			$details['name'] = $name;
384 383
 		}
385 384
 
386
-		if ( ! empty( $email ) ) {
385
+		if ( ! empty($email)) {
387 386
 			$details['email'] = $email;
388 387
 		}
389 388
 
@@ -394,7 +393,7 @@  discard block
 block discarded – undo
394 393
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
395 394
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
396 395
 
397
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
396
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
398 397
 	}
399 398
 
400 399
 	/**
@@ -403,15 +402,15 @@  discard block
 block discarded – undo
403 402
 	 * @since 4.0.3
404 403
 	 * @param string $source_id The source ID to get source object for.
405 404
 	 */
406
-	public function get_source_object( $source_id = '' ) {
407
-		if ( empty( $source_id ) ) {
405
+	public function get_source_object($source_id = '') {
406
+		if (empty($source_id)) {
408 407
 			return '';
409 408
 		}
410 409
 
411
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id );
410
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source_id);
412 411
 
413
-		if ( ! empty( $source_object->error ) ) {
414
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
412
+		if ( ! empty($source_object->error)) {
413
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
415 414
 		}
416 415
 
417 416
 		return $source_object;
@@ -424,11 +423,11 @@  discard block
 block discarded – undo
424 423
 	 * @param object $source_object
425 424
 	 * @return bool
426 425
 	 */
427
-	public function is_3ds_required( $source_object ) {
426
+	public function is_3ds_required($source_object) {
428 427
 		return (
429
-			$source_object && ! empty( $source_object->card ) ) &&
430
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
431
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
428
+			$source_object && ! empty($source_object->card) ) &&
429
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
430
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
432 431
 		);
433 432
 	}
434 433
 
@@ -439,8 +438,8 @@  discard block
 block discarded – undo
439 438
 	 * @param object $source_object
440 439
 	 * @return bool
441 440
 	 */
442
-	public function is_3ds_card( $source_object ) {
443
-		return ( $source_object && 'three_d_secure' === $source_object->type );
441
+	public function is_3ds_card($source_object) {
442
+		return ($source_object && 'three_d_secure' === $source_object->type);
444 443
 	}
445 444
 
446 445
 	/**
@@ -450,8 +449,8 @@  discard block
 block discarded – undo
450 449
 	 * @param object $source_object
451 450
 	 * @return bool
452 451
 	 */
453
-	public function is_prepaid_card( $source_object ) {
454
-		return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding );
452
+	public function is_prepaid_card($source_object) {
453
+		return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding);
455 454
 	}
456 455
 
457 456
 	/**
@@ -461,8 +460,8 @@  discard block
 block discarded – undo
461 460
 	 * @param string $source_id
462 461
 	 * @return bool
463 462
 	 */
464
-	public function is_type_legacy_card( $source_id ) {
465
-		return ( preg_match( '/^card_/', $source_id ) );
463
+	public function is_type_legacy_card($source_id) {
464
+		return (preg_match('/^card_/', $source_id));
466 465
 	}
467 466
 
468 467
 	/**
@@ -475,22 +474,22 @@  discard block
 block discarded – undo
475 474
 	 * @param string $return_url
476 475
 	 * @return mixed
477 476
 	 */
478
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
477
+	public function create_3ds_source($order, $source_object, $return_url = '') {
479 478
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
480 479
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
481
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
480
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
482 481
 
483 482
 		$post_data                   = array();
484
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
485
-		$post_data['currency']       = strtolower( $currency );
483
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
484
+		$post_data['currency']       = strtolower($currency);
486 485
 		$post_data['type']           = 'three_d_secure';
487
-		$post_data['owner']          = $this->get_owner_details( $order );
488
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
489
-		$post_data['redirect']       = array( 'return_url' => $return_url );
486
+		$post_data['owner']          = $this->get_owner_details($order);
487
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
488
+		$post_data['redirect']       = array('return_url' => $return_url);
490 489
 
491
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
490
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
492 491
 
493
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
492
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
494 493
 	}
495 494
 
496 495
 	/**
@@ -506,61 +505,61 @@  discard block
 block discarded – undo
506 505
 	 * @throws Exception When card was not added or for and invalid card.
507 506
 	 * @return object
508 507
 	 */
509
-	public function prepare_source( $user_id, $force_save_source = false ) {
510
-		$customer           = new WC_Stripe_Customer( $user_id );
508
+	public function prepare_source($user_id, $force_save_source = false) {
509
+		$customer           = new WC_Stripe_Customer($user_id);
511 510
 		$set_customer       = true;
512
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
511
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
513 512
 		$source_object      = '';
514 513
 		$source_id          = '';
515 514
 		$wc_token_id        = false;
516
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
515
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
517 516
 		$is_token           = false;
518 517
 
519 518
 		// New CC info was entered and we have a new source to process.
520
-		if ( ! empty( $_POST['stripe_source'] ) ) {
521
-			$source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) );
519
+		if ( ! empty($_POST['stripe_source'])) {
520
+			$source_object = self::get_source_object(wc_clean($_POST['stripe_source']));
522 521
 			$source_id     = $source_object->id;
523 522
 
524 523
 			// This checks to see if customer opted to save the payment method to file.
525
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
524
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
526 525
 
527 526
 			/**
528 527
 			 * This is true if the user wants to store the card to their account.
529 528
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
530 529
 			 * actually reusable. Either that or force_save_source is true.
531 530
 			 */
532
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
533
-				$response = $customer->add_source( $source_object->id );
531
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
532
+				$response = $customer->add_source($source_object->id);
534 533
 
535
-				if ( ! empty( $response->error ) ) {
536
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
534
+				if ( ! empty($response->error)) {
535
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
537 536
 				}
538 537
 			}
539
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
538
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
540 539
 			// Use an existing token, and then process the payment.
541
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
542
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
540
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
541
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
543 542
 
544
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
545
-				WC()->session->set( 'refresh_totals', true );
546
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
543
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
544
+				WC()->session->set('refresh_totals', true);
545
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
547 546
 			}
548 547
 
549 548
 			$source_id = $wc_token->get_token();
550 549
 
551
-			if ( $this->is_type_legacy_card( $source_id ) ) {
550
+			if ($this->is_type_legacy_card($source_id)) {
552 551
 				$is_token = true;
553 552
 			}
554
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
555
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
556
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
553
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
554
+			$stripe_token     = wc_clean($_POST['stripe_token']);
555
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
557 556
 
558 557
 			// This is true if the user wants to store the card to their account.
559
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
560
-				$response = $customer->add_source( $stripe_token );
558
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
559
+				$response = $customer->add_source($stripe_token);
561 560
 
562
-				if ( ! empty( $response->error ) ) {
563
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
561
+				if ( ! empty($response->error)) {
562
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
564 563
 				}
565 564
 			} else {
566 565
 				$set_customer = false;
@@ -569,14 +568,14 @@  discard block
 block discarded – undo
569 568
 			}
570 569
 		}
571 570
 
572
-		if ( ! $set_customer ) {
571
+		if ( ! $set_customer) {
573 572
 			$customer_id = false;
574 573
 		} else {
575 574
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
576 575
 		}
577 576
 
578
-		if ( empty( $source_object ) && ! $is_token ) {
579
-			$source_object = self::get_source_object( $source_id );
577
+		if (empty($source_object) && ! $is_token) {
578
+			$source_object = self::get_source_object($source_id);
580 579
 		}
581 580
 
582 581
 		return (object) array(
@@ -600,37 +599,37 @@  discard block
 block discarded – undo
600 599
 	 * @param object $order
601 600
 	 * @return object
602 601
 	 */
603
-	public function prepare_order_source( $order = null ) {
602
+	public function prepare_order_source($order = null) {
604 603
 		$stripe_customer = new WC_Stripe_Customer();
605 604
 		$stripe_source   = false;
606 605
 		$token_id        = false;
607 606
 
608
-		if ( $order ) {
607
+		if ($order) {
609 608
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
610 609
 
611
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
610
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
612 611
 
613
-			if ( $stripe_customer_id ) {
614
-				$stripe_customer->set_id( $stripe_customer_id );
612
+			if ($stripe_customer_id) {
613
+				$stripe_customer->set_id($stripe_customer_id);
615 614
 			}
616 615
 
617
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
616
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
618 617
 
619 618
 			// Since 4.0.0, we changed card to source so we need to account for that.
620
-			if ( empty( $source_id ) ) {
621
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
619
+			if (empty($source_id)) {
620
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
622 621
 
623 622
 				// Take this opportunity to update the key name.
624
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id );
623
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id);
625 624
 
626
-				if ( is_callable( array( $order, 'save' ) ) ) {
625
+				if (is_callable(array($order, 'save'))) {
627 626
 					$order->save();
628 627
 				}
629 628
 			}
630 629
 
631
-			if ( $source_id ) {
630
+			if ($source_id) {
632 631
 				$stripe_source = $source_id;
633
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
632
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
634 633
 				/*
635 634
 				 * We can attempt to charge the customer's default source
636 635
 				 * by sending empty source id.
@@ -654,27 +653,27 @@  discard block
 block discarded – undo
654 653
 	 * @param WC_Order $order For to which the source applies.
655 654
 	 * @param stdClass $source Source information.
656 655
 	 */
657
-	public function save_source_to_order( $order, $source ) {
656
+	public function save_source_to_order($order, $source) {
658 657
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
659 658
 
660 659
 		// Store source in the order.
661
-		if ( $source->customer ) {
662
-			if ( WC_Stripe_Helper::is_pre_30() ) {
663
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
660
+		if ($source->customer) {
661
+			if (WC_Stripe_Helper::is_pre_30()) {
662
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
664 663
 			} else {
665
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
664
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
666 665
 			}
667 666
 		}
668 667
 
669
-		if ( $source->source ) {
670
-			if ( WC_Stripe_Helper::is_pre_30() ) {
671
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
668
+		if ($source->source) {
669
+			if (WC_Stripe_Helper::is_pre_30()) {
670
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
672 671
 			} else {
673
-				$order->update_meta_data( '_stripe_source_id', $source->source );
672
+				$order->update_meta_data('_stripe_source_id', $source->source);
674 673
 			}
675 674
 		}
676 675
 
677
-		if ( is_callable( array( $order, 'save' ) ) ) {
676
+		if (is_callable(array($order, 'save'))) {
678 677
 			$order->save();
679 678
 		}
680 679
 	}
@@ -688,35 +687,35 @@  discard block
 block discarded – undo
688 687
 	 * @param object $order The order object
689 688
 	 * @param int $balance_transaction_id
690 689
 	 */
691
-	public function update_fees( $order, $balance_transaction_id ) {
690
+	public function update_fees($order, $balance_transaction_id) {
692 691
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
693 692
 
694
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
693
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
695 694
 
696
-		if ( empty( $balance_transaction->error ) ) {
697
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
695
+		if (empty($balance_transaction->error)) {
696
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
698 697
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
699 698
 				// values are in the local currency of the Stripe account, not from WC.
700
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
701
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
699
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
700
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
702 701
 
703 702
 				// Current data fee & net.
704
-				$fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true );
705
-				$net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true );
703
+				$fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true);
704
+				$net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true);
706 705
 
707 706
 				// Calculation.
708 707
 				$fee = (float) $fee_current + (float) $fee_refund;
709 708
 				$net = (float) $net_current + (float) $net_refund;
710 709
 
711
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee );
712
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net );
710
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee);
711
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net);
713 712
 
714
-				if ( is_callable( array( $order, 'save' ) ) ) {
713
+				if (is_callable(array($order, 'save'))) {
715 714
 					$order->save();
716 715
 				}
717 716
 			}
718 717
 		} else {
719
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
718
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
720 719
 		}
721 720
 	}
722 721
 
@@ -729,33 +728,33 @@  discard block
 block discarded – undo
729 728
 	 * @param  float $amount
730 729
 	 * @return bool
731 730
 	 */
732
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
733
-		$order = wc_get_order( $order_id );
731
+	public function process_refund($order_id, $amount = null, $reason = '') {
732
+		$order = wc_get_order($order_id);
734 733
 
735
-		if ( ! $order || ! $order->get_transaction_id() ) {
734
+		if ( ! $order || ! $order->get_transaction_id()) {
736 735
 			return false;
737 736
 		}
738 737
 
739 738
 		$request = array();
740 739
 
741
-		if ( WC_Stripe_Helper::is_pre_30() ) {
742
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
743
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
740
+		if (WC_Stripe_Helper::is_pre_30()) {
741
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
742
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
744 743
 		} else {
745 744
 			$order_currency = $order->get_currency();
746
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
745
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
747 746
 		}
748 747
 
749
-		if ( ! is_null( $amount ) ) {
750
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
748
+		if ( ! is_null($amount)) {
749
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
751 750
 		}
752 751
 
753 752
 		// If order is only authorized, don't pass amount.
754
-		if ( 'yes' !== $captured ) {
755
-			unset( $request['amount'] );
753
+		if ('yes' !== $captured) {
754
+			unset($request['amount']);
756 755
 		}
757 756
 
758
-		if ( $reason ) {
757
+		if ($reason) {
759 758
 			$request['metadata'] = array(
760 759
 				'reason' => $reason,
761 760
 			);
@@ -763,35 +762,35 @@  discard block
 block discarded – undo
763 762
 
764 763
 		$request['charge'] = $order->get_transaction_id();
765 764
 
766
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
765
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
767 766
 
768
-		$request = apply_filters( 'wc_stripe_refund_request', $request, $order );
767
+		$request = apply_filters('wc_stripe_refund_request', $request, $order);
769 768
 
770
-		$response = WC_Stripe_API::request( $request, 'refunds' );
769
+		$response = WC_Stripe_API::request($request, 'refunds');
771 770
 
772
-		if ( ! empty( $response->error ) ) {
773
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
771
+		if ( ! empty($response->error)) {
772
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
774 773
 
775 774
 			return $response;
776 775
 
777
-		} elseif ( ! empty( $response->id ) ) {
778
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id );
776
+		} elseif ( ! empty($response->id)) {
777
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id);
779 778
 
780
-			$amount = wc_price( $response->amount / 100 );
779
+			$amount = wc_price($response->amount / 100);
781 780
 
782
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
783
-				$amount = wc_price( $response->amount );
781
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
782
+				$amount = wc_price($response->amount);
784 783
 			}
785 784
 
786
-			if ( isset( $response->balance_transaction ) ) {
787
-				$this->update_fees( $order, $response->balance_transaction );
785
+			if (isset($response->balance_transaction)) {
786
+				$this->update_fees($order, $response->balance_transaction);
788 787
 			}
789 788
 
790 789
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
791
-			$refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' );
790
+			$refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe');
792 791
 
793
-			$order->add_order_note( $refund_message );
794
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
792
+			$order->add_order_note($refund_message);
793
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
795 794
 
796 795
 			return true;
797 796
 		}
@@ -806,44 +805,44 @@  discard block
 block discarded – undo
806 805
 	 */
807 806
 	public function add_payment_method() {
808 807
 		$error     = false;
809
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
808
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
810 809
 		$source_id = '';
811 810
 
812
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
811
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
813 812
 			$error = true;
814 813
 		}
815 814
 
816
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
815
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
817 816
 
818
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
817
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
819 818
 
820
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
819
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
821 820
 
822
-		if ( isset( $source_object ) ) {
823
-			if ( ! empty( $source_object->error ) ) {
821
+		if (isset($source_object)) {
822
+			if ( ! empty($source_object->error)) {
824 823
 				$error = true;
825 824
 			}
826 825
 
827 826
 			$source_id = $source_object->id;
828
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
829
-			$source_id = wc_clean( $_POST['stripe_token'] );
827
+		} elseif (isset($_POST['stripe_token'])) {
828
+			$source_id = wc_clean($_POST['stripe_token']);
830 829
 		}
831 830
 
832
-		$response = $stripe_customer->add_source( $source_id );
831
+		$response = $stripe_customer->add_source($source_id);
833 832
 
834
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
833
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
835 834
 			$error = true;
836 835
 		}
837 836
 
838
-		if ( $error ) {
839
-			wc_add_notice( $error_msg, 'error' );
840
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
837
+		if ($error) {
838
+			wc_add_notice($error_msg, 'error');
839
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
841 840
 			return;
842 841
 		}
843 842
 
844 843
 		return array(
845 844
 			'result'   => 'success',
846
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
845
+			'redirect' => wc_get_endpoint_url('payment-methods'),
847 846
 		);
848 847
 	}
849 848
 
@@ -860,10 +859,10 @@  discard block
 block discarded – undo
860 859
 		 * Stripe expects Norwegian to only be passed NO.
861 860
 		 * But WP has different dialects.
862 861
 		 */
863
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
862
+		if ('NO' === substr($locale, 3, 2)) {
864 863
 			$locale = 'no';
865 864
 		} else {
866
-			$locale = substr( get_locale(), 0, 2 );
865
+			$locale = substr(get_locale(), 0, 2);
867 866
 		}
868 867
 
869 868
 		return $locale;
@@ -877,9 +876,9 @@  discard block
 block discarded – undo
877 876
 	 * @param string $idempotency_key
878 877
 	 * @param array $request
879 878
 	 */
880
-	public function change_idempotency_key( $idempotency_key, $request ) {
881
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
882
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
879
+	public function change_idempotency_key($idempotency_key, $request) {
880
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
881
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
883 882
 		$count    = $this->retry_interval;
884 883
 
885 884
 		return $request['metadata']['order_id'] . '-' . $count . '-' . $source;
@@ -893,8 +892,8 @@  discard block
 block discarded – undo
893 892
 	 * @since 4.0.6
894 893
 	 * @param array $headers
895 894
 	 */
896
-	public function is_original_request( $headers ) {
897
-		if ( $headers['original-request'] === $headers['request-id'] ) {
895
+	public function is_original_request($headers) {
896
+		if ($headers['original-request'] === $headers['request-id']) {
898 897
 			return true;
899 898
 		}
900 899
 
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-stripe-payment-request.php 1 patch
Spacing   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   4.0.0
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if ( ! defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
@@ -71,36 +71,36 @@  discard block
 block discarded – undo
71 71
 	 */
72 72
 	public function __construct() {
73 73
 		self::$_this                   = $this;
74
-		$this->stripe_settings         = get_option( 'woocommerce_stripe_settings', array() );
75
-		$this->testmode                = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false;
76
-		$this->publishable_key         = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : '';
77
-		$this->secret_key              = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : '';
78
-		$this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout'];
79
-		$this->total_label             = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';
74
+		$this->stripe_settings         = get_option('woocommerce_stripe_settings', array());
75
+		$this->testmode                = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false;
76
+		$this->publishable_key         = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : '';
77
+		$this->secret_key              = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : '';
78
+		$this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout'];
79
+		$this->total_label             = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : '';
80 80
 
81
-		if ( $this->testmode ) {
82
-			$this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : '';
83
-			$this->secret_key      = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : '';
81
+		if ($this->testmode) {
82
+			$this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : '';
83
+			$this->secret_key      = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : '';
84 84
 		}
85 85
 
86
-		$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
86
+		$this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)');
87 87
 
88 88
 		// Checks if Stripe Gateway is enabled.
89
-		if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) {
89
+		if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) {
90 90
 			return;
91 91
 		}
92 92
 
93 93
 		// Checks if Payment Request is enabled.
94
-		if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) {
94
+		if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) {
95 95
 			return;
96 96
 		}
97 97
 
98 98
 		// Don't load for change payment method page.
99
-		if ( isset( $_GET['change_payment_method'] ) ) {
99
+		if (isset($_GET['change_payment_method'])) {
100 100
 			return;
101 101
 		}
102 102
 
103
-		add_action( 'template_redirect', array( $this, 'set_session' ) );
103
+		add_action('template_redirect', array($this, 'set_session'));
104 104
 		$this->init();
105 105
 	}
106 106
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @return bool
112 112
 	 */
113 113
 	public function are_keys_set() {
114
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
114
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
115 115
 			return false;
116 116
 		}
117 117
 
@@ -135,18 +135,18 @@  discard block
 block discarded – undo
135 135
 	 * @since 4.0.0
136 136
 	 */
137 137
 	public function set_session() {
138
-		if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
138
+		if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) {
139 139
 			return;
140 140
 		}
141 141
 
142
-		$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
142
+		$session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler');
143 143
 		$wc_session    = new $session_class();
144 144
 
145
-		if ( version_compare( WC_VERSION, '3.3', '>=' ) ) {
145
+		if (version_compare(WC_VERSION, '3.3', '>=')) {
146 146
 			$wc_session->init();
147 147
 		}
148 148
 
149
-		$wc_session->set_customer_session_cookie( true );
149
+		$wc_session->set_customer_session_cookie(true);
150 150
 	}
151 151
 
152 152
 	/**
@@ -156,40 +156,40 @@  discard block
 block discarded – undo
156 156
 	 * @version 4.0.0
157 157
 	 */
158 158
 	public function init() {
159
-		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
159
+		add_action('wp_enqueue_scripts', array($this, 'scripts'));
160 160
 
161 161
 		/*
162 162
 		 * In order to display the Payment Request button in the correct position,
163 163
 		 * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce,
164 164
 		 * CSS is used to position the button.
165 165
 		 */
166
-		if ( WC_Stripe_Helper::is_pre_30() ) {
167
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 );
168
-			add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 );
166
+		if (WC_Stripe_Helper::is_pre_30()) {
167
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1);
168
+			add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2);
169 169
 		} else {
170
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 );
171
-			add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 );
170
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1);
171
+			add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2);
172 172
 		}
173 173
 
174
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
175
-		add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 );
174
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1);
175
+		add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2);
176 176
 
177
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 );
178
-		add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 );
177
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1);
178
+		add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2);
179 179
 
180
-		add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) );
181
-		add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) );
182
-		add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) );
183
-		add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) );
184
-		add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) );
185
-		add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) );
186
-		add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) );
187
-		add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) );
180
+		add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details'));
181
+		add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options'));
182
+		add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method'));
183
+		add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order'));
184
+		add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart'));
185
+		add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data'));
186
+		add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart'));
187
+		add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors'));
188 188
 
189
-		add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 );
190
-		add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 );
189
+		add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2);
190
+		add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3);
191 191
 
192
-		add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 );
192
+		add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2);
193 193
 	}
194 194
 
195 195
 	/**
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @return string
201 201
 	 */
202 202
 	public function get_button_type() {
203
-		return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
203
+		return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default';
204 204
 	}
205 205
 
206 206
 	/**
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	 * @return string
212 212
 	 */
213 213
 	public function get_button_theme() {
214
-		return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
214
+		return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
215 215
 	}
216 216
 
217 217
 	/**
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 * @return string
223 223
 	 */
224 224
 	public function get_button_height() {
225
-		return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64';
225
+		return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64';
226 226
 	}
227 227
 
228 228
 	/**
@@ -232,40 +232,40 @@  discard block
 block discarded – undo
232 232
 	 * @version 4.0.0
233 233
 	 */
234 234
 	public function get_product_data() {
235
-		if ( ! is_product() ) {
235
+		if ( ! is_product()) {
236 236
 			return false;
237 237
 		}
238 238
 
239 239
 		global $post;
240 240
 
241
-		$product = wc_get_product( $post->ID );
241
+		$product = wc_get_product($post->ID);
242 242
 
243 243
 		$data  = array();
244 244
 		$items = array();
245 245
 
246 246
 		$items[] = array(
247 247
 			'label'  => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(),
248
-			'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
248
+			'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
249 249
 		);
250 250
 
251
-		if ( wc_tax_enabled() ) {
251
+		if (wc_tax_enabled()) {
252 252
 			$items[] = array(
253
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
253
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
254 254
 				'amount'  => 0,
255 255
 				'pending' => true,
256 256
 			);
257 257
 		}
258 258
 
259
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
259
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
260 260
 			$items[] = array(
261
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
261
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
262 262
 				'amount'  => 0,
263 263
 				'pending' => true,
264 264
 			);
265 265
 
266
-			$data['shippingOptions']  = array(
266
+			$data['shippingOptions'] = array(
267 267
 				'id'     => 'pending',
268
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
268
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
269 269
 				'detail' => '',
270 270
 				'amount' => 0,
271 271
 			);
@@ -273,41 +273,41 @@  discard block
 block discarded – undo
273 273
 
274 274
 		$data['displayItems'] = $items;
275 275
 		$data['total'] = array(
276
-			'label'   => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ),
277
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ),
276
+			'label'   => apply_filters('wc_stripe_payment_request_total_label', $this->total_label),
277
+			'amount'  => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()),
278 278
 			'pending' => true,
279 279
 		);
280 280
 
281
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
282
-		$data['currency']        = strtolower( get_woocommerce_currency() );
283
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
281
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
282
+		$data['currency']        = strtolower(get_woocommerce_currency());
283
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
284 284
 
285
-		return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product );
285
+		return apply_filters('wc_stripe_payment_request_product_data', $data, $product);
286 286
 	}
287 287
 
288 288
 	/**
289 289
 	 * Filters the gateway title to reflect Payment Request type
290 290
 	 *
291 291
 	 */
292
-	public function filter_gateway_title( $title, $id ) {
292
+	public function filter_gateway_title($title, $id) {
293 293
 		global $post;
294 294
 
295
-		if ( ! is_object( $post ) ) {
295
+		if ( ! is_object($post)) {
296 296
 			return $title;
297 297
 		}
298 298
 
299
-		if ( WC_Stripe_Helper::is_pre_30() ) {
300
-			$method_title = get_post_meta( $post->ID, '_payment_method_title', true );
299
+		if (WC_Stripe_Helper::is_pre_30()) {
300
+			$method_title = get_post_meta($post->ID, '_payment_method_title', true);
301 301
 		} else {
302
-			$order        = wc_get_order( $post->ID );
303
-			$method_title = is_object( $order ) ? $order->get_payment_method_title() : '';
302
+			$order        = wc_get_order($post->ID);
303
+			$method_title = is_object($order) ? $order->get_payment_method_title() : '';
304 304
 		}
305 305
 
306
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) {
306
+		if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) {
307 307
 			return $method_title;
308 308
 		}
309 309
 
310
-		if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) {
310
+		if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) {
311 311
 			return $method_title;
312 312
 		}
313 313
 
@@ -320,16 +320,16 @@  discard block
 block discarded – undo
320 320
 	 * @since 3.1.4
321 321
 	 * @version 4.0.0
322 322
 	 */
323
-	public function postal_code_validation( $valid, $postcode, $country ) {
323
+	public function postal_code_validation($valid, $postcode, $country) {
324 324
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
325 325
 
326
-		if ( ! isset( $gateways['stripe'] ) ) {
326
+		if ( ! isset($gateways['stripe'])) {
327 327
 			return $valid;
328 328
 		}
329 329
 
330
-		$payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : '';
330
+		$payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : '';
331 331
 
332
-		if ( 'apple_pay' !== $payment_request_type ) {
332
+		if ('apple_pay' !== $payment_request_type) {
333 333
 			return $valid;
334 334
 		}
335 335
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 		 * the order and not let it go through. The remedy for now is just to remove this validation.
340 340
 		 * Note that this only works with shipping providers that don't validate full postal codes.
341 341
 		 */
342
-		if ( 'GB' === $country || 'CA' === $country ) {
342
+		if ('GB' === $country || 'CA' === $country) {
343 343
 			return true;
344 344
 		}
345 345
 
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 	 * @param int $order_id
355 355
 	 * @param array $posted_data The posted data from checkout form.
356 356
 	 */
357
-	public function add_order_meta( $order_id, $posted_data ) {
358
-		if ( empty( $_POST['payment_request_type'] ) ) {
357
+	public function add_order_meta($order_id, $posted_data) {
358
+		if (empty($_POST['payment_request_type'])) {
359 359
 			return;
360 360
 		}
361 361
 
362
-		$order = wc_get_order( $order_id );
362
+		$order = wc_get_order($order_id);
363 363
 
364
-		$payment_request_type = wc_clean( $_POST['payment_request_type'] );
364
+		$payment_request_type = wc_clean($_POST['payment_request_type']);
365 365
 
366
-		if ( 'apple_pay' === $payment_request_type ) {
367
-			if ( WC_Stripe_Helper::is_pre_30() ) {
368
-				update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' );
366
+		if ('apple_pay' === $payment_request_type) {
367
+			if (WC_Stripe_Helper::is_pre_30()) {
368
+				update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)');
369 369
 			} else {
370
-				$order->set_payment_method_title( 'Apple Pay (Stripe)' );
370
+				$order->set_payment_method_title('Apple Pay (Stripe)');
371 371
 				$order->save();
372 372
 			}
373 373
 		}
374 374
 
375
-		if ( 'payment_request_api' === $payment_request_type ) {
376
-			if ( WC_Stripe_Helper::is_pre_30() ) {
377
-				update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' );
375
+		if ('payment_request_api' === $payment_request_type) {
376
+			if (WC_Stripe_Helper::is_pre_30()) {
377
+				update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)');
378 378
 			} else {
379
-				$order->set_payment_method_title( 'Chrome Payment Request (Stripe)' );
379
+				$order->set_payment_method_title('Chrome Payment Request (Stripe)');
380 380
 				$order->save();
381 381
 			}
382 382
 		}
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
 	 * @return array
391 391
 	 */
392 392
 	public function supported_product_types() {
393
-		return apply_filters( 'wc_stripe_payment_request_supported_types', array(
393
+		return apply_filters('wc_stripe_payment_request_supported_types', array(
394 394
 			'simple',
395 395
 			'variable',
396 396
 			'variation',
397
-		) );
397
+		));
398 398
 	}
399 399
 
400 400
 	/**
@@ -405,15 +405,15 @@  discard block
 block discarded – undo
405 405
 	 * @return bool
406 406
 	 */
407 407
 	public function allowed_items_in_cart() {
408
-		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
409
-			$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
408
+		foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
409
+			$_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
410 410
 
411
-			if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) {
411
+			if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) {
412 412
 				return false;
413 413
 			}
414 414
 
415 415
 			// Pre Orders compatbility where we don't support charge upon release.
416
-			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() ) ) {
416
+			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())) {
417 417
 				return false;
418 418
 			}
419 419
 		}
@@ -429,82 +429,82 @@  discard block
 block discarded – undo
429 429
 	 */
430 430
 	public function scripts() {
431 431
 		// If keys are not set bail.
432
-		if ( ! $this->are_keys_set() ) {
433
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
432
+		if ( ! $this->are_keys_set()) {
433
+			WC_Stripe_Logger::log('Keys are not set correctly.');
434 434
 			return;
435 435
 		}
436 436
 
437 437
 		// If no SSL bail.
438
-		if ( ! $this->testmode && ! is_ssl() ) {
439
-			WC_Stripe_Logger::log( 'Stripe requires SSL.' );
438
+		if ( ! $this->testmode && ! is_ssl()) {
439
+			WC_Stripe_Logger::log('Stripe requires SSL.');
440 440
 			return;
441 441
 		}
442 442
 
443
-		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
443
+		if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
444 444
 			return;
445 445
 		}
446 446
 
447
-		if ( is_product() ) {
447
+		if (is_product()) {
448 448
 			global $post;
449 449
 
450
-			$product = wc_get_product( $post->ID );
450
+			$product = wc_get_product($post->ID);
451 451
 
452
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
452
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
453 453
 				return;
454 454
 			}
455 455
 
456
-			if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
456
+			if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
457 457
 				return;
458 458
 			}
459 459
 		}
460 460
 
461
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
461
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
462 462
 
463
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
464
-		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 );
463
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
464
+		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);
465 465
 
466 466
 		wp_localize_script(
467 467
 			'wc_stripe_payment_request',
468 468
 			'wc_stripe_payment_request_params',
469 469
 			array(
470
-				'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
470
+				'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'),
471 471
 				'stripe'   => array(
472 472
 					'key'                => $this->publishable_key,
473
-					'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no',
473
+					'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no',
474 474
 				),
475 475
 				'nonce'    => array(
476
-					'payment'                        => wp_create_nonce( 'wc-stripe-payment-request' ),
477
-					'shipping'                       => wp_create_nonce( 'wc-stripe-payment-request-shipping' ),
478
-					'update_shipping'                => wp_create_nonce( 'wc-stripe-update-shipping-method' ),
479
-					'checkout'                       => wp_create_nonce( 'woocommerce-process_checkout' ),
480
-					'add_to_cart'                    => wp_create_nonce( 'wc-stripe-add-to-cart' ),
481
-					'get_selected_product_data'      => wp_create_nonce( 'wc-stripe-get-selected-product-data' ),
482
-					'log_errors'                     => wp_create_nonce( 'wc-stripe-log-errors' ),
483
-					'clear_cart'                     => wp_create_nonce( 'wc-stripe-clear-cart' ),
476
+					'payment'                        => wp_create_nonce('wc-stripe-payment-request'),
477
+					'shipping'                       => wp_create_nonce('wc-stripe-payment-request-shipping'),
478
+					'update_shipping'                => wp_create_nonce('wc-stripe-update-shipping-method'),
479
+					'checkout'                       => wp_create_nonce('woocommerce-process_checkout'),
480
+					'add_to_cart'                    => wp_create_nonce('wc-stripe-add-to-cart'),
481
+					'get_selected_product_data'      => wp_create_nonce('wc-stripe-get-selected-product-data'),
482
+					'log_errors'                     => wp_create_nonce('wc-stripe-log-errors'),
483
+					'clear_cart'                     => wp_create_nonce('wc-stripe-clear-cart'),
484 484
 				),
485 485
 				'i18n'     => array(
486
-					'no_prepaid_card'  => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ),
486
+					'no_prepaid_card'  => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'),
487 487
 					/* translators: Do not translate the [option] placeholder */
488
-					'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ),
488
+					'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'),
489 489
 				),
490 490
 				'checkout' => array(
491 491
 					'url'            => wc_get_checkout_url(),
492
-					'currency_code'  => strtolower( get_woocommerce_currency() ),
493
-					'country_code'   => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
492
+					'currency_code'  => strtolower(get_woocommerce_currency()),
493
+					'country_code'   => substr(get_option('woocommerce_default_country'), 0, 2),
494 494
 					'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no',
495 495
 				),
496 496
 				'button' => array(
497 497
 					'type'   => $this->get_button_type(),
498 498
 					'theme'  => $this->get_button_theme(),
499 499
 					'height' => $this->get_button_height(),
500
-					'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US.
500
+					'locale' => substr(get_locale(), 0, 2), // Default format is en_US.
501 501
 				),
502 502
 				'is_product_page' => is_product(),
503 503
 				'product'         => $this->get_product_data(),
504 504
 			)
505 505
 		);
506 506
 
507
-		wp_enqueue_script( 'wc_stripe_payment_request' );
507
+		wp_enqueue_script('wc_stripe_payment_request');
508 508
 	}
509 509
 
510 510
 	/**
@@ -516,39 +516,39 @@  discard block
 block discarded – undo
516 516
 	public function display_payment_request_button_html() {
517 517
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
518 518
 
519
-		if ( ! isset( $gateways['stripe'] ) ) {
519
+		if ( ! isset($gateways['stripe'])) {
520 520
 			return;
521 521
 		}
522 522
 
523
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
523
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
524 524
 			return;
525 525
 		}
526 526
 
527
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
527
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
528 528
 			return;
529 529
 		}
530 530
 
531
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
531
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
532 532
 			return;
533 533
 		}
534 534
 
535
-		if ( is_product() ) {
535
+		if (is_product()) {
536 536
 			global $post;
537 537
 
538
-			$product = wc_get_product( $post->ID );
538
+			$product = wc_get_product($post->ID);
539 539
 
540
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
540
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
541 541
 				return;
542 542
 			}
543 543
 
544 544
 			// Pre Orders charge upon release not supported.
545
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
546
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
545
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
546
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
547 547
 				return;
548 548
 			}
549 549
 		} else {
550
-			if ( ! $this->allowed_items_in_cart() ) {
551
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
550
+			if ( ! $this->allowed_items_in_cart()) {
551
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
552 552
 				return;
553 553
 			}
554 554
 		}
@@ -570,44 +570,44 @@  discard block
 block discarded – undo
570 570
 	public function display_payment_request_button_separator_html() {
571 571
 		$gateways = WC()->payment_gateways->get_available_payment_gateways();
572 572
 
573
-		if ( ! isset( $gateways['stripe'] ) ) {
573
+		if ( ! isset($gateways['stripe'])) {
574 574
 			return;
575 575
 		}
576 576
 
577
-		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
577
+		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) {
578 578
 			return;
579 579
 		}
580 580
 
581
-		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
581
+		if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) {
582 582
 			return;
583 583
 		}
584 584
 
585
-		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
585
+		if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) {
586 586
 			return;
587 587
 		}
588 588
 
589
-		if ( is_product() ) {
589
+		if (is_product()) {
590 590
 			global $post;
591 591
 
592
-			$product = wc_get_product( $post->ID );
592
+			$product = wc_get_product($post->ID);
593 593
 
594
-			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
594
+			if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) {
595 595
 				return;
596 596
 			}
597 597
 
598 598
 			// Pre Orders charge upon release not supported.
599
-			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
600
-				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
599
+			if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
600
+				WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )');
601 601
 				return;
602 602
 			}
603 603
 		} else {
604
-			if ( ! $this->allowed_items_in_cart() ) {
605
-				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
604
+			if ( ! $this->allowed_items_in_cart()) {
605
+				WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )');
606 606
 				return;
607 607
 			}
608 608
 		}
609 609
 		?>
610
-		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> &mdash;</p>
610
+		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> &mdash;</p>
611 611
 		<?php
612 612
 	}
613 613
 
@@ -618,11 +618,11 @@  discard block
 block discarded – undo
618 618
 	 * @version 4.0.0
619 619
 	 */
620 620
 	public function ajax_log_errors() {
621
-		check_ajax_referer( 'wc-stripe-log-errors', 'security' );
621
+		check_ajax_referer('wc-stripe-log-errors', 'security');
622 622
 
623
-		$errors = wc_clean( stripslashes( $_POST['errors'] ) );
623
+		$errors = wc_clean(stripslashes($_POST['errors']));
624 624
 
625
-		WC_Stripe_Logger::log( $errors );
625
+		WC_Stripe_Logger::log($errors);
626 626
 
627 627
 		exit;
628 628
 	}
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 	 * @version 4.0.0
635 635
 	 */
636 636
 	public function ajax_clear_cart() {
637
-		check_ajax_referer( 'wc-stripe-clear-cart', 'security' );
637
+		check_ajax_referer('wc-stripe-clear-cart', 'security');
638 638
 
639 639
 		WC()->cart->empty_cart();
640 640
 		exit;
@@ -644,10 +644,10 @@  discard block
 block discarded – undo
644 644
 	 * Get cart details.
645 645
 	 */
646 646
 	public function ajax_get_cart_details() {
647
-		check_ajax_referer( 'wc-stripe-payment-request', 'security' );
647
+		check_ajax_referer('wc-stripe-payment-request', 'security');
648 648
 
649
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
650
-			define( 'WOOCOMMERCE_CART', true );
649
+		if ( ! defined('WOOCOMMERCE_CART')) {
650
+			define('WOOCOMMERCE_CART', true);
651 651
 		}
652 652
 
653 653
 		WC()->cart->calculate_totals();
@@ -658,14 +658,14 @@  discard block
 block discarded – undo
658 658
 		$data = array(
659 659
 			'shipping_required' => WC()->cart->needs_shipping(),
660 660
 			'order_data'        => array(
661
-				'currency'        => strtolower( $currency ),
662
-				'country_code'    => substr( get_option( 'woocommerce_default_country' ), 0, 2 ),
661
+				'currency'        => strtolower($currency),
662
+				'country_code'    => substr(get_option('woocommerce_default_country'), 0, 2),
663 663
 			),
664 664
 		);
665 665
 
666 666
 		$data['order_data'] += $this->build_display_items();
667 667
 
668
-		wp_send_json( $data );
668
+		wp_send_json($data);
669 669
 	}
670 670
 
671 671
 	/**
@@ -676,47 +676,47 @@  discard block
 block discarded – undo
676 676
 	 * @see WC_Shipping::get_packages().
677 677
 	 */
678 678
 	public function ajax_get_shipping_options() {
679
-		check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' );
679
+		check_ajax_referer('wc-stripe-payment-request-shipping', 'security');
680 680
 
681 681
 		try {
682 682
 			// Set the shipping package.
683
-			$posted = filter_input_array( INPUT_POST, array(
683
+			$posted = filter_input_array(INPUT_POST, array(
684 684
 				'country'   => FILTER_SANITIZE_STRING,
685 685
 				'state'     => FILTER_SANITIZE_STRING,
686 686
 				'postcode'  => FILTER_SANITIZE_STRING,
687 687
 				'city'      => FILTER_SANITIZE_STRING,
688 688
 				'address'   => FILTER_SANITIZE_STRING,
689 689
 				'address_2' => FILTER_SANITIZE_STRING,
690
-			) );
690
+			));
691 691
 
692
-			$this->calculate_shipping( $posted );
692
+			$this->calculate_shipping($posted);
693 693
 
694 694
 			// Set the shipping options.
695 695
 			$data     = array();
696 696
 			$packages = WC()->shipping->get_packages();
697 697
 
698
-			if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) {
699
-				foreach ( $packages as $package_key => $package ) {
700
-					if ( empty( $package['rates'] ) ) {
701
-						throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
698
+			if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) {
699
+				foreach ($packages as $package_key => $package) {
700
+					if (empty($package['rates'])) {
701
+						throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
702 702
 					}
703 703
 
704
-					foreach ( $package['rates'] as $key => $rate ) {
704
+					foreach ($package['rates'] as $key => $rate) {
705 705
 						$data['shipping_options'][] = array(
706 706
 							'id'       => $rate->id,
707 707
 							'label'    => $rate->label,
708 708
 							'detail'   => '',
709
-							'amount'   => WC_Stripe_Helper::get_stripe_amount( $rate->cost ),
709
+							'amount'   => WC_Stripe_Helper::get_stripe_amount($rate->cost),
710 710
 						);
711 711
 					}
712 712
 				}
713 713
 			} else {
714
-				throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) );
714
+				throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe'));
715 715
 			}
716 716
 
717
-			if ( isset( $data[0] ) ) {
717
+			if (isset($data[0])) {
718 718
 				// Auto select the first shipping method.
719
-				WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) );
719
+				WC()->session->set('chosen_shipping_methods', array($data[0]['id']));
720 720
 			}
721 721
 
722 722
 			WC()->cart->calculate_totals();
@@ -724,12 +724,12 @@  discard block
 block discarded – undo
724 724
 			$data += $this->build_display_items();
725 725
 			$data['result'] = 'success';
726 726
 
727
-			wp_send_json( $data );
728
-		} catch ( Exception $e ) {
727
+			wp_send_json($data);
728
+		} catch (Exception $e) {
729 729
 			$data += $this->build_display_items();
730 730
 			$data['result'] = 'invalid_shipping_address';
731 731
 
732
-			wp_send_json( $data );
732
+			wp_send_json($data);
733 733
 		}
734 734
 	}
735 735
 
@@ -737,22 +737,22 @@  discard block
 block discarded – undo
737 737
 	 * Update shipping method.
738 738
 	 */
739 739
 	public function ajax_update_shipping_method() {
740
-		check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' );
740
+		check_ajax_referer('wc-stripe-update-shipping-method', 'security');
741 741
 
742
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
743
-			define( 'WOOCOMMERCE_CART', true );
742
+		if ( ! defined('WOOCOMMERCE_CART')) {
743
+			define('WOOCOMMERCE_CART', true);
744 744
 		}
745 745
 
746
-		$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
747
-		$shipping_method         = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
746
+		$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
747
+		$shipping_method         = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
748 748
 
749
-		if ( is_array( $shipping_method ) ) {
750
-			foreach ( $shipping_method as $i => $value ) {
751
-				$chosen_shipping_methods[ $i ] = wc_clean( $value );
749
+		if (is_array($shipping_method)) {
750
+			foreach ($shipping_method as $i => $value) {
751
+				$chosen_shipping_methods[$i] = wc_clean($value);
752 752
 			}
753 753
 		}
754 754
 
755
-		WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
755
+		WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
756 756
 
757 757
 		WC()->cart->calculate_totals();
758 758
 
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
 		$data += $this->build_display_items();
761 761
 		$data['result'] = 'success';
762 762
 
763
-		wp_send_json( $data );
763
+		wp_send_json($data);
764 764
 	}
765 765
 
766 766
 	/**
@@ -771,31 +771,31 @@  discard block
 block discarded – undo
771 771
 	 * @return array $data
772 772
 	 */
773 773
 	public function ajax_get_selected_product_data() {
774
-		check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' );
774
+		check_ajax_referer('wc-stripe-get-selected-product-data', 'security');
775 775
 
776
-		$product_id = absint( $_POST['product_id'] );
777
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
776
+		$product_id = absint($_POST['product_id']);
777
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
778 778
 
779
-		$product = wc_get_product( $product_id );
779
+		$product = wc_get_product($product_id);
780 780
 
781
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
782
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
781
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
782
+			$attributes = array_map('wc_clean', $_POST['attributes']);
783 783
 
784
-			if ( WC_Stripe_Helper::is_pre_30() ) {
785
-				$variation_id = $product->get_matching_variation( $attributes );
784
+			if (WC_Stripe_Helper::is_pre_30()) {
785
+				$variation_id = $product->get_matching_variation($attributes);
786 786
 			} else {
787
-				$data_store = WC_Data_Store::load( 'product' );
788
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
787
+				$data_store = WC_Data_Store::load('product');
788
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
789 789
 			}
790 790
 
791
-			if ( ! empty( $variation_id ) ) {
792
-				$product = wc_get_product( $variation_id );
791
+			if ( ! empty($variation_id)) {
792
+				$product = wc_get_product($variation_id);
793 793
 			}
794
-		} elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
795
-			$product = wc_get_product( $product_id );
794
+		} elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
795
+			$product = wc_get_product($product_id);
796 796
 		}
797 797
 
798
-		$total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() );
798
+		$total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price());
799 799
 
800 800
 		$quantity_label = 1 < $qty ? ' (x' . $qty . ')' : '';
801 801
 
@@ -803,28 +803,28 @@  discard block
 block discarded – undo
803 803
 		$items = array();
804 804
 
805 805
 		$items[] = array(
806
-			'label'  => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label,
807
-			'amount' => WC_Stripe_Helper::get_stripe_amount( $total ),
806
+			'label'  => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label,
807
+			'amount' => WC_Stripe_Helper::get_stripe_amount($total),
808 808
 		);
809 809
 
810
-		if ( wc_tax_enabled() ) {
810
+		if (wc_tax_enabled()) {
811 811
 			$items[] = array(
812
-				'label'   => __( 'Tax', 'woocommerce-gateway-stripe' ),
812
+				'label'   => __('Tax', 'woocommerce-gateway-stripe'),
813 813
 				'amount'  => 0,
814 814
 				'pending' => true,
815 815
 			);
816 816
 		}
817 817
 
818
-		if ( wc_shipping_enabled() && $product->needs_shipping() ) {
818
+		if (wc_shipping_enabled() && $product->needs_shipping()) {
819 819
 			$items[] = array(
820
-				'label'   => __( 'Shipping', 'woocommerce-gateway-stripe' ),
820
+				'label'   => __('Shipping', 'woocommerce-gateway-stripe'),
821 821
 				'amount'  => 0,
822 822
 				'pending' => true,
823 823
 			);
824 824
 
825
-			$data['shippingOptions']  = array(
825
+			$data['shippingOptions'] = array(
826 826
 				'id'     => 'pending',
827
-				'label'  => __( 'Pending', 'woocommerce-gateway-stripe' ),
827
+				'label'  => __('Pending', 'woocommerce-gateway-stripe'),
828 828
 				'detail' => '',
829 829
 				'amount' => 0,
830 830
 			);
@@ -833,15 +833,15 @@  discard block
 block discarded – undo
833 833
 		$data['displayItems'] = $items;
834 834
 		$data['total'] = array(
835 835
 			'label'   => $this->total_label,
836
-			'amount'  => WC_Stripe_Helper::get_stripe_amount( $total ),
836
+			'amount'  => WC_Stripe_Helper::get_stripe_amount($total),
837 837
 			'pending' => true,
838 838
 		);
839 839
 
840
-		$data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() );
841
-		$data['currency']        = strtolower( get_woocommerce_currency() );
842
-		$data['country_code']    = substr( get_option( 'woocommerce_default_country' ), 0, 2 );
840
+		$data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping());
841
+		$data['currency']        = strtolower(get_woocommerce_currency());
842
+		$data['country_code']    = substr(get_option('woocommerce_default_country'), 0, 2);
843 843
 
844
-		wp_send_json( $data );
844
+		wp_send_json($data);
845 845
 	}
846 846
 
847 847
 	/**
@@ -852,37 +852,37 @@  discard block
 block discarded – undo
852 852
 	 * @return array $data
853 853
 	 */
854 854
 	public function ajax_add_to_cart() {
855
-		check_ajax_referer( 'wc-stripe-add-to-cart', 'security' );
855
+		check_ajax_referer('wc-stripe-add-to-cart', 'security');
856 856
 
857
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
858
-			define( 'WOOCOMMERCE_CART', true );
857
+		if ( ! defined('WOOCOMMERCE_CART')) {
858
+			define('WOOCOMMERCE_CART', true);
859 859
 		}
860 860
 
861 861
 		WC()->shipping->reset_shipping();
862 862
 
863
-		$product_id = absint( $_POST['product_id'] );
864
-		$qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] );
863
+		$product_id = absint($_POST['product_id']);
864
+		$qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']);
865 865
 
866
-		$product = wc_get_product( $product_id );
866
+		$product = wc_get_product($product_id);
867 867
 
868 868
 		// First empty the cart to prevent wrong calculation.
869 869
 		WC()->cart->empty_cart();
870 870
 
871
-		if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) {
872
-			$attributes = array_map( 'wc_clean', $_POST['attributes'] );
871
+		if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) {
872
+			$attributes = array_map('wc_clean', $_POST['attributes']);
873 873
 
874
-			if ( WC_Stripe_Helper::is_pre_30() ) {
875
-				$variation_id = $product->get_matching_variation( $attributes );
874
+			if (WC_Stripe_Helper::is_pre_30()) {
875
+				$variation_id = $product->get_matching_variation($attributes);
876 876
 			} else {
877
-				$data_store = WC_Data_Store::load( 'product' );
878
-				$variation_id = $data_store->find_matching_product_variation( $product, $attributes );
877
+				$data_store = WC_Data_Store::load('product');
878
+				$variation_id = $data_store->find_matching_product_variation($product, $attributes);
879 879
 			}
880 880
 
881
-			WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes );
881
+			WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes);
882 882
 		}
883 883
 
884
-		if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) {
885
-			WC()->cart->add_to_cart( $product->get_id(), $qty );
884
+		if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) {
885
+			WC()->cart->add_to_cart($product->get_id(), $qty);
886 886
 		}
887 887
 
888 888
 		WC()->cart->calculate_totals();
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 		$data += $this->build_display_items();
892 892
 		$data['result'] = 'success';
893 893
 
894
-		wp_send_json( $data );
894
+		wp_send_json($data);
895 895
 	}
896 896
 
897 897
 	/**
@@ -904,31 +904,31 @@  discard block
 block discarded – undo
904 904
 	 * @version 4.0.0
905 905
 	 */
906 906
 	public function normalize_state() {
907
-		$billing_country  = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : '';
908
-		$shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : '';
909
-		$billing_state    = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : '';
910
-		$shipping_state   = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : '';
907
+		$billing_country  = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : '';
908
+		$shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : '';
909
+		$billing_state    = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : '';
910
+		$shipping_state   = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : '';
911 911
 
912
-		if ( $billing_state && $billing_country ) {
913
-			$valid_states = WC()->countries->get_states( $billing_country );
912
+		if ($billing_state && $billing_country) {
913
+			$valid_states = WC()->countries->get_states($billing_country);
914 914
 
915 915
 			// Valid states found for country.
916
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
917
-				foreach ( $valid_states as $state_abbr => $state ) {
918
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) {
916
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
917
+				foreach ($valid_states as $state_abbr => $state) {
918
+					if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) {
919 919
 						$_POST['billing_state'] = $state_abbr;
920 920
 					}
921 921
 				}
922 922
 			}
923 923
 		}
924 924
 
925
-		if ( $shipping_state && $shipping_country ) {
926
-			$valid_states = WC()->countries->get_states( $shipping_country );
925
+		if ($shipping_state && $shipping_country) {
926
+			$valid_states = WC()->countries->get_states($shipping_country);
927 927
 
928 928
 			// Valid states found for country.
929
-			if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) {
930
-				foreach ( $valid_states as $state_abbr => $state ) {
931
-					if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) {
929
+			if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) {
930
+				foreach ($valid_states as $state_abbr => $state) {
931
+					if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) {
932 932
 						$_POST['shipping_state'] = $state_abbr;
933 933
 					}
934 934
 				}
@@ -943,19 +943,19 @@  discard block
 block discarded – undo
943 943
 	 * @version 4.0.0
944 944
 	 */
945 945
 	public function ajax_create_order() {
946
-		if ( WC()->cart->is_empty() ) {
947
-			wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
946
+		if (WC()->cart->is_empty()) {
947
+			wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe'));
948 948
 		}
949 949
 
950
-		if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
951
-			define( 'WOOCOMMERCE_CHECKOUT', true );
950
+		if ( ! defined('WOOCOMMERCE_CHECKOUT')) {
951
+			define('WOOCOMMERCE_CHECKOUT', true);
952 952
 		}
953 953
 
954 954
 		$this->normalize_state();
955 955
 
956 956
 		WC()->checkout()->process_checkout();
957 957
 
958
-		die( 0 );
958
+		die(0);
959 959
 	}
960 960
 
961 961
 	/**
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 	 * @version 4.0.0
966 966
 	 * @param array $address
967 967
 	 */
968
-	protected function calculate_shipping( $address = array() ) {
968
+	protected function calculate_shipping($address = array()) {
969 969
 		global $states;
970 970
 
971 971
 		$country   = $address['country'];
@@ -982,28 +982,28 @@  discard block
 block discarded – undo
982 982
 		 * In some versions of Chrome, state can be a full name. So we need
983 983
 		 * to convert that to abbreviation as WC is expecting that.
984 984
 		 */
985
-		if ( 2 < strlen( $state ) ) {
986
-			$state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] );
985
+		if (2 < strlen($state)) {
986
+			$state = array_search(ucfirst(strtolower($state)), $states[$country]);
987 987
 		}
988 988
 
989 989
 		WC()->shipping->reset_shipping();
990 990
 
991
-		if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) {
992
-			$postcode = wc_format_postcode( $postcode, $country );
991
+		if ($postcode && WC_Validation::is_postcode($postcode, $country)) {
992
+			$postcode = wc_format_postcode($postcode, $country);
993 993
 		}
994 994
 
995
-		if ( $country ) {
996
-			WC()->customer->set_location( $country, $state, $postcode, $city );
997
-			WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
995
+		if ($country) {
996
+			WC()->customer->set_location($country, $state, $postcode, $city);
997
+			WC()->customer->set_shipping_location($country, $state, $postcode, $city);
998 998
 		} else {
999 999
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base();
1000 1000
 			WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base();
1001 1001
 		}
1002 1002
 
1003
-		if ( WC_Stripe_Helper::is_pre_30() ) {
1004
-			WC()->customer->calculated_shipping( true );
1003
+		if (WC_Stripe_Helper::is_pre_30()) {
1004
+			WC()->customer->calculated_shipping(true);
1005 1005
 		} else {
1006
-			WC()->customer->set_calculated_shipping( true );
1006
+			WC()->customer->set_calculated_shipping(true);
1007 1007
 			WC()->customer->save();
1008 1008
 		}
1009 1009
 
@@ -1020,17 +1020,17 @@  discard block
 block discarded – undo
1020 1020
 		$packages[0]['destination']['address']   = $address_1;
1021 1021
 		$packages[0]['destination']['address_2'] = $address_2;
1022 1022
 
1023
-		foreach ( WC()->cart->get_cart() as $item ) {
1024
-			if ( $item['data']->needs_shipping() ) {
1025
-				if ( isset( $item['line_total'] ) ) {
1023
+		foreach (WC()->cart->get_cart() as $item) {
1024
+			if ($item['data']->needs_shipping()) {
1025
+				if (isset($item['line_total'])) {
1026 1026
 					$packages[0]['contents_cost'] += $item['line_total'];
1027 1027
 				}
1028 1028
 			}
1029 1029
 		}
1030 1030
 
1031
-		$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );
1031
+		$packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
1032 1032
 
1033
-		WC()->shipping->calculate_shipping( $packages );
1033
+		WC()->shipping->calculate_shipping($packages);
1034 1034
 	}
1035 1035
 
1036 1036
 	/**
@@ -1039,19 +1039,19 @@  discard block
 block discarded – undo
1039 1039
 	 * @since 3.1.0
1040 1040
 	 * @version 4.0.0
1041 1041
 	 */
1042
-	protected function build_shipping_methods( $shipping_methods ) {
1043
-		if ( empty( $shipping_methods ) ) {
1042
+	protected function build_shipping_methods($shipping_methods) {
1043
+		if (empty($shipping_methods)) {
1044 1044
 			return array();
1045 1045
 		}
1046 1046
 
1047 1047
 		$shipping = array();
1048 1048
 
1049
-		foreach ( $shipping_methods as $method ) {
1049
+		foreach ($shipping_methods as $method) {
1050 1050
 			$shipping[] = array(
1051 1051
 				'id'         => $method['id'],
1052 1052
 				'label'      => $method['label'],
1053 1053
 				'detail'     => '',
1054
-				'amount'     => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ),
1054
+				'amount'     => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']),
1055 1055
 			);
1056 1056
 		}
1057 1057
 
@@ -1065,69 +1065,69 @@  discard block
 block discarded – undo
1065 1065
 	 * @version 4.0.0
1066 1066
 	 */
1067 1067
 	protected function build_display_items() {
1068
-		if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
1069
-			define( 'WOOCOMMERCE_CART', true );
1068
+		if ( ! defined('WOOCOMMERCE_CART')) {
1069
+			define('WOOCOMMERCE_CART', true);
1070 1070
 		}
1071 1071
 
1072 1072
 		$items    = array();
1073 1073
 		$subtotal = 0;
1074 1074
 
1075 1075
 		// Default show only subtotal instead of itemization.
1076
-		if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) {
1077
-			foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
1076
+		if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) {
1077
+			foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
1078 1078
 				$amount         = $cart_item['line_subtotal'];
1079
-				$subtotal       += $cart_item['line_subtotal'];
1079
+				$subtotal += $cart_item['line_subtotal'];
1080 1080
 				$quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : '';
1081 1081
 
1082 1082
 				$product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name();
1083 1083
 
1084 1084
 				$item = array(
1085 1085
 					'label'  => $product_name . $quantity_label,
1086
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ),
1086
+					'amount' => WC_Stripe_Helper::get_stripe_amount($amount),
1087 1087
 				);
1088 1088
 
1089 1089
 				$items[] = $item;
1090 1090
 			}
1091 1091
 		}
1092 1092
 
1093
-		$discounts   = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp );
1094
-		$tax         = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp );
1095
-		$shipping    = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp );
1096
-		$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
1097
-		$order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp );
1093
+		$discounts   = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp);
1094
+		$tax         = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp);
1095
+		$shipping    = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp);
1096
+		$items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts;
1097
+		$order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp);
1098 1098
 
1099
-		if ( wc_tax_enabled() ) {
1099
+		if (wc_tax_enabled()) {
1100 1100
 			$items[] = array(
1101
-				'label'  => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ),
1102
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ),
1101
+				'label'  => esc_html(__('Tax', 'woocommerce-gateway-stripe')),
1102
+				'amount' => WC_Stripe_Helper::get_stripe_amount($tax),
1103 1103
 			);
1104 1104
 		}
1105 1105
 
1106
-		if ( WC()->cart->needs_shipping() ) {
1106
+		if (WC()->cart->needs_shipping()) {
1107 1107
 			$items[] = array(
1108
-				'label'  => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ),
1109
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ),
1108
+				'label'  => esc_html(__('Shipping', 'woocommerce-gateway-stripe')),
1109
+				'amount' => WC_Stripe_Helper::get_stripe_amount($shipping),
1110 1110
 			);
1111 1111
 		}
1112 1112
 
1113
-		if ( WC()->cart->has_discount() ) {
1113
+		if (WC()->cart->has_discount()) {
1114 1114
 			$items[] = array(
1115
-				'label'  => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ),
1116
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ),
1115
+				'label'  => esc_html(__('Discount', 'woocommerce-gateway-stripe')),
1116
+				'amount' => WC_Stripe_Helper::get_stripe_amount($discounts),
1117 1117
 			);
1118 1118
 		}
1119 1119
 
1120
-		if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
1120
+		if (version_compare(WC_VERSION, '3.2', '<')) {
1121 1121
 			$cart_fees = WC()->cart->fees;
1122 1122
 		} else {
1123 1123
 			$cart_fees = WC()->cart->get_fees();
1124 1124
 		}
1125 1125
 
1126 1126
 		// Include fees and taxes as display items.
1127
-		foreach ( $cart_fees as $key => $fee ) {
1127
+		foreach ($cart_fees as $key => $fee) {
1128 1128
 			$items[] = array(
1129 1129
 				'label'  => $fee->name,
1130
-				'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ),
1130
+				'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount),
1131 1131
 			);
1132 1132
 		}
1133 1133
 
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 			'displayItems' => $items,
1136 1136
 			'total'      => array(
1137 1137
 				'label'   => $this->total_label,
1138
-				'amount'  => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ),
1138
+				'amount'  => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)),
1139 1139
 				'pending' => false,
1140 1140
 			),
1141 1141
 		);
Please login to merge, or discard this patch.