Completed
Pull Request — master (#535)
by Roy
02:21
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +180 added lines, -180 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
 
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 	public function __construct() {
102 102
 		$this->retry_interval       = 2;
103 103
 		$this->id                   = 'stripe';
104
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
104
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
105 105
 		/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
106
-		$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' );
106
+		$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');
107 107
 		$this->has_fields           = true;
108 108
 		$this->supports             = array(
109 109
 			'products',
@@ -130,32 +130,32 @@  discard block
 block discarded – undo
130 130
 		$this->init_settings();
131 131
 
132 132
 		// Get setting values.
133
-		$this->title                   = $this->get_option( 'title' );
134
-		$this->description             = $this->get_option( 'description' );
135
-		$this->enabled                 = $this->get_option( 'enabled' );
136
-		$this->testmode                = 'yes' === $this->get_option( 'testmode' );
137
-		$this->inline_cc_form          = 'yes' === $this->get_option( 'inline_cc_form' );
138
-		$this->capture                 = 'yes' === $this->get_option( 'capture', 'yes' );
139
-		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
140
-		$this->three_d_secure          = 'yes' === $this->get_option( 'three_d_secure' );
141
-		$this->stripe_checkout         = 'yes' === $this->get_option( 'stripe_checkout' );
142
-		$this->stripe_checkout_image   = $this->get_option( 'stripe_checkout_image', '' );
143
-		$this->saved_cards             = 'yes' === $this->get_option( 'saved_cards' );
144
-		$this->secret_key              = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
145
-		$this->publishable_key         = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
146
-		$this->bitcoin                 = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
147
-		$this->payment_request         = 'yes' === $this->get_option( 'payment_request', 'yes' );
148
-
149
-		if ( $this->stripe_checkout ) {
150
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
133
+		$this->title                   = $this->get_option('title');
134
+		$this->description             = $this->get_option('description');
135
+		$this->enabled                 = $this->get_option('enabled');
136
+		$this->testmode                = 'yes' === $this->get_option('testmode');
137
+		$this->inline_cc_form          = 'yes' === $this->get_option('inline_cc_form');
138
+		$this->capture                 = 'yes' === $this->get_option('capture', 'yes');
139
+		$this->statement_descriptor    = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor'));
140
+		$this->three_d_secure          = 'yes' === $this->get_option('three_d_secure');
141
+		$this->stripe_checkout         = 'yes' === $this->get_option('stripe_checkout');
142
+		$this->stripe_checkout_image   = $this->get_option('stripe_checkout_image', '');
143
+		$this->saved_cards             = 'yes' === $this->get_option('saved_cards');
144
+		$this->secret_key              = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
145
+		$this->publishable_key         = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
146
+		$this->bitcoin                 = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
147
+		$this->payment_request         = 'yes' === $this->get_option('payment_request', 'yes');
148
+
149
+		if ($this->stripe_checkout) {
150
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
151 151
 		}
152 152
 
153
-		WC_Stripe_API::set_secret_key( $this->secret_key );
153
+		WC_Stripe_API::set_secret_key($this->secret_key);
154 154
 
155 155
 		// Hooks.
156
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
157
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
158
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
156
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
157
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
158
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
159 159
 	}
160 160
 
161 161
 	/**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @return bool
166 166
 	 */
167 167
 	public function are_keys_set() {
168
-		if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) {
168
+		if (empty($this->secret_key) || empty($this->publishable_key)) {
169 169
 			return false;
170 170
 		}
171 171
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @since 4.0.2
179 179
 	 */
180 180
 	public function is_available() {
181
-		if ( is_add_payment_method_page() && ! $this->saved_cards ) {
181
+		if (is_add_payment_method_page() && ! $this->saved_cards) {
182 182
 			return false;
183 183
 		}
184 184
 
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
 		$icons_str .= $icons['amex'];
202 202
 		$icons_str .= $icons['mastercard'];
203 203
 
204
-		if ( 'USD' === get_woocommerce_currency() ) {
204
+		if ('USD' === get_woocommerce_currency()) {
205 205
 			$icons_str .= $icons['discover'];
206 206
 			$icons_str .= $icons['jcb'];
207 207
 			$icons_str .= $icons['diners'];
208 208
 		}
209 209
 
210
-		if ( $this->bitcoin && $this->stripe_checkout ) {
210
+		if ($this->bitcoin && $this->stripe_checkout) {
211 211
 			$icons_str .= $icons['bitcoin'];
212 212
 		}
213 213
 
214
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
214
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
215 215
 	}
216 216
 
217 217
 	/**
218 218
 	 * Initialise Gateway Settings Form Fields
219 219
 	 */
220 220
 	public function init_form_fields() {
221
-		$this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' );
221
+		$this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php');
222 222
 	}
223 223
 
224 224
 	/**
@@ -226,68 +226,68 @@  discard block
 block discarded – undo
226 226
 	 */
227 227
 	public function payment_fields() {
228 228
 		$user                 = wp_get_current_user();
229
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
229
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
230 230
 		$total                = WC()->cart->total;
231 231
 		$user_email           = '';
232 232
 
233 233
 		// If paying from order, we need to get total from order not cart.
234
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
235
-			$order      = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
234
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
235
+			$order      = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
236 236
 			$total      = $order->get_total();
237 237
 			$user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
238 238
 		} else {
239
-			if ( $user->ID ) {
240
-				$user_email = get_user_meta( $user->ID, 'billing_email', true );
239
+			if ($user->ID) {
240
+				$user_email = get_user_meta($user->ID, 'billing_email', true);
241 241
 				$user_email = $user_email ? $user_email : $user->user_email;
242 242
 			}
243 243
 		}
244 244
 
245
-		if ( is_add_payment_method_page() ) {
246
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
247
-			$total        = '';
245
+		if (is_add_payment_method_page()) {
246
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
247
+			$total = '';
248 248
 		} else {
249 249
 			$pay_button_text = '';
250 250
 		}
251 251
 
252 252
 		echo '<div
253 253
 			id="stripe-payment-data"
254
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
254
+			data-panel-label="' . esc_attr($pay_button_text) . '"
255 255
 			data-description=""
256
-			data-email="' . esc_attr( $user_email ) . '"
257
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
258
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
259
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
260
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
261
-			data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '"
262
-			data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '"
263
-			data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '"
264
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
265
-
266
-		if ( $this->description ) {
267
-			if ( $this->testmode ) {
256
+			data-email="' . esc_attr($user_email) . '"
257
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
258
+			data-name="' . esc_attr($this->statement_descriptor) . '"
259
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
260
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
261
+			data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '"
262
+			data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '"
263
+			data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '"
264
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
265
+
266
+		if ($this->description) {
267
+			if ($this->testmode) {
268 268
 				/* translators: link to Stripe testing page */
269
-				$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' );
270
-				$this->description  = trim( $this->description );
269
+				$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');
270
+				$this->description  = trim($this->description);
271 271
 			}
272
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
272
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
273 273
 		}
274 274
 
275
-		if ( $display_tokenization ) {
275
+		if ($display_tokenization) {
276 276
 			$this->tokenization_script();
277 277
 			$this->saved_payment_methods();
278 278
 		}
279 279
 
280
-		if ( ! $this->stripe_checkout ) {
281
-			if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) {
280
+		if ( ! $this->stripe_checkout) {
281
+			if (apply_filters('wc_stripe_use_elements_checkout_form', true)) {
282 282
 				$this->elements_form();
283 283
 			} else {
284
-				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!' );
284
+				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!');
285 285
 				$this->form();
286 286
 				echo '<div class="stripe-source-errors" role="alert"></div>';
287 287
 			}
288 288
 		}
289 289
 
290
-		if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
290
+		if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
291 291
 			$this->save_payment_method_checkbox();
292 292
 		}
293 293
 
@@ -302,12 +302,12 @@  discard block
 block discarded – undo
302 302
 	 */
303 303
 	public function elements_form() {
304 304
 		?>
305
-		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
306
-			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
305
+		<fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;">
306
+			<?php do_action('woocommerce_credit_card_form_start', $this->id); ?>
307 307
 
308
-			<?php if ( $this->inline_cc_form ) { ?>
308
+			<?php if ($this->inline_cc_form) { ?>
309 309
 				<label for="card-element">
310
-					<?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?>
310
+					<?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?>
311 311
 				</label>
312 312
 
313 313
 				<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 				</div>
316 316
 			<?php } else { ?>
317 317
 				<div class="form-row form-row-wide">
318
-					<label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
318
+					<label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
319 319
 
320 320
 					<div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
321 321
 					<!-- a Stripe Element will be inserted here. -->
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 				</div>
324 324
 
325 325
 				<div class="form-row form-row-first">
326
-					<label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
326
+					<label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
327 327
 
328 328
 					<div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
329 329
 					<!-- a Stripe Element will be inserted here. -->
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 				</div>
332 332
 
333 333
 				<div class="form-row form-row-last">
334
-					<label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label>
334
+					<label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label>
335 335
 				<div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;">
336 336
 				<!-- a Stripe Element will be inserted here. -->
337 337
 				</div>
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 			<!-- Used to display form errors -->
343 343
 			<div class="stripe-source-errors" role="alert"></div>
344
-			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
344
+			<?php do_action('woocommerce_credit_card_form_end', $this->id); ?>
345 345
 			<div class="clear"></div>
346 346
 		</fieldset>
347 347
 		<?php
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
 	 * @version 3.1.0
355 355
 	 */
356 356
 	public function admin_scripts() {
357
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
357
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
358 358
 			return;
359 359
 		}
360 360
 
361
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
361
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
362 362
 
363
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
363
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
364 364
 	}
365 365
 
366 366
 	/**
@@ -372,46 +372,46 @@  discard block
 block discarded – undo
372 372
 	 * @version 4.0.0
373 373
 	 */
374 374
 	public function payment_scripts() {
375
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) {
375
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) {
376 376
 			return;
377 377
 		}
378 378
 
379 379
 		// If Stripe is not enabled bail.
380
-		if ( 'no' === $this->enabled ) {
380
+		if ('no' === $this->enabled) {
381 381
 			return;
382 382
 		}
383 383
 
384 384
 		// If keys are not set bail.
385
-		if ( ! $this->are_keys_set() ) {
386
-			WC_Stripe_Logger::log( 'Keys are not set correctly.' );
385
+		if ( ! $this->are_keys_set()) {
386
+			WC_Stripe_Logger::log('Keys are not set correctly.');
387 387
 			return;
388 388
 		}
389 389
 
390 390
 		// If no SSL bail.
391
-		if ( ! $this->testmode && ! is_ssl() ) {
392
-			WC_Stripe_Logger::log( 'Stripe requires SSL.' );
391
+		if ( ! $this->testmode && ! is_ssl()) {
392
+			WC_Stripe_Logger::log('Stripe requires SSL.');
393 393
 			return;
394 394
 		}
395 395
 
396
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
396
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
397 397
 
398
-		wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' );
399
-		wp_enqueue_style( 'stripe_paymentfonts' );
400
-		wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
401
-		wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true );
402
-		wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true );
403
-		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 );
398
+		wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5');
399
+		wp_enqueue_style('stripe_paymentfonts');
400
+		wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
401
+		wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true);
402
+		wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true);
403
+		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);
404 404
 
405 405
 		$stripe_params = array(
406 406
 			'key'                  => $this->publishable_key,
407
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
408
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
407
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
408
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
409 409
 		);
410 410
 
411 411
 		// If we're on the pay page we need to pass stripe.js the address of the order.
412
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
413
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
414
-			$order    = wc_get_order( $order_id );
412
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
413
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
414
+			$order    = wc_get_order($order_id);
415 415
 
416 416
 			$stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
417 417
 			$stripe_params['billing_last_name']  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
@@ -423,38 +423,38 @@  discard block
 block discarded – undo
423 423
 			$stripe_params['billing_country']    = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
424 424
 		}
425 425
 
426
-		$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' );
427
-		$stripe_params['no_sepa_owner_msg']                       = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' );
428
-		$stripe_params['no_sepa_iban_msg']                        = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' );
429
-		$stripe_params['sepa_mandate_notification']               = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' );
430
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
426
+		$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');
427
+		$stripe_params['no_sepa_owner_msg']                       = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe');
428
+		$stripe_params['no_sepa_iban_msg']                        = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe');
429
+		$stripe_params['sepa_mandate_notification']               = apply_filters('wc_stripe_sepa_mandate_notification', 'email');
430
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
431 431
 		$stripe_params['inline_cc_form']                          = $this->inline_cc_form ? 'yes' : 'no';
432
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
433
-		$stripe_params['is_checkout']                             = ( is_checkout() && empty( $_GET['pay_for_order'] ) );
432
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
433
+		$stripe_params['is_checkout']                             = (is_checkout() && empty($_GET['pay_for_order']));
434 434
 		$stripe_params['return_url']                              = $this->get_stripe_return_url();
435
-		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint( '%%endpoint%%' );
436
-		$stripe_params['stripe_nonce']                            = wp_create_nonce( '_wc_stripe_nonce' );
435
+		$stripe_params['ajaxurl']                                 = WC_AJAX::get_endpoint('%%endpoint%%');
436
+		$stripe_params['stripe_nonce']                            = wp_create_nonce('_wc_stripe_nonce');
437 437
 		$stripe_params['statement_descriptor']                    = $this->statement_descriptor;
438
-		$stripe_params['use_elements']                            = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no';
439
-		$stripe_params['elements_options']                        = apply_filters( 'wc_stripe_elements_options', array() );
438
+		$stripe_params['use_elements']                            = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no';
439
+		$stripe_params['elements_options']                        = apply_filters('wc_stripe_elements_options', array());
440 440
 		$stripe_params['is_stripe_checkout']                      = $this->stripe_checkout ? 'yes' : 'no';
441
-		$stripe_params['is_change_payment_page']                  = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no';
442
-		$stripe_params['validate_modal_checkout']                 = apply_filters( 'wc_stripe_validate_model_checkout', true ) ? 'yes' : 'no';
443
-		$stripe_params['elements_styling']                        = apply_filters( 'wc_stripe_elements_styling', false );
444
-		$stripe_params['elements_classes']                        = apply_filters( 'wc_stripe_elements_classes', false );
441
+		$stripe_params['is_change_payment_page']                  = isset($_GET['change_payment_method']) ? 'yes' : 'no';
442
+		$stripe_params['validate_modal_checkout']                 = apply_filters('wc_stripe_validate_model_checkout', true) ? 'yes' : 'no';
443
+		$stripe_params['elements_styling']                        = apply_filters('wc_stripe_elements_styling', false);
444
+		$stripe_params['elements_classes']                        = apply_filters('wc_stripe_elements_classes', false);
445 445
 
446 446
 		// merge localized messages to be use in JS
447
-		$stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() );
447
+		$stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages());
448 448
 
449
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
450
-		wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
449
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
450
+		wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
451 451
 
452
-		if ( $this->stripe_checkout ) {
453
-			wp_enqueue_script( 'stripe_checkout' );
452
+		if ($this->stripe_checkout) {
453
+			wp_enqueue_script('stripe_checkout');
454 454
 		}
455 455
 
456 456
 		$this->tokenization_script();
457
-		wp_enqueue_script( 'woocommerce_stripe' );
457
+		wp_enqueue_script('woocommerce_stripe');
458 458
 	}
459 459
 
460 460
 	/**
@@ -470,43 +470,43 @@  discard block
 block discarded – undo
470 470
 	 *
471 471
 	 * @return array|void
472 472
 	 */
473
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
473
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
474 474
 		try {
475
-			$order = wc_get_order( $order_id );
475
+			$order = wc_get_order($order_id);
476 476
 
477 477
 			// This comes from the create account checkbox in the checkout page.
478
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
478
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
479 479
 
480
-			if ( $create_account ) {
480
+			if ($create_account) {
481 481
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
482
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
482
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
483 483
 				$new_stripe_customer->create_customer();
484 484
 			}
485 485
 
486 486
 			$source_object   = $this->get_source_object();
487
-			$prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source );
487
+			$prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source);
488 488
 
489 489
 			// Check if we don't allow prepaid credit cards.
490
-			if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) {
491
-				if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) {
492
-					$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' );
493
-					throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message );
490
+			if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) {
491
+				if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) {
492
+					$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');
493
+					throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message);
494 494
 				}
495 495
 			}
496 496
 
497
-			if ( empty( $prepared_source->source ) ) {
498
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
499
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
497
+			if (empty($prepared_source->source)) {
498
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
499
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
500 500
 			}
501 501
 
502
-			$this->save_source_to_order( $order, $prepared_source );
502
+			$this->save_source_to_order($order, $prepared_source);
503 503
 
504 504
 			// Result from Stripe API request.
505 505
 			$response = null;
506 506
 
507
-			if ( $order->get_total() > 0 ) {
507
+			if ($order->get_total() > 0) {
508 508
 				// This will throw exception if not valid.
509
-				$this->validate_minimum_order_amount( $order );
509
+				$this->validate_minimum_order_amount($order);
510 510
 
511 511
 				/*
512 512
 				 * Check if card 3DS is required or optional with 3DS setting.
@@ -515,109 +515,109 @@  discard block
 block discarded – undo
515 515
 				 * Note that if we need to save source, the original source must be first
516 516
 				 * attached to a customer in Stripe before it can be charged.
517 517
 				 */
518
-				if ( $this->is_3ds_required( $source_object ) ) {
519
-					$response = $this->create_3ds_source( $order, $source_object );
518
+				if ($this->is_3ds_required($source_object)) {
519
+					$response = $this->create_3ds_source($order, $source_object);
520 520
 
521
-					if ( ! empty( $response->error ) ) {
521
+					if ( ! empty($response->error)) {
522 522
 						$localized_message = $response->error->message;
523 523
 
524
-						$order->add_order_note( $localized_message );
524
+						$order->add_order_note($localized_message);
525 525
 
526
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
526
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
527 527
 					}
528 528
 
529 529
 					// Update order meta with 3DS source.
530
-					if ( WC_Stripe_Helper::is_pre_30() ) {
531
-						update_post_meta( $order_id, '_stripe_source_id', $response->id );
530
+					if (WC_Stripe_Helper::is_pre_30()) {
531
+						update_post_meta($order_id, '_stripe_source_id', $response->id);
532 532
 					} else {
533
-						$order->update_meta_data( '_stripe_source_id', $response->id );
533
+						$order->update_meta_data('_stripe_source_id', $response->id);
534 534
 						$order->save();
535 535
 					}
536 536
 
537
-					WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' );
537
+					WC_Stripe_Logger::log('Info: Redirecting to 3DS...');
538 538
 
539 539
 					return array(
540 540
 						'result'   => 'success',
541
-						'redirect' => esc_url_raw( $response->redirect->url ),
541
+						'redirect' => esc_url_raw($response->redirect->url),
542 542
 					);
543 543
 				}
544 544
 
545
-				WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
545
+				WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
546 546
 
547 547
 				// Make the request.
548
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) );
548
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source));
549 549
 
550
-				if ( ! empty( $response->error ) ) {
550
+				if ( ! empty($response->error)) {
551 551
 					// If it is an API error such connection or server, let's retry.
552
-					if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
553
-						if ( $retry ) {
554
-							sleep( 5 );
555
-							return $this->process_payment( $order_id, false, $force_save_source );
552
+					if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
553
+						if ($retry) {
554
+							sleep(5);
555
+							return $this->process_payment($order_id, false, $force_save_source);
556 556
 						} else {
557 557
 							$localized_message = 'API connection error and retries exhausted.';
558
-							$order->add_order_note( $localized_message );
559
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
558
+							$order->add_order_note($localized_message);
559
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
560 560
 						}
561 561
 					}
562 562
 
563 563
 					// We want to retry.
564
-					if ( $this->is_retryable_error( $response->error ) ) {
565
-						if ( $retry ) {
564
+					if ($this->is_retryable_error($response->error)) {
565
+						if ($retry) {
566 566
 							// Don't do anymore retries after this.
567
-							if ( 5 <= $this->retry_interval ) {
567
+							if (5 <= $this->retry_interval) {
568 568
 
569
-								return $this->process_payment( $order_id, false, $force_save_source );
569
+								return $this->process_payment($order_id, false, $force_save_source);
570 570
 							}
571 571
 
572
-							sleep( $this->retry_interval );
572
+							sleep($this->retry_interval);
573 573
 
574 574
 							$this->retry_interval++;
575
-							return $this->process_payment( $order_id, true, $force_save_source );
575
+							return $this->process_payment($order_id, true, $force_save_source);
576 576
 						} else {
577
-							$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
578
-							$order->add_order_note( $localized_message );
579
-							throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
577
+							$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
578
+							$order->add_order_note($localized_message);
579
+							throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
580 580
 						}
581 581
 					}
582 582
 
583 583
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
584
-					if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
585
-						if ( WC_Stripe_Helper::is_pre_30() ) {
586
-							delete_user_meta( $order->customer_user, '_stripe_customer_id' );
587
-							delete_post_meta( $order_id, '_stripe_customer_id' );
584
+					if (preg_match('/No such customer/i', $response->error->message) && $retry) {
585
+						if (WC_Stripe_Helper::is_pre_30()) {
586
+							delete_user_meta($order->customer_user, '_stripe_customer_id');
587
+							delete_post_meta($order_id, '_stripe_customer_id');
588 588
 						} else {
589
-							delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
590
-							$order->delete_meta_data( '_stripe_customer_id' );
589
+							delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
590
+							$order->delete_meta_data('_stripe_customer_id');
591 591
 							$order->save();
592 592
 						}
593 593
 
594
-						return $this->process_payment( $order_id, false, $force_save_source );
595
-					} elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) {
594
+						return $this->process_payment($order_id, false, $force_save_source);
595
+					} elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) {
596 596
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
597
-						$wc_token = WC_Payment_Tokens::get( $prepared_source->token_id );
597
+						$wc_token = WC_Payment_Tokens::get($prepared_source->token_id);
598 598
 						$wc_token->delete();
599
-						$localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
600
-						$order->add_order_note( $localized_message );
601
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
599
+						$localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
600
+						$order->add_order_note($localized_message);
601
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
602 602
 					}
603 603
 
604 604
 					$localized_messages = WC_Stripe_Helper::get_localized_messages();
605 605
 
606
-					if ( 'card_error' === $response->error->type ) {
607
-						$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
606
+					if ('card_error' === $response->error->type) {
607
+						$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
608 608
 					} else {
609
-						$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
609
+						$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
610 610
 					}
611 611
 
612
-					$order->add_order_note( $localized_message );
612
+					$order->add_order_note($localized_message);
613 613
 
614
-					throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
614
+					throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
615 615
 				}
616 616
 
617
-				do_action( 'wc_gateway_stripe_process_payment', $response, $order );
617
+				do_action('wc_gateway_stripe_process_payment', $response, $order);
618 618
 
619 619
 				// Process valid response.
620
-				$this->process_response( $response, $order );
620
+				$this->process_response($response, $order);
621 621
 			} else {
622 622
 				$order->payment_complete();
623 623
 			}
@@ -628,17 +628,17 @@  discard block
 block discarded – undo
628 628
 			// Return thank you page redirect.
629 629
 			return array(
630 630
 				'result'   => 'success',
631
-				'redirect' => $this->get_return_url( $order ),
631
+				'redirect' => $this->get_return_url($order),
632 632
 			);
633 633
 
634
-		} catch ( WC_Stripe_Exception $e ) {
635
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
636
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
634
+		} catch (WC_Stripe_Exception $e) {
635
+			wc_add_notice($e->getLocalizedMessage(), 'error');
636
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
637 637
 
638
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
638
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
639 639
 
640
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
641
-				$this->send_failed_order_email( $order_id );
640
+			if ($order->has_status(array('pending', 'failed'))) {
641
+				$this->send_failed_order_email($order_id);
642 642
 			}
643 643
 
644 644
 			return array(
Please login to merge, or discard this patch.
includes/deprecated/class-wc-stripe-apple-pay.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 /**
7 7
  * DEPRECATED DO NOT USE!!
8 8
  */
9
-if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) {
9
+if ( ! class_exists('WC_Stripe_Apple_Pay')) {
10 10
 	class WC_Stripe_Apple_Pay {
11 11
 		/**
12 12
 		 * This Instance.
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
 		}
21 21
 
22 22
 		public static function instance() {
23
-			WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0' );
23
+			WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0');
24 24
 			return self::$_this;
25 25
 		}
26 26
 
27
-		public function __get( $var ) {
27
+		public function __get($var) {
28 28
 			return null;
29 29
 		}
30 30
 
31
-		public function __call( $name, $arguments ) {
31
+		public function __call($name, $arguments) {
32 32
 			return null;
33 33
 		}
34 34
 	}
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-bitcoin.php 1 patch
Spacing   +89 added lines, -89 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
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function __construct() {
66 66
 		$this->id                   = 'stripe_bitcoin';
67
-		$this->method_title         = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' );
67
+		$this->method_title         = __('Stripe Bitcoin', 'woocommerce-gateway-stripe');
68 68
 		/* translators: link */
69
-		$this->method_description   = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
69
+		$this->method_description   = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
70 70
 		$this->supports             = array(
71 71
 			'products',
72 72
 			'refunds',
@@ -78,29 +78,29 @@  discard block
 block discarded – undo
78 78
 		// Load the settings.
79 79
 		$this->init_settings();
80 80
 
81
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
82
-		$this->title                = $this->get_option( 'title' );
83
-		$this->description          = $this->get_option( 'description' );
84
-		$this->enabled              = $this->get_option( 'enabled' );
85
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
86
-		$this->saved_cards          = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false;
87
-		$this->publishable_key      = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : '';
88
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
89
-		$this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : '';
90
-
91
-		if ( $this->testmode ) {
92
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
93
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
81
+		$main_settings              = get_option('woocommerce_stripe_settings');
82
+		$this->title                = $this->get_option('title');
83
+		$this->description          = $this->get_option('description');
84
+		$this->enabled              = $this->get_option('enabled');
85
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
86
+		$this->saved_cards          = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false;
87
+		$this->publishable_key      = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : '';
88
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
89
+		$this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : '';
90
+
91
+		if ($this->testmode) {
92
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
93
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
94 94
 		}
95 95
 
96
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
97
-		add_action( 'admin_notices', array( $this, 'check_environment' ) );
98
-		add_action( 'admin_head', array( $this, 'remove_admin_notice' ) );
99
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
100
-		add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) );
96
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
97
+		add_action('admin_notices', array($this, 'check_environment'));
98
+		add_action('admin_head', array($this, 'remove_admin_notice'));
99
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
100
+		add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page'));
101 101
 
102 102
 		// Customer Emails.
103
-		add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
103
+		add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
104 104
 	}
105 105
 
106 106
 	/**
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 	 * @version 4.0.0
111 111
 	 */
112 112
 	public function check_environment() {
113
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
113
+		if ( ! current_user_can('manage_woocommerce')) {
114 114
 			return;
115 115
 		}
116 116
 
117 117
 		$environment_warning = $this->get_environment_warning();
118 118
 
119
-		if ( $environment_warning ) {
120
-			$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
119
+		if ($environment_warning) {
120
+			$this->add_admin_notice('bad_environment', 'error', $environment_warning);
121 121
 		}
122 122
 
123
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
124
-			echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
125
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
123
+		foreach ((array) $this->notices as $notice_key => $notice) {
124
+			echo "<div class='" . esc_attr($notice['class']) . "'><p>";
125
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
126 126
 			echo '</p></div>';
127 127
 		}
128 128
 	}
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 	 */
137 137
 	public function get_environment_warning() {
138 138
 		// Add deprecated notice to logs.
139
-		if ( 'yes' === $this->enabled ) {
140
-			WC_Stripe_Logger::log( 'DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.' );
139
+		if ('yes' === $this->enabled) {
140
+			WC_Stripe_Logger::log('DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.');
141 141
 		}
142 142
 
143
-		if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
144
-			$message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' );
143
+		if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
144
+			$message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe');
145 145
 
146 146
 			return $message;
147 147
 		}
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 	 * @return array
158 158
 	 */
159 159
 	public function get_supported_currency() {
160
-		return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array(
160
+		return apply_filters('wc_stripe_bitcoin_supported_currencies', array(
161 161
 			'USD',
162
-		) );
162
+		));
163 163
 	}
164 164
 
165 165
 	/**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return bool
171 171
 	 */
172 172
 	public function is_available() {
173
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
173
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
174 174
 			return false;
175 175
 		}
176 176
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
 		$icons_str .= $icons['bitcoin'];
193 193
 
194
-		return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id );
194
+		return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id);
195 195
 	}
196 196
 
197 197
 	/**
@@ -202,19 +202,19 @@  discard block
 block discarded – undo
202 202
 	 * @access public
203 203
 	 */
204 204
 	public function payment_scripts() {
205
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
205
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
206 206
 			return;
207 207
 		}
208 208
 
209
-		wp_enqueue_style( 'stripe_paymentfonts' );
210
-		wp_enqueue_script( 'woocommerce_stripe' );
209
+		wp_enqueue_style('stripe_paymentfonts');
210
+		wp_enqueue_script('woocommerce_stripe');
211 211
 	}
212 212
 
213 213
 	/**
214 214
 	 * Initialize Gateway Settings Form Fields.
215 215
 	 */
216 216
 	public function init_form_fields() {
217
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' );
217
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php');
218 218
 	}
219 219
 
220 220
 	/**
@@ -225,25 +225,25 @@  discard block
 block discarded – undo
225 225
 		$total                = WC()->cart->total;
226 226
 
227 227
 		// If paying from order, we need to get total from order not cart.
228
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
229
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
228
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
229
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
230 230
 			$total = $order->get_total();
231 231
 		}
232 232
 
233
-		if ( is_add_payment_method_page() ) {
234
-			$pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' );
235
-			$total        = '';
233
+		if (is_add_payment_method_page()) {
234
+			$pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe');
235
+			$total = '';
236 236
 		} else {
237 237
 			$pay_button_text = '';
238 238
 		}
239 239
 
240 240
 		echo '<div
241 241
 			id="stripe-bitcoin-payment-data"
242
-			data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '"
243
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">';
242
+			data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '"
243
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">';
244 244
 
245
-		if ( $this->description ) {
246
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
245
+		if ($this->description) {
246
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
247 247
 		}
248 248
 
249 249
 		echo '</div>';
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @param int $order_id
256 256
 	 */
257
-	public function thankyou_page( $order_id ) {
258
-		$this->get_instructions( $order_id );
257
+	public function thankyou_page($order_id) {
258
+		$this->get_instructions($order_id);
259 259
 	}
260 260
 
261 261
 	/**
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @param bool $sent_to_admin
268 268
 	 * @param bool $plain_text
269 269
 	 */
270
-	public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
270
+	public function email_instructions($order, $sent_to_admin, $plain_text = false) {
271 271
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
272 272
 
273 273
 		$payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method();
274 274
 
275
-		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) {
276
-			$this->get_instructions( $order_id, $plain_text );
275
+		if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) {
276
+			$this->get_instructions($order_id, $plain_text);
277 277
 		}
278 278
 	}
279 279
 
@@ -284,38 +284,38 @@  discard block
 block discarded – undo
284 284
 	 * @version 4.0.0
285 285
 	 * @param int $order_id
286 286
 	 */
287
-	public function get_instructions( $order_id, $plain_text = false ) {
288
-		$data = get_post_meta( $order_id, '_stripe_bitcoin', true );
287
+	public function get_instructions($order_id, $plain_text = false) {
288
+		$data = get_post_meta($order_id, '_stripe_bitcoin', true);
289 289
 
290
-		if ( $plain_text ) {
291
-			esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n";
290
+		if ($plain_text) {
291
+			esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n";
292 292
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
293
-			esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n";
293
+			esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n";
294 294
 			echo $data['amount'] . "\n\n";
295 295
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
296
-			esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n";
296
+			esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n";
297 297
 			echo $data['address'] . "\n\n";
298 298
 			echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
299
-			esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n";
299
+			esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n";
300 300
 			echo $data['uri'] . "\n\n";
301 301
 		} else {
302 302
 			?>
303
-			<h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3>
303
+			<h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3>
304 304
 			<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
305 305
 			<li class="woocommerce-order-overview__order order">
306
-				<?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?>
306
+				<?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?>
307 307
 				<strong><?php echo $data['amount']; ?></strong>
308 308
 			</li>
309 309
 			<li class="woocommerce-order-overview__order order">
310
-				<?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?>
310
+				<?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?>
311 311
 				<strong><?php echo $data['address']; ?></strong>
312 312
 			</li>
313 313
 			<li class="woocommerce-order-overview__order order">
314
-				<?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?>
314
+				<?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?>
315 315
 				<strong>
316 316
 				<?php
317 317
 				/* translators: link */
318
-				printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] );
318
+				printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']);
319 319
 				?>
320 320
 				</strong>
321 321
 			</li>
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 * @param object $order
333 333
 	 * @param object $source_object
334 334
 	 */
335
-	public function save_instructions( $order, $source_object ) {
335
+	public function save_instructions($order, $source_object) {
336 336
 		$data = array(
337 337
 			'amount'  => $source_object->bitcoin->amount,
338 338
 			'address' => $source_object->bitcoin->address,
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
343 343
 
344
-		update_post_meta( $order_id, '_stripe_bitcoin', $data );
344
+		update_post_meta($order_id, '_stripe_bitcoin', $data);
345 345
 	}
346 346
 
347 347
 	/**
@@ -355,37 +355,37 @@  discard block
 block discarded – undo
355 355
 	 *
356 356
 	 * @return array|void
357 357
 	 */
358
-	public function process_payment( $order_id, $retry = true, $force_save_source = false ) {
358
+	public function process_payment($order_id, $retry = true, $force_save_source = false) {
359 359
 		try {
360
-			$order = wc_get_order( $order_id );
360
+			$order = wc_get_order($order_id);
361 361
 
362 362
 			// This comes from the create account checkbox in the checkout page.
363
-			$create_account = ! empty( $_POST['createaccount'] ) ? true : false;
363
+			$create_account = ! empty($_POST['createaccount']) ? true : false;
364 364
 
365
-			if ( $create_account ) {
365
+			if ($create_account) {
366 366
 				$new_customer_id     = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id();
367
-				$new_stripe_customer = new WC_Stripe_Customer( $new_customer_id );
367
+				$new_stripe_customer = new WC_Stripe_Customer($new_customer_id);
368 368
 				$new_stripe_customer->create_customer();
369 369
 			}
370 370
 
371
-			$prepared_source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), $force_save_source );
371
+			$prepared_source = $this->prepare_source($this->get_source_object(), get_current_user_id(), $force_save_source);
372 372
 
373
-			if ( empty( $prepared_source->source ) ) {
374
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
375
-				throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message );
373
+			if (empty($prepared_source->source)) {
374
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
375
+				throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message);
376 376
 			}
377 377
 
378
-			$this->save_source_to_order( $order, $prepared_source );
378
+			$this->save_source_to_order($order, $prepared_source);
379 379
 
380 380
 			// This will throw exception if not valid.
381
-			$this->validate_minimum_order_amount( $order );
381
+			$this->validate_minimum_order_amount($order);
382 382
 
383
-			$this->save_instructions( $order, $this->get_source_object() );
383
+			$this->save_instructions($order, $this->get_source_object());
384 384
 
385 385
 			// Mark as on-hold (we're awaiting the payment).
386
-			$order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) );
386
+			$order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe'));
387 387
 
388
-			wc_reduce_stock_levels( $order_id );
388
+			wc_reduce_stock_levels($order_id);
389 389
 
390 390
 			// Remove cart.
391 391
 			WC()->cart->empty_cart();
@@ -393,16 +393,16 @@  discard block
 block discarded – undo
393 393
 			// Return thankyou redirect.
394 394
 			return array(
395 395
 				'result'    => 'success',
396
-				'redirect'  => $this->get_return_url( $order ),
396
+				'redirect'  => $this->get_return_url($order),
397 397
 			);
398
-		} catch ( WC_Stripe_Exception $e ) {
399
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
400
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
398
+		} catch (WC_Stripe_Exception $e) {
399
+			wc_add_notice($e->getLocalizedMessage(), 'error');
400
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
401 401
 
402
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
402
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
403 403
 
404
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
405
-				$this->send_failed_order_email( $order_id );
404
+			if ($order->has_status(array('pending', 'failed'))) {
405
+				$this->send_failed_order_email($order_id);
406 406
 			}
407 407
 
408 408
 			return array(
Please login to merge, or discard this patch.
includes/compat/class-wc-stripe-sepa-compat.php 1 patch
Spacing   +160 added lines, -160 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,89 +341,89 @@  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 ) {
397
+		if ($sources) {
398 398
 			$found_source = false;
399
-			foreach ( $sources as $source ) {
400
-				if ( isset( $source->type ) && 'card' === $source->type ) {
399
+			foreach ($sources as $source) {
400
+				if (isset($source->type) && 'card' === $source->type) {
401 401
 					$card = $source->card;
402 402
 				}
403 403
 
404
-				if ( $source->id === $stripe_source_id ) {
404
+				if ($source->id === $stripe_source_id) {
405 405
 					$found_source = true;
406 406
 
407
-					if ( $card ) {
407
+					if ($card) {
408 408
 						/* translators: 1) card brand 2) last 4 digits */
409
-						$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 );
409
+						$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);
410 410
 					} else {
411
-						$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
411
+						$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
412 412
 					}
413 413
 					break;
414 414
 				}
415 415
 			}
416 416
 
417
-			if ( ! $found_source ) {
418
-				if ( 'card' === $sources[0]->type ) {
417
+			if ( ! $found_source) {
418
+				if ('card' === $sources[0]->type) {
419 419
 					$card = $sources[0]->card;
420 420
 				}
421 421
 
422
-				if ( $card ) {
422
+				if ($card) {
423 423
 					/* translators: 1) card brand 2) last 4 digits */
424
-					$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 );
424
+					$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);
425 425
 				} else {
426
-					$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
426
+					$payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe');
427 427
 				}
428 428
 			}
429 429
 		}
@@ -436,42 +436,42 @@  discard block
 block discarded – undo
436 436
 	 * @param int $order_id
437 437
 	 * @return array
438 438
 	 */
439
-	public function process_pre_order( $order_id, $retry, $force_save_source ) {
440
-		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
439
+	public function process_pre_order($order_id, $retry, $force_save_source) {
440
+		if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) {
441 441
 			try {
442
-				$order = wc_get_order( $order_id );
442
+				$order = wc_get_order($order_id);
443 443
 
444
-				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
444
+				if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
445 445
 					/* translators: minimum amount */
446
-					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 ) ) );
446
+					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)));
447 447
 				}
448 448
 
449
-				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
449
+				$source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true);
450 450
 
451 451
 				// We need a source on file to continue.
452
-				if ( empty( $source->customer ) || empty( $source->source ) ) {
453
-					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
452
+				if (empty($source->customer) || empty($source->source)) {
453
+					throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
454 454
 				}
455 455
 
456
-				$this->save_source_to_order( $order, $source );
456
+				$this->save_source_to_order($order, $source);
457 457
 
458 458
 				// Remove cart
459 459
 				WC()->cart->empty_cart();
460 460
 
461 461
 				// Is pre ordered!
462
-				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
462
+				WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
463 463
 
464 464
 				// Return thank you page redirect
465 465
 				return array(
466 466
 					'result'   => 'success',
467
-					'redirect' => $this->get_return_url( $order ),
467
+					'redirect' => $this->get_return_url($order),
468 468
 				);
469
-			} catch ( Exception $e ) {
470
-				wc_add_notice( $e->getMessage(), 'error' );
469
+			} catch (Exception $e) {
470
+				wc_add_notice($e->getMessage(), 'error');
471 471
 				return;
472 472
 			}
473 473
 		} else {
474
-			return parent::process_payment( $order_id, $retry, $force_save_source );
474
+			return parent::process_payment($order_id, $retry, $force_save_source);
475 475
 		}
476 476
 	}
477 477
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @param WC_Order $order
481 481
 	 * @return void
482 482
 	 */
483
-	public function process_pre_order_release_payment( $order ) {
483
+	public function process_pre_order_release_payment($order) {
484 484
 		try {
485 485
 			// Define some callbacks if the first attempt fails.
486 486
 			$retry_callbacks = array(
@@ -488,33 +488,33 @@  discard block
 block discarded – undo
488 488
 				'remove_order_customer_before_retry',
489 489
 			);
490 490
 
491
-			while ( 1 ) {
492
-				$source   = $this->prepare_order_source( $order );
493
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
491
+			while (1) {
492
+				$source   = $this->prepare_order_source($order);
493
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
494 494
 
495
-				if ( ! empty( $response->error ) ) {
496
-					if ( 0 === sizeof( $retry_callbacks ) ) {
497
-						throw new Exception( $response->error->message );
495
+				if ( ! empty($response->error)) {
496
+					if (0 === sizeof($retry_callbacks)) {
497
+						throw new Exception($response->error->message);
498 498
 					} else {
499
-						$retry_callback = array_shift( $retry_callbacks );
500
-						call_user_func( array( $this, $retry_callback ), $order );
499
+						$retry_callback = array_shift($retry_callbacks);
500
+						call_user_func(array($this, $retry_callback), $order);
501 501
 					}
502 502
 				} else {
503 503
 					// Successful
504
-					$this->process_response( $response, $order );
504
+					$this->process_response($response, $order);
505 505
 					break;
506 506
 				}
507 507
 			}
508
-		} catch ( Exception $e ) {
508
+		} catch (Exception $e) {
509 509
 			/* translators: error message */
510
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
510
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
511 511
 
512 512
 			// Mark order as failed if not already set,
513 513
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
514
-			if ( ! $order->has_status( 'failed' ) ) {
515
-				$order->update_status( 'failed', $order_note );
514
+			if ( ! $order->has_status('failed')) {
515
+				$order->update_status('failed', $order_note);
516 516
 			} else {
517
-				$order->add_order_note( $order_note );
517
+				$order->add_order_note($order_note);
518 518
 			}
519 519
 		}
520 520
 	}
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.5' );
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.5');
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/abstracts/abstract-wc-stripe-payment-gateway.php 1 patch
Spacing   +209 added lines, -210 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 ||
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * Check if this gateway is enabled
34 34
 	 */
35 35
 	public function is_available() {
36
-		if ( 'yes' === $this->enabled ) {
37
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
36
+		if ('yes' === $this->enabled) {
37
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
38 38
 				return false;
39 39
 			}
40
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
40
+			if ( ! $this->secret_key || ! $this->publishable_key) {
41 41
 				return false;
42 42
 			}
43 43
 			return true;
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	 * @since 4.0.0
53 53
 	 * @version 4.0.0
54 54
 	 */
55
-	public function add_admin_notice( $slug, $class, $message ) {
56
-		$this->notices[ $slug ] = array(
55
+	public function add_admin_notice($slug, $class, $message) {
56
+		$this->notices[$slug] = array(
57 57
 			'class'   => $class,
58 58
 			'message' => $message,
59 59
 		);
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @version 4.0.0
67 67
 	 */
68 68
 	public function remove_admin_notice() {
69
-		if ( did_action( 'woocommerce_update_options' ) ) {
70
-			remove_action( 'admin_notices', array( $this, 'check_environment' ) );
69
+		if (did_action('woocommerce_update_options')) {
70
+			remove_action('admin_notices', array($this, 'check_environment'));
71 71
 		}
72 72
 	}
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @return array
80 80
 	 */
81 81
 	public function payment_icons() {
82
-		return apply_filters( 'wc_stripe_payment_icons', array(
82
+		return apply_filters('wc_stripe_payment_icons', array(
83 83
 			'visa'       => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>',
84 84
 			'amex'       => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>',
85 85
 			'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			'eps'        => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>',
97 97
 			'sofort'     => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>',
98 98
 			'sepa'       => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>',
99
-		) );
99
+		));
100 100
 	}
101 101
 
102 102
 	/**
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	 * @version 4.0.0
108 108
 	 * @param object $order
109 109
 	 */
110
-	public function validate_minimum_order_amount( $order ) {
111
-		if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
110
+	public function validate_minimum_order_amount($order) {
111
+		if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) {
112 112
 			/* translators: 1) dollar amount */
113
-			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 ) ) );
113
+			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)));
114 114
 		}
115 115
 	}
116 116
 
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 	 * @since 4.0.0
121 121
 	 * @version 4.0.0
122 122
 	 */
123
-	public function get_transaction_url( $order ) {
124
-		if ( $this->testmode ) {
123
+	public function get_transaction_url($order) {
124
+		if ($this->testmode) {
125 125
 			$this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s';
126 126
 		} else {
127 127
 			$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
128 128
 		}
129 129
 
130
-		return parent::get_transaction_url( $order );
130
+		return parent::get_transaction_url($order);
131 131
 	}
132 132
 
133 133
 	/**
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 	 * @since 4.0.0
137 137
 	 * @version 4.0.0
138 138
 	 */
139
-	public function get_stripe_customer_id( $order ) {
140
-		$customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true );
139
+	public function get_stripe_customer_id($order) {
140
+		$customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true);
141 141
 
142
-		if ( empty( $customer ) ) {
142
+		if (empty($customer)) {
143 143
 			// Try to get it via the order.
144
-			if ( WC_Stripe_Helper::is_pre_30() ) {
145
-				return get_post_meta( $order->id, '_stripe_customer_id', true );
144
+			if (WC_Stripe_Helper::is_pre_30()) {
145
+				return get_post_meta($order->id, '_stripe_customer_id', true);
146 146
 			} else {
147
-				return $order->get_meta( '_stripe_customer_id', true );
147
+				return $order->get_meta('_stripe_customer_id', true);
148 148
 			}
149 149
 		} else {
150 150
 			return $customer;
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param object $order
162 162
 	 * @param int $id Stripe session id.
163 163
 	 */
164
-	public function get_stripe_return_url( $order = null, $id = null ) {
165
-		if ( is_object( $order ) ) {
166
-			if ( empty( $id ) ) {
164
+	public function get_stripe_return_url($order = null, $id = null) {
165
+		if (is_object($order)) {
166
+			if (empty($id)) {
167 167
 				$id = uniqid();
168 168
 			}
169 169
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 				'order_id'       => $order_id,
175 175
 			);
176 176
 
177
-			return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) );
177
+			return esc_url_raw(add_query_arg($args, $this->get_return_url($order)));
178 178
 		}
179 179
 
180
-		return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) );
180
+		return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url()));
181 181
 	}
182 182
 
183 183
 	/**
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  int  $order_id
186 186
 	 * @return boolean
187 187
 	 */
188
-	public function has_subscription( $order_id ) {
189
-		return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) );
188
+	public function has_subscription($order_id) {
189
+		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 190
 	}
191 191
 
192 192
 	/**
@@ -198,34 +198,33 @@  discard block
 block discarded – undo
198 198
 	 * @param  object $source
199 199
 	 * @return array()
200 200
 	 */
201
-	public function generate_payment_request( $order, $source ) {
202
-		$settings                          = get_option( 'woocommerce_stripe_settings', array() );
203
-		$statement_descriptor              = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
204
-		$capture                           = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
201
+	public function generate_payment_request($order, $source) {
202
+		$settings                          = get_option('woocommerce_stripe_settings', array());
203
+		$statement_descriptor              = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : '';
204
+		$capture                           = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false;
205 205
 		$post_data                         = array();
206
-		$post_data['currency']             = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() );
207
-		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
206
+		$post_data['currency']             = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency());
207
+		$post_data['amount']               = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']);
208 208
 		/* translators: 1) blog name 2) order number */
209
-		$post_data['description']          = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
209
+		$post_data['description']          = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
210 210
 		$billing_email      = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email();
211 211
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
212 212
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
213 213
 
214
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
214
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
215 215
 			$post_data['receipt_email'] = $billing_email;
216 216
 		}
217 217
 
218
-		switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) {
219
-			case 'stripe':
220
-				if ( ! empty( $statement_descriptor ) ) {
221
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
218
+		switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) {
219
+			case 'stripe' : if ( ! empty($statement_descriptor)) {
220
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
222 221
 				}
223 222
 
224 223
 				$post_data['capture'] = $capture ? 'true' : 'false';
225 224
 				break;
226 225
 			case 'stripe_sepa':
227
-				if ( ! empty( $statement_descriptor ) ) {
228
-					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
226
+				if ( ! empty($statement_descriptor)) {
227
+					$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor);
229 228
 				}
230 229
 				break;
231 230
 		}
@@ -233,25 +232,25 @@  discard block
 block discarded – undo
233 232
 		$post_data['expand[]'] = 'balance_transaction';
234 233
 
235 234
 		$metadata = array(
236
-			__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
237
-			__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
235
+			__('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
236
+			__('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
238 237
 			'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(),
239 238
 		);
240 239
 
241
-		if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) {
240
+		if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) {
242 241
 			$metadata += array(
243 242
 				'payment_type' => 'recurring',
244
-				'site_url'     => esc_url( get_site_url() ),
243
+				'site_url'     => esc_url(get_site_url()),
245 244
 			);
246 245
 		}
247 246
 
248
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
247
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
249 248
 
250
-		if ( $source->customer ) {
249
+		if ($source->customer) {
251 250
 			$post_data['customer'] = $source->customer;
252 251
 		}
253 252
 
254
-		if ( $source->source ) {
253
+		if ($source->source) {
255 254
 			$post_data['source'] = $source->source;
256 255
 		}
257 256
 
@@ -263,79 +262,79 @@  discard block
 block discarded – undo
263 262
 		 * @param WC_Order $order
264 263
 		 * @param object $source
265 264
 		 */
266
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
265
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
267 266
 	}
268 267
 
269 268
 	/**
270 269
 	 * Store extra meta data for an order from a Stripe Response.
271 270
 	 */
272
-	public function process_response( $response, $order ) {
273
-		WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) );
271
+	public function process_response($response, $order) {
272
+		WC_Stripe_Logger::log('Processing response: ' . print_r($response, true));
274 273
 
275 274
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
276 275
 
277
-		$captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no';
276
+		$captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no';
278 277
 
279 278
 		// Store charge data.
280
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured );
279
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured);
281 280
 
282 281
 		// Store other data such as fees.
283
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
282
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
284 283
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
285 284
 			// values are in the local currency of the Stripe account, not from WC.
286
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0;
287
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0;
288
-			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 );
289
-			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 );
285
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0;
286
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0;
287
+			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);
288
+			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);
290 289
 		}
291 290
 
292
-		if ( 'yes' === $captured ) {
291
+		if ('yes' === $captured) {
293 292
 			/**
294 293
 			 * Charge can be captured but in a pending state. Payment methods
295 294
 			 * that are asynchronous may take couple days to clear. Webhook will
296 295
 			 * take care of the status changes.
297 296
 			 */
298
-			if ( 'pending' === $response->status ) {
299
-				$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 );
297
+			if ('pending' === $response->status) {
298
+				$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);
300 299
 
301
-				if ( ! $order_stock_reduced ) {
302
-					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
300
+				if ( ! $order_stock_reduced) {
301
+					WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
303 302
 				}
304 303
 
305
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
304
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
306 305
 				/* translators: transaction id */
307
-				$order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) );
306
+				$order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id));
308 307
 			}
309 308
 
310
-			if ( 'succeeded' === $response->status ) {
311
-				$order->payment_complete( $response->id );
309
+			if ('succeeded' === $response->status) {
310
+				$order->payment_complete($response->id);
312 311
 
313 312
 				/* translators: transaction id */
314
-				$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
315
-				$order->add_order_note( $message );
313
+				$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
314
+				$order->add_order_note($message);
316 315
 			}
317 316
 
318
-			if ( 'failed' === $response->status ) {
319
-				$localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' );
320
-				$order->add_order_note( $localized_message );
321
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
317
+			if ('failed' === $response->status) {
318
+				$localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe');
319
+				$order->add_order_note($localized_message);
320
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
322 321
 			}
323 322
 		} else {
324
-			WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id );
323
+			WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id);
325 324
 
326
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
327
-				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
325
+			if ($order->has_status(array('pending', 'failed'))) {
326
+				WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
328 327
 			}
329 328
 
330 329
 			/* translators: transaction id */
331
-			$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 ) );
330
+			$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 331
 		}
333 332
 
334
-		if ( is_callable( array( $order, 'save' ) ) ) {
333
+		if (is_callable(array($order, 'save'))) {
335 334
 			$order->save();
336 335
 		}
337 336
 
338
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
337
+		do_action('wc_gateway_stripe_process_response', $response, $order);
339 338
 
340 339
 		return $response;
341 340
 	}
@@ -348,10 +347,10 @@  discard block
 block discarded – undo
348 347
 	 * @param int $order_id
349 348
 	 * @return null
350 349
 	 */
351
-	public function send_failed_order_email( $order_id ) {
350
+	public function send_failed_order_email($order_id) {
352 351
 		$emails = WC()->mailer()->get_emails();
353
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
354
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
352
+		if ( ! empty($emails) && ! empty($order_id)) {
353
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
355 354
 		}
356 355
 	}
357 356
 
@@ -363,7 +362,7 @@  discard block
 block discarded – undo
363 362
 	 * @param object $order
364 363
 	 * @return object $details
365 364
 	 */
366
-	public function get_owner_details( $order ) {
365
+	public function get_owner_details($order) {
367 366
 		$billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name();
368 367
 		$billing_last_name  = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name();
369 368
 
@@ -374,8 +373,8 @@  discard block
 block discarded – undo
374 373
 
375 374
 		$phone                             = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone();
376 375
 
377
-		if ( ! empty( $phone ) ) {
378
-			$details['phone']              = $phone;
376
+		if ( ! empty($phone)) {
377
+			$details['phone'] = $phone;
379 378
 		}
380 379
 
381 380
 		$details['address']['line1']       = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1();
@@ -385,7 +384,7 @@  discard block
 block discarded – undo
385 384
 		$details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode();
386 385
 		$details['address']['country']     = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country();
387 386
 
388
-		return (object) apply_filters( 'wc_stripe_owner_details', $details, $order );
387
+		return (object) apply_filters('wc_stripe_owner_details', $details, $order);
389 388
 	}
390 389
 
391 390
 	/**
@@ -394,16 +393,16 @@  discard block
 block discarded – undo
394 393
 	 * @since 4.0.3
395 394
 	 */
396 395
 	public function get_source_object() {
397
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
396
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
398 397
 
399
-		if ( empty( $source ) ) {
398
+		if (empty($source)) {
400 399
 			return '';
401 400
 		}
402 401
 
403
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
402
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
404 403
 
405
-		if ( ! empty( $source_object->error ) ) {
406
-			throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message );
404
+		if ( ! empty($source_object->error)) {
405
+			throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message);
407 406
 		}
408 407
 
409 408
 		return $source_object;
@@ -416,11 +415,11 @@  discard block
 block discarded – undo
416 415
 	 * @param object $source_object
417 416
 	 * @return bool
418 417
 	 */
419
-	public function is_3ds_required( $source_object ) {
418
+	public function is_3ds_required($source_object) {
420 419
 		return (
421
-			$source_object && ! empty( $source_object->card ) ) &&
422
-			( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
423
-			( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure )
420
+			$source_object && ! empty($source_object->card) ) &&
421
+			('card' === $source_object->type && 'required' === $source_object->card->three_d_secure ||
422
+			($this->three_d_secure && 'optional' === $source_object->card->three_d_secure)
424 423
 		);
425 424
 	}
426 425
 
@@ -431,8 +430,8 @@  discard block
 block discarded – undo
431 430
 	 * @param object $source_object
432 431
 	 * @return bool
433 432
 	 */
434
-	public function is_3ds_card( $source_object ) {
435
-		return ( $source_object && 'three_d_secure' === $source_object->type );
433
+	public function is_3ds_card($source_object) {
434
+		return ($source_object && 'three_d_secure' === $source_object->type);
436 435
 	}
437 436
 
438 437
 	/**
@@ -445,22 +444,22 @@  discard block
 block discarded – undo
445 444
 	 * @param string $return_url
446 445
 	 * @return mixed
447 446
 	 */
448
-	public function create_3ds_source( $order, $source_object, $return_url = '' ) {
447
+	public function create_3ds_source($order, $source_object, $return_url = '') {
449 448
 		$currency                    = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency();
450 449
 		$order_id                    = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
451
-		$return_url                  = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url;
450
+		$return_url                  = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url;
452 451
 
453 452
 		$post_data                   = array();
454
-		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency );
455
-		$post_data['currency']       = strtolower( $currency );
453
+		$post_data['amount']         = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency);
454
+		$post_data['currency']       = strtolower($currency);
456 455
 		$post_data['type']           = 'three_d_secure';
457
-		$post_data['owner']          = $this->get_owner_details( $order );
458
-		$post_data['three_d_secure'] = array( 'card' => $source_object->id );
459
-		$post_data['redirect']       = array( 'return_url' => $return_url );
456
+		$post_data['owner']          = $this->get_owner_details($order);
457
+		$post_data['three_d_secure'] = array('card' => $source_object->id);
458
+		$post_data['redirect']       = array('return_url' => $return_url);
460 459
 
461
-		WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' );
460
+		WC_Stripe_Logger::log('Info: Begin creating 3DS source...');
462 461
 
463
-		return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' );
462
+		return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources');
464 463
 	}
465 464
 
466 465
 	/**
@@ -477,54 +476,54 @@  discard block
 block discarded – undo
477 476
 	 * @throws Exception When card was not added or for and invalid card.
478 477
 	 * @return object
479 478
 	 */
480
-	public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) {
481
-		$customer           = new WC_Stripe_Customer( $user_id );
479
+	public function prepare_source($source_object = '', $user_id, $force_save_source = false) {
480
+		$customer           = new WC_Stripe_Customer($user_id);
482 481
 		$set_customer       = true;
483
-		$force_save_source  = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer );
482
+		$force_save_source  = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer);
484 483
 		$source_id          = '';
485 484
 		$wc_token_id        = false;
486
-		$payment_method     = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe';
485
+		$payment_method     = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe';
487 486
 
488 487
 		// New CC info was entered and we have a new source to process.
489
-		if ( ! empty( $source_object ) ) {
488
+		if ( ! empty($source_object)) {
490 489
 			$source_id = $source_object->id;
491 490
 
492 491
 			// This checks to see if customer opted to save the payment method to file.
493
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
492
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
494 493
 
495 494
 			/**
496 495
 			 * This is true if the user wants to store the card to their account.
497 496
 			 * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is
498 497
 			 * actually reusable. Either that or force_save_source is true.
499 498
 			 */
500
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) {
501
-				$response = $customer->add_source( $source_object->id );
499
+			if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) {
500
+				$response = $customer->add_source($source_object->id);
502 501
 
503
-				if ( ! empty( $response->error ) ) {
504
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
502
+				if ( ! empty($response->error)) {
503
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
505 504
 				}
506 505
 			}
507
-		} elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) {
506
+		} elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) {
508 507
 			// Use an existing token, and then process the payment.
509
-			$wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] );
510
-			$wc_token    = WC_Payment_Tokens::get( $wc_token_id );
508
+			$wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']);
509
+			$wc_token    = WC_Payment_Tokens::get($wc_token_id);
511 510
 
512
-			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) {
513
-				WC()->session->set( 'refresh_totals', true );
514
-				throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
511
+			if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) {
512
+				WC()->session->set('refresh_totals', true);
513
+				throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
515 514
 			}
516 515
 
517 516
 			$source_id = $wc_token->get_token();
518
-		} elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) {
519
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
520
-			$maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] );
517
+		} elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) {
518
+			$stripe_token     = wc_clean($_POST['stripe_token']);
519
+			$maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']);
521 520
 
522 521
 			// This is true if the user wants to store the card to their account.
523
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) {
524
-				$response = $customer->add_source( $stripe_token );
522
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) {
523
+				$response = $customer->add_source($stripe_token);
525 524
 
526
-				if ( ! empty( $response->error ) ) {
527
-					throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
525
+				if ( ! empty($response->error)) {
526
+					throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
528 527
 				}
529 528
 			} else {
530 529
 				$set_customer = false;
@@ -532,7 +531,7 @@  discard block
 block discarded – undo
532 531
 			}
533 532
 		}
534 533
 
535
-		if ( ! $set_customer ) {
534
+		if ( ! $set_customer) {
536 535
 			$customer_id = false;
537 536
 		} else {
538 537
 			$customer_id = $customer->get_id() ? $customer->get_id() : false;
@@ -558,37 +557,37 @@  discard block
 block discarded – undo
558 557
 	 * @param object $order
559 558
 	 * @return object
560 559
 	 */
561
-	public function prepare_order_source( $order = null ) {
560
+	public function prepare_order_source($order = null) {
562 561
 		$stripe_customer = new WC_Stripe_Customer();
563 562
 		$stripe_source   = false;
564 563
 		$token_id        = false;
565 564
 
566
-		if ( $order ) {
565
+		if ($order) {
567 566
 			$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
568 567
 
569
-			$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
568
+			$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
570 569
 
571
-			if ( $stripe_customer_id ) {
572
-				$stripe_customer->set_id( $stripe_customer_id );
570
+			if ($stripe_customer_id) {
571
+				$stripe_customer->set_id($stripe_customer_id);
573 572
 			}
574 573
 
575
-			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true );
574
+			$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true);
576 575
 
577 576
 			// Since 4.0.0, we changed card to source so we need to account for that.
578
-			if ( empty( $source_id ) ) {
579
-				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true );
577
+			if (empty($source_id)) {
578
+				$source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true);
580 579
 
581 580
 				// Take this opportunity to update the key name.
582
-				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 );
581
+				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);
583 582
 
584
-				if ( is_callable( array( $order, 'save' ) ) ) {
583
+				if (is_callable(array($order, 'save'))) {
585 584
 					$order->save();
586 585
 				}
587 586
 			}
588 587
 
589
-			if ( $source_id ) {
588
+			if ($source_id) {
590 589
 				$stripe_source = $source_id;
591
-			} elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) {
590
+			} elseif (apply_filters('wc_stripe_use_default_customer_source', true)) {
592 591
 				/*
593 592
 				 * We can attempt to charge the customer's default source
594 593
 				 * by sending empty source id.
@@ -612,27 +611,27 @@  discard block
 block discarded – undo
612 611
 	 * @param WC_Order $order For to which the source applies.
613 612
 	 * @param stdClass $source Source information.
614 613
 	 */
615
-	public function save_source_to_order( $order, $source ) {
614
+	public function save_source_to_order($order, $source) {
616 615
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
617 616
 
618 617
 		// Store source in the order.
619
-		if ( $source->customer ) {
620
-			if ( WC_Stripe_Helper::is_pre_30() ) {
621
-				update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
618
+		if ($source->customer) {
619
+			if (WC_Stripe_Helper::is_pre_30()) {
620
+				update_post_meta($order_id, '_stripe_customer_id', $source->customer);
622 621
 			} else {
623
-				$order->update_meta_data( '_stripe_customer_id', $source->customer );
622
+				$order->update_meta_data('_stripe_customer_id', $source->customer);
624 623
 			}
625 624
 		}
626 625
 
627
-		if ( $source->source ) {
628
-			if ( WC_Stripe_Helper::is_pre_30() ) {
629
-				update_post_meta( $order_id, '_stripe_source_id', $source->source );
626
+		if ($source->source) {
627
+			if (WC_Stripe_Helper::is_pre_30()) {
628
+				update_post_meta($order_id, '_stripe_source_id', $source->source);
630 629
 			} else {
631
-				$order->update_meta_data( '_stripe_source_id', $source->source );
630
+				$order->update_meta_data('_stripe_source_id', $source->source);
632 631
 			}
633 632
 		}
634 633
 
635
-		if ( is_callable( array( $order, 'save' ) ) ) {
634
+		if (is_callable(array($order, 'save'))) {
636 635
 			$order->save();
637 636
 		}
638 637
 	}
@@ -646,35 +645,35 @@  discard block
 block discarded – undo
646 645
 	 * @param object $order The order object
647 646
 	 * @param int $balance_transaction_id
648 647
 	 */
649
-	public function update_fees( $order, $balance_transaction_id ) {
648
+	public function update_fees($order, $balance_transaction_id) {
650 649
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
651 650
 
652
-		$balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id );
651
+		$balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id);
653 652
 
654
-		if ( empty( $balance_transaction->error ) ) {
655
-			if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) {
653
+		if (empty($balance_transaction->error)) {
654
+			if (isset($balance_transaction) && isset($balance_transaction->fee)) {
656 655
 				// Fees and Net needs to both come from Stripe to be accurate as the returned
657 656
 				// values are in the local currency of the Stripe account, not from WC.
658
-				$fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0;
659
-				$net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0;
657
+				$fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0;
658
+				$net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0;
660 659
 
661 660
 				// Current data fee & net.
662
-				$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 );
663
-				$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 );
661
+				$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);
662
+				$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);
664 663
 
665 664
 				// Calculation.
666 665
 				$fee = $fee_current + $fee_refund;
667 666
 				$net = $net_current + $net_refund;
668 667
 
669
-				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 );
670
-				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 );
668
+				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);
669
+				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);
671 670
 
672
-				if ( is_callable( array( $order, 'save' ) ) ) {
671
+				if (is_callable(array($order, 'save'))) {
673 672
 					$order->save();
674 673
 				}
675 674
 			}
676 675
 		} else {
677
-			WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" );
676
+			WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}");
678 677
 		}
679 678
 	}
680 679
 
@@ -687,33 +686,33 @@  discard block
 block discarded – undo
687 686
 	 * @param  float $amount
688 687
 	 * @return bool
689 688
 	 */
690
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
691
-		$order = wc_get_order( $order_id );
689
+	public function process_refund($order_id, $amount = null, $reason = '') {
690
+		$order = wc_get_order($order_id);
692 691
 
693
-		if ( ! $order || ! $order->get_transaction_id() ) {
692
+		if ( ! $order || ! $order->get_transaction_id()) {
694 693
 			return false;
695 694
 		}
696 695
 
697 696
 		$request = array();
698 697
 
699
-		if ( WC_Stripe_Helper::is_pre_30() ) {
700
-			$order_currency = get_post_meta( $order_id, '_order_currency', true );
701
-			$captured       = get_post_meta( $order_id, '_stripe_charge_captured', true );
698
+		if (WC_Stripe_Helper::is_pre_30()) {
699
+			$order_currency = get_post_meta($order_id, '_order_currency', true);
700
+			$captured       = get_post_meta($order_id, '_stripe_charge_captured', true);
702 701
 		} else {
703 702
 			$order_currency = $order->get_currency();
704
-			$captured       = $order->get_meta( '_stripe_charge_captured', true );
703
+			$captured       = $order->get_meta('_stripe_charge_captured', true);
705 704
 		}
706 705
 
707
-		if ( ! is_null( $amount ) ) {
708
-			$request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency );
706
+		if ( ! is_null($amount)) {
707
+			$request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency);
709 708
 		}
710 709
 
711 710
 		// If order is only authorized, don't pass amount.
712
-		if ( 'yes' !== $captured ) {
713
-			unset( $request['amount'] );
711
+		if ('yes' !== $captured) {
712
+			unset($request['amount']);
714 713
 		}
715 714
 
716
-		if ( $reason ) {
715
+		if ($reason) {
717 716
 			$request['metadata'] = array(
718 717
 				'reason' => $reason,
719 718
 			);
@@ -721,33 +720,33 @@  discard block
 block discarded – undo
721 720
 
722 721
 		$request['charge'] = $order->get_transaction_id();
723 722
 
724
-		WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" );
723
+		WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}");
725 724
 
726
-		$response = WC_Stripe_API::request( $request, 'refunds' );
725
+		$response = WC_Stripe_API::request($request, 'refunds');
727 726
 
728
-		if ( ! empty( $response->error ) ) {
729
-			WC_Stripe_Logger::log( 'Error: ' . $response->error->message );
727
+		if ( ! empty($response->error)) {
728
+			WC_Stripe_Logger::log('Error: ' . $response->error->message);
730 729
 
731 730
 			return $response;
732 731
 
733
-		} elseif ( ! empty( $response->id ) ) {
734
-			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 );
732
+		} elseif ( ! empty($response->id)) {
733
+			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);
735 734
 
736
-			$amount = wc_price( $response->amount / 100 );
735
+			$amount = wc_price($response->amount / 100);
737 736
 
738
-			if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
739
-				$amount = wc_price( $response->amount );
737
+			if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) {
738
+				$amount = wc_price($response->amount);
740 739
 			}
741 740
 
742
-			if ( isset( $response->balance_transaction ) ) {
743
-				$this->update_fees( $order, $response->balance_transaction );
741
+			if (isset($response->balance_transaction)) {
742
+				$this->update_fees($order, $response->balance_transaction);
744 743
 			}
745 744
 
746 745
 			/* translators: 1) dollar amount 2) transaction id 3) refund message */
747
-			$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' );
746
+			$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');
748 747
 
749
-			$order->add_order_note( $refund_message );
750
-			WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
748
+			$order->add_order_note($refund_message);
749
+			WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message)));
751 750
 
752 751
 			return true;
753 752
 		}
@@ -762,44 +761,44 @@  discard block
 block discarded – undo
762 761
 	 */
763 762
 	public function add_payment_method() {
764 763
 		$error     = false;
765
-		$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
764
+		$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
766 765
 		$source_id = '';
767 766
 
768
-		if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
767
+		if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) {
769 768
 			$error = true;
770 769
 		}
771 770
 
772
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
771
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
773 772
 
774
-		$source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : '';
773
+		$source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : '';
775 774
 
776
-		$source_object = WC_Stripe_API::retrieve( 'sources/' . $source );
775
+		$source_object = WC_Stripe_API::retrieve('sources/' . $source);
777 776
 
778
-		if ( isset( $source_object ) ) {
779
-			if ( ! empty( $source_object->error ) ) {
777
+		if (isset($source_object)) {
778
+			if ( ! empty($source_object->error)) {
780 779
 				$error = true;
781 780
 			}
782 781
 
783 782
 			$source_id = $source_object->id;
784
-		} elseif ( isset( $_POST['stripe_token'] ) ) {
785
-			$source_id = wc_clean( $_POST['stripe_token'] );
783
+		} elseif (isset($_POST['stripe_token'])) {
784
+			$source_id = wc_clean($_POST['stripe_token']);
786 785
 		}
787 786
 
788
-		$response = $stripe_customer->add_source( $source_id );
787
+		$response = $stripe_customer->add_source($source_id);
789 788
 
790
-		if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) {
789
+		if ( ! $response || is_wp_error($response) || ! empty($response->error)) {
791 790
 			$error = true;
792 791
 		}
793 792
 
794
-		if ( $error ) {
795
-			wc_add_notice( $error_msg, 'error' );
796
-			WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg );
793
+		if ($error) {
794
+			wc_add_notice($error_msg, 'error');
795
+			WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg);
797 796
 			return;
798 797
 		}
799 798
 
800 799
 		return array(
801 800
 			'result'   => 'success',
802
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
801
+			'redirect' => wc_get_endpoint_url('payment-methods'),
803 802
 		);
804 803
 	}
805 804
 
@@ -816,10 +815,10 @@  discard block
 block discarded – undo
816 815
 		 * Stripe expects Norwegian to only be passed NO.
817 816
 		 * But WP has different dialects.
818 817
 		 */
819
-		if ( 'NO' === substr( $locale, 3, 2 ) ) {
818
+		if ('NO' === substr($locale, 3, 2)) {
820 819
 			$locale = 'no';
821 820
 		} else {
822
-			$locale = substr( get_locale(), 0, 2 );
821
+			$locale = substr(get_locale(), 0, 2);
823 822
 		}
824 823
 
825 824
 		return $locale;
Please login to merge, or discard this patch.
includes/class-wc-stripe-webhook-handler.php 1 patch
Spacing   +173 added lines, -173 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
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	public function __construct() {
22 22
 		$this->retry_interval = 2;
23
-		add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) );
23
+		add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook'));
24 24
 	}
25 25
 
26 26
 	/**
@@ -30,24 +30,24 @@  discard block
 block discarded – undo
30 30
 	 * @version 4.0.0
31 31
 	 */
32 32
 	public function check_for_webhook() {
33
-		if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] )
34
-			|| ! isset( $_GET['wc-api'] )
35
-			|| ( 'wc_stripe' !== $_GET['wc-api'] )
33
+		if (('POST' !== $_SERVER['REQUEST_METHOD'])
34
+			|| ! isset($_GET['wc-api'])
35
+			|| ('wc_stripe' !== $_GET['wc-api'])
36 36
 		) {
37 37
 			return;
38 38
 		}
39 39
 
40
-		$request_body    = file_get_contents( 'php://input' );
41
-		$request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER );
40
+		$request_body    = file_get_contents('php://input');
41
+		$request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER);
42 42
 
43 43
 		// Validate it to make sure it is legit.
44
-		if ( $this->is_valid_request( $request_headers, $request_body ) ) {
45
-			$this->process_webhook( $request_body );
46
-			status_header( 200 );
44
+		if ($this->is_valid_request($request_headers, $request_body)) {
45
+			$this->process_webhook($request_body);
46
+			status_header(200);
47 47
 			exit;
48 48
 		} else {
49
-			WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) );
50
-			status_header( 400 );
49
+			WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true));
50
+			status_header(400);
51 51
 			exit;
52 52
 		}
53 53
 	}
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
 	 * @param string $request_body The request body from Stripe.
63 63
 	 * @return bool
64 64
 	 */
65
-	public function is_valid_request( $request_headers = null, $request_body = null ) {
66
-		if ( null === $request_headers || null === $request_body ) {
65
+	public function is_valid_request($request_headers = null, $request_body = null) {
66
+		if (null === $request_headers || null === $request_body) {
67 67
 			return false;
68 68
 		}
69 69
 
70
-		if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) {
70
+		if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) {
71 71
 			return false;
72 72
 		}
73 73
 
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 	 * @version 4.0.0
84 84
 	 */
85 85
 	public function get_request_headers() {
86
-		if ( ! function_exists( 'getallheaders' ) ) {
86
+		if ( ! function_exists('getallheaders')) {
87 87
 			$headers = [];
88
-			foreach ( $_SERVER as $name => $value ) {
89
-				if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
90
-					$headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
88
+			foreach ($_SERVER as $name => $value) {
89
+				if ('HTTP_' === substr($name, 0, 5)) {
90
+					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
91 91
 				}
92 92
 			}
93 93
 
@@ -106,30 +106,30 @@  discard block
 block discarded – undo
106 106
 	 * @param object $notification
107 107
 	 * @param bool $retry
108 108
 	 */
109
-	public function process_webhook_payment( $notification, $retry = true ) {
109
+	public function process_webhook_payment($notification, $retry = true) {
110 110
 		// The following 2 payment methods are synchronous so does not need to be handle via webhook.
111
-		if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) {
111
+		if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) {
112 112
 			return;
113 113
 		}
114 114
 
115
-		$order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id );
115
+		$order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id);
116 116
 
117
-		if ( ! $order ) {
118
-			WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id );
117
+		if ( ! $order) {
118
+			WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id);
119 119
 			return;
120 120
 		}
121 121
 
122 122
 		$order_id  = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
123 123
 		$source_id = $notification->data->object->id;
124 124
 
125
-		$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
125
+		$is_pending_receiver = ('receiver' === $notification->data->object->flow);
126 126
 
127 127
 		try {
128
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) {
128
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status()) {
129 129
 				return;
130 130
 			}
131 131
 
132
-			if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) {
132
+			if ('on-hold' === $order->get_status() && ! $is_pending_receiver) {
133 133
 				return;
134 134
 			}
135 135
 
@@ -137,100 +137,100 @@  discard block
 block discarded – undo
137 137
 			$response = null;
138 138
 
139 139
 			// This will throw exception if not valid.
140
-			$this->validate_minimum_order_amount( $order );
140
+			$this->validate_minimum_order_amount($order);
141 141
 
142
-			WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
142
+			WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
143 143
 
144 144
 			// Prep source object.
145 145
 			$source_object           = new stdClass();
146 146
 			$source_object->token_id = '';
147
-			$source_object->customer = $this->get_stripe_customer_id( $order );
147
+			$source_object->customer = $this->get_stripe_customer_id($order);
148 148
 			$source_object->source   = $source_id;
149 149
 
150 150
 			// Make the request.
151
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
151
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
152 152
 
153
-			if ( ! empty( $response->error ) ) {
153
+			if ( ! empty($response->error)) {
154 154
 				// If it is an API error such connection or server, let's retry.
155
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
156
-					if ( $retry ) {
157
-						sleep( 5 );
158
-						return $this->process_webhook_payment( $notification, false );
155
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
156
+					if ($retry) {
157
+						sleep(5);
158
+						return $this->process_webhook_payment($notification, false);
159 159
 					} else {
160 160
 						$localized_message = 'API connection error and retries exhausted.';
161
-						$order->add_order_note( $localized_message );
162
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
161
+						$order->add_order_note($localized_message);
162
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
163 163
 					}
164 164
 				}
165 165
 
166 166
 				// We want to retry.
167
-				if ( $this->is_retryable_error( $response->error ) ) {
168
-					if ( $retry ) {
167
+				if ($this->is_retryable_error($response->error)) {
168
+					if ($retry) {
169 169
 						// Don't do anymore retries after this.
170
-						if ( 5 <= $this->retry_interval ) {
170
+						if (5 <= $this->retry_interval) {
171 171
 
172
-							return $this->process_webhook_payment( $notification, false );
172
+							return $this->process_webhook_payment($notification, false);
173 173
 						}
174 174
 
175
-						sleep( $this->retry_interval );
175
+						sleep($this->retry_interval);
176 176
 
177 177
 						$this->retry_interval++;
178
-						return $this->process_webhook_payment( $notification, true );
178
+						return $this->process_webhook_payment($notification, true);
179 179
 					} else {
180
-						$localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' );
181
-						$order->add_order_note( $localized_message );
182
-						throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
180
+						$localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe');
181
+						$order->add_order_note($localized_message);
182
+						throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
183 183
 					}
184 184
 				}
185 185
 
186 186
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
187
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
188
-					if ( WC_Stripe_Helper::is_pre_30() ) {
189
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
190
-						delete_post_meta( $order_id, '_stripe_customer_id' );
187
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
188
+					if (WC_Stripe_Helper::is_pre_30()) {
189
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
190
+						delete_post_meta($order_id, '_stripe_customer_id');
191 191
 					} else {
192
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
193
-						$order->delete_meta_data( '_stripe_customer_id' );
192
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
193
+						$order->delete_meta_data('_stripe_customer_id');
194 194
 						$order->save();
195 195
 					}
196 196
 
197
-					return $this->process_webhook_payment( $notification, false );
197
+					return $this->process_webhook_payment($notification, false);
198 198
 
199
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
199
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
200 200
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
201
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
201
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
202 202
 					$wc_token->delete();
203
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
204
-					$order->add_order_note( $message );
205
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
203
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
204
+					$order->add_order_note($message);
205
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
206 206
 				}
207 207
 
208 208
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
209 209
 
210
-				if ( 'card_error' === $response->error->type ) {
211
-					$localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
210
+				if ('card_error' === $response->error->type) {
211
+					$localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
212 212
 				} else {
213
-					$localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
213
+					$localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
214 214
 				}
215 215
 
216
-				$order->add_order_note( $localized_message );
216
+				$order->add_order_note($localized_message);
217 217
 
218
-				throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message );
218
+				throw new WC_Stripe_Exception(print_r($response, true), $localized_message);
219 219
 			}
220 220
 
221
-			do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order );
221
+			do_action('wc_gateway_stripe_process_webhook_payment', $response, $order);
222 222
 
223
-			$this->process_response( $response, $order );
223
+			$this->process_response($response, $order);
224 224
 
225
-		} catch ( WC_Stripe_Exception $e ) {
226
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
225
+		} catch (WC_Stripe_Exception $e) {
226
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
227 227
 
228
-			do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order );
228
+			do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order);
229 229
 
230
-			$statuses = array( 'pending', 'failed' );
230
+			$statuses = array('pending', 'failed');
231 231
 
232
-			if ( $order->has_status( $statuses ) ) {
233
-				$this->send_failed_order_email( $order_id );
232
+			if ($order->has_status($statuses)) {
233
+				$this->send_failed_order_email($order_id);
234 234
 			}
235 235
 		}
236 236
 	}
@@ -243,20 +243,20 @@  discard block
 block discarded – undo
243 243
 	 * @since 4.0.0
244 244
 	 * @param object $notification
245 245
 	 */
246
-	public function process_webhook_dispute( $notification ) {
247
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
246
+	public function process_webhook_dispute($notification) {
247
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
248 248
 
249
-		if ( ! $order ) {
250
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
249
+		if ( ! $order) {
250
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
251 251
 			return;
252 252
 		}
253 253
 
254
-		$order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) );
254
+		$order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe'));
255 255
 
256
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
256
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
257 257
 
258 258
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
259
-		$this->send_failed_order_email( $order_id );
259
+		$this->send_failed_order_email($order_id);
260 260
 	}
261 261
 
262 262
 	/**
@@ -267,41 +267,41 @@  discard block
 block discarded – undo
267 267
 	 * @version 4.0.0
268 268
 	 * @param object $notification
269 269
 	 */
270
-	public function process_webhook_capture( $notification ) {
271
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
270
+	public function process_webhook_capture($notification) {
271
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
272 272
 
273
-		if ( ! $order ) {
274
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
273
+		if ( ! $order) {
274
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
279 279
 
280
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
281
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
282
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
280
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
281
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
282
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
283 283
 
284
-			if ( $charge && 'no' === $captured ) {
285
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
284
+			if ($charge && 'no' === $captured) {
285
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
286 286
 
287 287
 				// Store other data such as fees
288
-				WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
288
+				WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
289 289
 
290
-				if ( isset( $notification->data->object->balance_transaction ) ) {
291
-					$this->update_fees( $order, $notification->data->object->balance_transaction );
290
+				if (isset($notification->data->object->balance_transaction)) {
291
+					$this->update_fees($order, $notification->data->object->balance_transaction);
292 292
 				}
293 293
 
294
-				if ( is_callable( array( $order, 'save' ) ) ) {
294
+				if (is_callable(array($order, 'save'))) {
295 295
 					$order->save();
296 296
 				}
297 297
 
298 298
 				/* translators: transaction id */
299
-				$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
299
+				$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
300 300
 
301 301
 				// Check and see if capture is partial.
302
-				if ( $this->is_partial_capture( $notification ) ) {
303
-					$order->set_total( $this->get_partial_amount_to_charge( $notification ) );
304
-					$order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) );
302
+				if ($this->is_partial_capture($notification)) {
303
+					$order->set_total($this->get_partial_amount_to_charge($notification));
304
+					$order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe'));
305 305
 					$order->save();
306 306
 				}
307 307
 			}
@@ -316,38 +316,38 @@  discard block
 block discarded – undo
316 316
 	 * @version 4.0.0
317 317
 	 * @param object $notification
318 318
 	 */
319
-	public function process_webhook_charge_succeeded( $notification ) {
319
+	public function process_webhook_charge_succeeded($notification) {
320 320
 		// The following payment methods are synchronous so does not need to be handle via webhook.
321
-		if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) {
321
+		if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) {
322 322
 			return;
323 323
 		}
324 324
 
325
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
325
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
326 326
 
327
-		if ( ! $order ) {
328
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
327
+		if ( ! $order) {
328
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
329 329
 			return;
330 330
 		}
331 331
 
332 332
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
333 333
 
334
-		if ( 'on-hold' !== $order->get_status() ) {
334
+		if ('on-hold' !== $order->get_status()) {
335 335
 			return;
336 336
 		}
337 337
 
338 338
 		// Store other data such as fees
339
-		WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id );
339
+		WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id);
340 340
 
341
-		if ( isset( $notification->data->object->balance_transaction ) ) {
342
-			$this->update_fees( $order, $notification->data->object->balance_transaction );
341
+		if (isset($notification->data->object->balance_transaction)) {
342
+			$this->update_fees($order, $notification->data->object->balance_transaction);
343 343
 		}
344 344
 
345
-		if ( is_callable( array( $order, 'save' ) ) ) {
345
+		if (is_callable(array($order, 'save'))) {
346 346
 			$order->save();
347 347
 		}
348 348
 
349 349
 		/* translators: transaction id */
350
-		$order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) );
350
+		$order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id));
351 351
 	}
352 352
 
353 353
 	/**
@@ -358,23 +358,23 @@  discard block
 block discarded – undo
358 358
 	 * @version 4.0.0
359 359
 	 * @param object $notification
360 360
 	 */
361
-	public function process_webhook_charge_failed( $notification ) {
362
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
361
+	public function process_webhook_charge_failed($notification) {
362
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
363 363
 
364
-		if ( ! $order ) {
365
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
364
+		if ( ! $order) {
365
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
366 366
 			return;
367 367
 		}
368 368
 
369 369
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
370 370
 
371
-		if ( 'on-hold' !== $order->get_status() ) {
371
+		if ('on-hold' !== $order->get_status()) {
372 372
 			return;
373 373
 		}
374 374
 
375
-		$order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) );
375
+		$order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe'));
376 376
 
377
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
377
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
378 378
 	}
379 379
 
380 380
 	/**
@@ -385,23 +385,23 @@  discard block
 block discarded – undo
385 385
 	 * @version 4.0.0
386 386
 	 * @param object $notification
387 387
 	 */
388
-	public function process_webhook_source_canceled( $notification ) {
389
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
388
+	public function process_webhook_source_canceled($notification) {
389
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
390 390
 
391
-		if ( ! $order ) {
392
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
391
+		if ( ! $order) {
392
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
393 393
 			return;
394 394
 		}
395 395
 
396 396
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
397 397
 
398
-		if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) {
398
+		if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) {
399 399
 			return;
400 400
 		}
401 401
 
402
-		$order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) );
402
+		$order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe'));
403 403
 
404
-		do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification );
404
+		do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification);
405 405
 	}
406 406
 
407 407
 	/**
@@ -412,42 +412,42 @@  discard block
 block discarded – undo
412 412
 	 * @version 4.0.0
413 413
 	 * @param object $notification
414 414
 	 */
415
-	public function process_webhook_refund( $notification ) {
416
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id );
415
+	public function process_webhook_refund($notification) {
416
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id);
417 417
 
418
-		if ( ! $order ) {
419
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id );
418
+		if ( ! $order) {
419
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id);
420 420
 			return;
421 421
 		}
422 422
 
423 423
 		$order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id();
424 424
 
425
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
426
-			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
427
-			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
428
-			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true );
425
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
426
+			$charge    = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
427
+			$captured  = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
428
+			$refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true);
429 429
 
430 430
 			// If the refund ID matches, don't continue to prevent double refunding.
431
-			if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
431
+			if ($notification->data->object->refunds->data[0]->id === $refund_id) {
432 432
 				return;
433 433
 			}
434 434
 
435 435
 			// Only refund captured charge.
436
-			if ( $charge ) {
437
-				$reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' );
436
+			if ($charge) {
437
+				$reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe');
438 438
 
439 439
 				// Create the refund.
440
-				$refund = wc_create_refund( array(
440
+				$refund = wc_create_refund(array(
441 441
 					'order_id'       => $order_id,
442
-					'amount'         => $this->get_refund_amount( $notification ),
442
+					'amount'         => $this->get_refund_amount($notification),
443 443
 					'reason'         => $reason,
444
-				) );
444
+				));
445 445
 
446
-				if ( is_wp_error( $refund ) ) {
447
-					WC_Stripe_Logger::log( $refund->get_error_message() );
446
+				if (is_wp_error($refund)) {
447
+					WC_Stripe_Logger::log($refund->get_error_message());
448 448
 				}
449 449
 
450
-				$order->add_order_note( $reason );
450
+				$order->add_order_note($reason);
451 451
 			}
452 452
 		}
453 453
 	}
@@ -458,17 +458,17 @@  discard block
 block discarded – undo
458 458
 	 * @since 4.0.6
459 459
 	 * @param object $notification
460 460
 	 */
461
-	public function process_review_opened( $notification ) {
462
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
461
+	public function process_review_opened($notification) {
462
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
463 463
 
464
-		if ( ! $order ) {
465
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
464
+		if ( ! $order) {
465
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
466 466
 			return;
467 467
 		}
468 468
 
469
-		if ( $notification->data->object->open ) {
469
+		if ($notification->data->object->open) {
470 470
 			/* translators: token is the reason returned. */
471
-			$order->update_status( 'on-hold', sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your Stripe Dashboard to review the issue. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ) );
471
+			$order->update_status('on-hold', sprintf(__('A review has been opened for this order. Action is needed. Please go to your Stripe Dashboard to review the issue. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason));
472 472
 		}
473 473
 	}
474 474
 
@@ -478,21 +478,21 @@  discard block
 block discarded – undo
478 478
 	 * @since 4.0.6
479 479
 	 * @param object $notification
480 480
 	 */
481
-	public function process_review_closed( $notification ) {
482
-		$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
481
+	public function process_review_closed($notification) {
482
+		$order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge);
483 483
 
484
-		if ( ! $order ) {
485
-			WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge );
484
+		if ( ! $order) {
485
+			WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge);
486 486
 			return;
487 487
 		}
488 488
 
489 489
 		/* translators: token is the reason returned. */
490
-		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
490
+		$message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason);
491 491
 
492
-		if ( 'on-hold' === $order->get_status() ) {
493
-			$order->update_status( 'processing', $message );
492
+		if ('on-hold' === $order->get_status()) {
493
+			$order->update_status('processing', $message);
494 494
 		} else {
495
-			$order->add_note( $message );
495
+			$order->add_note($message);
496 496
 		}
497 497
 	}
498 498
 
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 	 * @version 4.0.0
504 504
 	 * @param object $notification
505 505
 	 */
506
-	public function is_partial_capture( $notification ) {
506
+	public function is_partial_capture($notification) {
507 507
 		return 0 < $notification->data->object->amount_refunded;
508 508
 	}
509 509
 
@@ -514,11 +514,11 @@  discard block
 block discarded – undo
514 514
 	 * @version 4.0.0
515 515
 	 * @param object $notification
516 516
 	 */
517
-	public function get_refund_amount( $notification ) {
518
-		if ( $this->is_partial_capture( $notification ) ) {
517
+	public function get_refund_amount($notification) {
518
+		if ($this->is_partial_capture($notification)) {
519 519
 			$amount = $notification->data->object->amount_refunded / 100;
520 520
 
521
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
521
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
522 522
 				$amount = $notification->data->object->amount_refunded;
523 523
 			}
524 524
 
@@ -535,12 +535,12 @@  discard block
 block discarded – undo
535 535
 	 * @version 4.0.0
536 536
 	 * @param object $notification
537 537
 	 */
538
-	public function get_partial_amount_to_charge( $notification ) {
539
-		if ( $this->is_partial_capture( $notification ) ) {
540
-			$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100;
538
+	public function get_partial_amount_to_charge($notification) {
539
+		if ($this->is_partial_capture($notification)) {
540
+			$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100;
541 541
 
542
-			if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
543
-				$amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded );
542
+			if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) {
543
+				$amount = ($notification->data->object->amount - $notification->data->object->amount_refunded);
544 544
 			}
545 545
 
546 546
 			return $amount;
@@ -556,44 +556,44 @@  discard block
 block discarded – undo
556 556
 	 * @version 4.0.0
557 557
 	 * @param string $request_body
558 558
 	 */
559
-	public function process_webhook( $request_body ) {
560
-		$notification = json_decode( $request_body );
559
+	public function process_webhook($request_body) {
560
+		$notification = json_decode($request_body);
561 561
 
562
-		switch ( $notification->type ) {
562
+		switch ($notification->type) {
563 563
 			case 'source.chargeable':
564
-				$this->process_webhook_payment( $notification );
564
+				$this->process_webhook_payment($notification);
565 565
 				break;
566 566
 
567 567
 			case 'source.canceled':
568
-				$this->process_webhook_source_canceled( $notification );
568
+				$this->process_webhook_source_canceled($notification);
569 569
 				break;
570 570
 
571 571
 			case 'charge.succeeded':
572
-				$this->process_webhook_charge_succeeded( $notification );
572
+				$this->process_webhook_charge_succeeded($notification);
573 573
 				break;
574 574
 
575 575
 			case 'charge.failed':
576
-				$this->process_webhook_charge_failed( $notification );
576
+				$this->process_webhook_charge_failed($notification);
577 577
 				break;
578 578
 
579 579
 			case 'charge.captured':
580
-				$this->process_webhook_capture( $notification );
580
+				$this->process_webhook_capture($notification);
581 581
 				break;
582 582
 
583 583
 			case 'charge.dispute.created':
584
-				$this->process_webhook_dispute( $notification );
584
+				$this->process_webhook_dispute($notification);
585 585
 				break;
586 586
 
587 587
 			case 'charge.refunded':
588
-				$this->process_webhook_refund( $notification );
588
+				$this->process_webhook_refund($notification);
589 589
 				break;
590 590
 
591 591
 			case 'review.opened':
592
-				$this->process_review_opened( $notification );
592
+				$this->process_review_opened($notification);
593 593
 				break;
594 594
 
595 595
 			case 'review.closed':
596
-				$this->process_review_closed( $notification );
596
+				$this->process_review_closed($notification);
597 597
 				break;
598 598
 
599 599
 		}
Please login to merge, or discard this patch.