Completed
Push — master ( df51f4...d1c9a7 )
by Roy
02:28
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +286 added lines, -286 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
 
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public function __construct() {
122 122
 		$this->id                   = 'stripe';
123
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
124
-		$this->method_description   = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
123
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
124
+		$this->method_description   = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe');
125 125
 		$this->has_fields           = true;
126 126
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
127 127
 		$this->supports             = array(
@@ -149,54 +149,54 @@  discard block
 block discarded – undo
149 149
 		$this->init_settings();
150 150
 
151 151
 		// Get setting values.
152
-		$this->title                  = $this->get_option( 'title' );
153
-		$this->description            = $this->get_option( 'description' );
154
-		$this->enabled                = $this->get_option( 'enabled' );
155
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
156
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
157
-		$this->statement_descriptor   = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
158
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
159
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
160
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
161
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
162
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
163
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
164
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
165
-		$this->apple_pay              = 'yes' === $this->get_option( 'apple_pay', 'yes' );
166
-		$this->apple_pay_domain_set   = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' );
167
-		$this->apple_pay_button       = $this->get_option( 'apple_pay_button', 'black' );
168
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
169
-		$this->allow_remember_me      = 'yes' === $this->get_option( 'allow_remember_me', 'no' );
170
-
171
-		if ( $this->stripe_checkout ) {
172
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
152
+		$this->title                  = $this->get_option('title');
153
+		$this->description            = $this->get_option('description');
154
+		$this->enabled                = $this->get_option('enabled');
155
+		$this->testmode               = 'yes' === $this->get_option('testmode');
156
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
157
+		$this->statement_descriptor   = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
158
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
159
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
160
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
161
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
162
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
163
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
164
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
165
+		$this->apple_pay              = 'yes' === $this->get_option('apple_pay', 'yes');
166
+		$this->apple_pay_domain_set   = 'yes' === $this->get_option('apple_pay_domain_set', 'no');
167
+		$this->apple_pay_button       = $this->get_option('apple_pay_button', 'black');
168
+		$this->logging                = 'yes' === $this->get_option('logging');
169
+		$this->allow_remember_me      = 'yes' === $this->get_option('allow_remember_me', 'no');
170
+
171
+		if ($this->stripe_checkout) {
172
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
173 173
 
174 174
 			// Stripe checkout does not support add payment method.
175
-			if ( is_add_payment_method_page() ) {
176
-				if ( false !== ( $key = array_search( 'add_payment_method', $this->supports ) ) ) {
177
-					unset( $this->supports[ $key ] );
175
+			if (is_add_payment_method_page()) {
176
+				if (false !== ($key = array_search('add_payment_method', $this->supports))) {
177
+					unset($this->supports[$key]);
178 178
 				}
179 179
 
180
-				if ( false !== ( $key = array_search( 'tokenization', $this->supports ) ) ) {
181
-					unset( $this->supports[ $key ] );
180
+				if (false !== ($key = array_search('tokenization', $this->supports))) {
181
+					unset($this->supports[$key]);
182 182
 				}
183 183
 			}
184 184
 		}
185 185
 
186
-		if ( $this->testmode ) {
187
-			$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">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' );
188
-			$this->description  = trim( $this->description );
186
+		if ($this->testmode) {
187
+			$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">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing');
188
+			$this->description  = trim($this->description);
189 189
 		}
190 190
 
191
-		WC_Stripe_API::set_secret_key( $this->secret_key );
191
+		WC_Stripe_API::set_secret_key($this->secret_key);
192 192
 
193 193
 		$this->init_apple_pay();
194 194
 
195 195
 		// Hooks.
196
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
197
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
198
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
199
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
196
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
197
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
198
+		add_action('admin_notices', array($this, 'admin_notices'));
199
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
200 200
 	}
201 201
 
202 202
 	/**
@@ -206,24 +206,24 @@  discard block
 block discarded – undo
206 206
 	 * @return string
207 207
 	 */
208 208
 	public function get_icon() {
209
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
210
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
209
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
210
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
211 211
 
212
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
213
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
214
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
212
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
213
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
214
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
215 215
 
216
-		if ( 'USD' === get_woocommerce_currency() ) {
217
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
218
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
219
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
216
+		if ('USD' === get_woocommerce_currency()) {
217
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
218
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
219
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
220 220
 		}
221 221
 
222
-		if ( $this->bitcoin && $this->stripe_checkout ) {
223
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
222
+		if ($this->bitcoin && $this->stripe_checkout) {
223
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
224 224
 		}
225 225
 
226
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
226
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
227 227
 	}
228 228
 
229 229
 	/**
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
 	 *
235 235
 	 * @return float|int
236 236
 	 */
237
-	public function get_stripe_amount( $total, $currency = '' ) {
238
-		if ( ! $currency ) {
237
+	public function get_stripe_amount($total, $currency = '') {
238
+		if ( ! $currency) {
239 239
 			$currency = get_woocommerce_currency();
240 240
 		}
241
-		switch ( strtoupper( $currency ) ) {
241
+		switch (strtoupper($currency)) {
242 242
 			// Zero decimal currencies.
243 243
 			case 'BIF' :
244 244
 			case 'CLP' :
@@ -255,10 +255,10 @@  discard block
 block discarded – undo
255 255
 			case 'XAF' :
256 256
 			case 'XOF' :
257 257
 			case 'XPF' :
258
-				$total = absint( $total );
258
+				$total = absint($total);
259 259
 				break;
260 260
 			default :
261
-				$total = round( $total, 2 ) * 100; // In cents.
261
+				$total = round($total, 2) * 100; // In cents.
262 262
 				break;
263 263
 		}
264 264
 		return $total;
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 	public function init_apple_pay() {
274 274
 		if ( 
275 275
 			is_admin() && 
276
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && 
277
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
278
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section']
276
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] && 
277
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
278
+			isset($_GET['section']) && 'stripe' === $_GET['section']
279 279
 		) {
280 280
 			$this->process_apple_pay_verification();
281 281
 		}
@@ -288,9 +288,9 @@  discard block
 block discarded – undo
288 288
 	 * @version 3.1.0
289 289
 	 * @param string $secret_key
290 290
 	 */
291
-	private function _register_apple_pay_domain( $secret_key = '' ) {
292
-		if ( empty( $secret_key ) ) {
293
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
291
+	private function _register_apple_pay_domain($secret_key = '') {
292
+		if (empty($secret_key)) {
293
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
294 294
 		}
295 295
 
296 296
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
 			'Authorization' => 'Bearer ' . $secret_key,
305 305
 		);
306 306
 
307
-		$response = wp_remote_post( $endpoint, array(
307
+		$response = wp_remote_post($endpoint, array(
308 308
 			'headers' => $headers,
309
-			'body'    => http_build_query( $data ),
310
-		) );
309
+			'body'    => http_build_query($data),
310
+		));
311 311
 
312
-		if ( 200 !== $response['response']['code'] ) {
313
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response['response']['message'] ) );
312
+		if (200 !== $response['response']['code']) {
313
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response['response']['message']));
314 314
 		}
315 315
 	}
316 316
 
@@ -321,48 +321,48 @@  discard block
 block discarded – undo
321 321
 	 * @version 3.1.0
322 322
 	 */
323 323
 	public function process_apple_pay_verification() {
324
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
324
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
325 325
 
326 326
 		try {
327
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
327
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
328 328
 			$dir      = '.well-known';
329 329
 			$file     = 'apple-developer-merchantid-domain-association';
330 330
 			$fullpath = $path . '/' . $dir . '/' . $file;
331 331
 
332
-			if ( 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
332
+			if ('yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
333 333
 				return;
334 334
 			}
335 335
 
336
-			if ( ! file_exists( $path . '/' . $dir ) ) {
337
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
338
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
336
+			if ( ! file_exists($path . '/' . $dir)) {
337
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
338
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
339 339
 				}
340 340
 			}
341 341
 
342
-			if ( ! file_exists( $fullpath ) ) {
343
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
344
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
342
+			if ( ! file_exists($fullpath)) {
343
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
344
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
345 345
 				}
346 346
 			}
347 347
 
348 348
 			// At this point then the domain association folder and file should be available.
349 349
 			// Proceed to verify/and or verify again.
350
-			$this->_register_apple_pay_domain( $this->secret_key );
350
+			$this->_register_apple_pay_domain($this->secret_key);
351 351
 
352 352
 			// No errors to this point, verification success!
353 353
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
354 354
 			$this->apple_pay_domain_set = true;
355 355
 
356
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
356
+			update_option('woocommerce_stripe_settings', $gateway_settings);
357 357
 
358
-			$this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) );
358
+			$this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe'));
359 359
 
360
-		} catch ( Exception $e ) {
360
+		} catch (Exception $e) {
361 361
 			$gateway_settings['apple_pay_domain_set'] = 'no';
362 362
 
363
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
363
+			update_option('woocommerce_stripe_settings', $gateway_settings);
364 364
 
365
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
365
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
366 366
 		}
367 367
 	}
368 368
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	 * Check if SSL is enabled and notify the user
371 371
 	 */
372 372
 	public function admin_notices() {
373
-		if ( 'no' === $this->enabled ) {
373
+		if ('no' === $this->enabled) {
374 374
 			return;
375 375
 		}
376 376
 
@@ -379,13 +379,13 @@  discard block
 block discarded – undo
379 379
 		 * when setting screen is displayed. So if domain verification is not set,
380 380
 		 * something went wrong so lets notify user.
381 381
 		 */
382
-		if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) {
383
-			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue.', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
382
+		if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) {
383
+			echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue.', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
384 384
 		}
385 385
 
386 386
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
387
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
388
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>';
387
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
388
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>';
389 389
 		}
390 390
 	}
391 391
 
@@ -393,11 +393,11 @@  discard block
 block discarded – undo
393 393
 	 * Check if this gateway is enabled
394 394
 	 */
395 395
 	public function is_available() {
396
-		if ( 'yes' === $this->enabled ) {
397
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
396
+		if ('yes' === $this->enabled) {
397
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
398 398
 				return false;
399 399
 			}
400
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
400
+			if ( ! $this->secret_key || ! $this->publishable_key) {
401 401
 				return false;
402 402
 			}
403 403
 			return true;
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 	 * Initialise Gateway Settings Form Fields
410 410
 	 */
411 411
 	public function init_form_fields() {
412
-		$this->form_fields = include( 'settings-stripe.php' );
412
+		$this->form_fields = include('settings-stripe.php');
413 413
 	}
414 414
 
415 415
 	/**
@@ -417,54 +417,54 @@  discard block
 block discarded – undo
417 417
 	 */
418 418
 	public function payment_fields() {
419 419
 		$user                 = wp_get_current_user();
420
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
420
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
421 421
 		$total                = WC()->cart->total;
422 422
 
423 423
 		// If paying from order, we need to get total from order not cart.
424
-		if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) {
425
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
424
+		if (isset($_GET['pay_for_order']) && isset($_GET['key'])) {
425
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
426 426
 			$total = $order->get_total();
427 427
 		}
428 428
 
429
-		if ( $user->ID ) {
430
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
429
+		if ($user->ID) {
430
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
431 431
 			$user_email = $user_email ? $user_email : $user->user_email;
432 432
 		} else {
433 433
 			$user_email = '';
434 434
 		}
435 435
 
436
-		if ( is_add_payment_method_page() ) {
437
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
436
+		if (is_add_payment_method_page()) {
437
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
438 438
 		} else {
439 439
 			$pay_button_text = '';
440 440
 		}
441 441
 
442 442
 		echo '<div
443 443
 			id="stripe-payment-data"
444
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
444
+			data-panel-label="' . esc_attr($pay_button_text) . '"
445 445
 			data-description=""
446
-			data-email="' . esc_attr( $user_email ) . '"
447
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
448
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
449
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
450
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
451
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
452
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
453
-			data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">';
446
+			data-email="' . esc_attr($user_email) . '"
447
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
448
+			data-name="' . esc_attr($this->statement_descriptor) . '"
449
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
450
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
451
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
452
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
453
+			data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">';
454 454
 
455
-		if ( $this->description ) {
456
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
455
+		if ($this->description) {
456
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
457 457
 		}
458 458
 
459
-		if ( $display_tokenization ) {
459
+		if ($display_tokenization) {
460 460
 			$this->tokenization_script();
461 461
 			$this->saved_payment_methods();
462 462
 		}
463 463
 
464
-		if ( ! $this->stripe_checkout ) {
464
+		if ( ! $this->stripe_checkout) {
465 465
 			$this->form();
466 466
 
467
-			if ( $display_tokenization ) {
467
+			if ($display_tokenization) {
468 468
 				$this->save_payment_method_checkbox();
469 469
 			}
470 470
 		}
@@ -480,20 +480,20 @@  discard block
 block discarded – undo
480 480
 	 * @return array
481 481
 	 */
482 482
 	public function get_localized_messages() {
483
-		return apply_filters( 'wc_stripe_localized_messages', array(
484
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
485
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
486
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
487
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
488
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
489
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
490
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
491
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
492
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
493
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
494
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
495
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
496
-		) );
483
+		return apply_filters('wc_stripe_localized_messages', array(
484
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
485
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
486
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
487
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
488
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
489
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
490
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
491
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
492
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
493
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
494
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
495
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
496
+		));
497 497
 	}
498 498
 
499 499
 	/**
@@ -503,28 +503,28 @@  discard block
 block discarded – undo
503 503
 	 * @version 3.1.0
504 504
 	 */
505 505
 	public function admin_scripts() {
506
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
506
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
507 507
 			return;
508 508
 		}
509 509
 
510
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
510
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
511 511
 
512
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
512
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
513 513
 
514 514
 		$stripe_admin_params = array(
515 515
 			'localized_messages' => array(
516
-				'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ),
517
-				'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ),
518
-				're_verify_button_text'  => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ),
519
-				'missing_secret_key'     => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ),
516
+				'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'),
517
+				'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'),
518
+				're_verify_button_text'  => __('Re-verify Domain', 'woocommerce-gateway-stripe'),
519
+				'missing_secret_key'     => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'),
520 520
 			),
521
-			'ajaxurl'            => admin_url( 'admin-ajax.php' ),
521
+			'ajaxurl'            => admin_url('admin-ajax.php'),
522 522
 			'nonce'              => array( 
523
-				'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ),
523
+				'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'),
524 524
 			),
525 525
 		);
526 526
 
527
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) );
527
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params));
528 528
 	}
529 529
 
530 530
 	/**
@@ -535,49 +535,49 @@  discard block
 block discarded – undo
535 535
 	 * @access public
536 536
 	 */
537 537
 	public function payment_scripts() {
538
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
538
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
539 539
 			return;
540 540
 		}
541 541
 
542
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
542
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
543 543
 
544
-		if ( $this->stripe_checkout ) {
545
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
546
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
544
+		if ($this->stripe_checkout) {
545
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
546
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
547 547
 		} else {
548
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
549
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
548
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
549
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
550 550
 		}
551 551
 
552 552
 		$stripe_params = array(
553 553
 			'key'                  => $this->publishable_key,
554
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
555
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
554
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
555
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
556 556
 		);
557 557
 
558 558
 		// If we're on the pay page we need to pass stripe.js the address of the order.
559
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
560
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
561
-			$order    = wc_get_order( $order_id );
559
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
560
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
561
+			$order    = wc_get_order($order_id);
562 562
 
563
-			$stripe_params['billing_first_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
564
-			$stripe_params['billing_last_name']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
565
-			$stripe_params['billing_address_1']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1();
566
-			$stripe_params['billing_address_2']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2();
567
-			$stripe_params['billing_state']      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_state : $order->get_billing_state();
568
-			$stripe_params['billing_city']       = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_city : $order->get_billing_city();
569
-			$stripe_params['billing_postcode']   = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode();
570
-			$stripe_params['billing_country']    = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_country : $order->get_billing_country();
563
+			$stripe_params['billing_first_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
564
+			$stripe_params['billing_last_name']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
565
+			$stripe_params['billing_address_1']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1();
566
+			$stripe_params['billing_address_2']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2();
567
+			$stripe_params['billing_state']      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_state : $order->get_billing_state();
568
+			$stripe_params['billing_city']       = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_city : $order->get_billing_city();
569
+			$stripe_params['billing_postcode']   = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_postcode : $order->get_billing_postcode();
570
+			$stripe_params['billing_country']    = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_country : $order->get_billing_country();
571 571
 		}
572 572
 
573
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
574
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
575
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
573
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
574
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
575
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
576 576
 
577 577
 		// merge localized messages to be use in JS
578
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
578
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
579 579
 
580
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
580
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
581 581
 	}
582 582
 
583 583
 	/**
@@ -586,35 +586,35 @@  discard block
 block discarded – undo
586 586
 	 * @param  object $source
587 587
 	 * @return array()
588 588
 	 */
589
-	protected function generate_payment_request( $order, $source ) {
589
+	protected function generate_payment_request($order, $source) {
590 590
 		$post_data                = array();
591
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
592
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
593
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
591
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
592
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
593
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
594 594
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
595 595
 
596
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
597
-		$billing_first_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
598
-		$billing_last_name  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
596
+		$billing_email      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
597
+		$billing_first_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
598
+		$billing_last_name  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
599 599
 
600
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
600
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
601 601
 			$post_data['receipt_email'] = $billing_email;
602 602
 		}
603 603
 
604
-		$post_data['expand[]']    = 'balance_transaction';
604
+		$post_data['expand[]'] = 'balance_transaction';
605 605
 
606 606
 		$metadata = array(
607
-			__( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
608
-			__( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
607
+			__('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
608
+			__('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
609 609
 		);
610 610
 
611
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
611
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
612 612
 
613
-		if ( $source->customer ) {
613
+		if ($source->customer) {
614 614
 			$post_data['customer'] = $source->customer;
615 615
 		}
616 616
 
617
-		if ( $source->source ) {
617
+		if ($source->source) {
618 618
 			$post_data['source'] = $source->source;
619 619
 		}
620 620
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 		 * @param WC_Order $order
627 627
 		 * @param object $source
628 628
 		 */
629
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
629
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
630 630
 	}
631 631
 
632 632
 	/**
@@ -638,37 +638,37 @@  discard block
 block discarded – undo
638 638
 	 * @throws Exception When card was not added or for and invalid card.
639 639
 	 * @return object
640 640
 	 */
641
-	protected function get_source( $user_id, $force_customer = false ) {
642
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
641
+	protected function get_source($user_id, $force_customer = false) {
642
+		$stripe_customer = new WC_Stripe_Customer($user_id);
643 643
 		$stripe_source   = false;
644 644
 		$token_id        = false;
645 645
 
646 646
 		// New CC info was entered and we have a new token to process
647
-		if ( isset( $_POST['stripe_token'] ) ) {
648
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
649
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
647
+		if (isset($_POST['stripe_token'])) {
648
+			$stripe_token     = wc_clean($_POST['stripe_token']);
649
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
650 650
 
651 651
 			// This is true if the user wants to store the card to their account.
652
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
653
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
652
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
653
+				$stripe_source = $stripe_customer->add_card($stripe_token);
654 654
 
655
-				if ( is_wp_error( $stripe_source ) ) {
656
-					throw new Exception( $stripe_source->get_error_message() );
655
+				if (is_wp_error($stripe_source)) {
656
+					throw new Exception($stripe_source->get_error_message());
657 657
 				}
658 658
 			} else {
659 659
 				// Not saving token, so don't define customer either.
660 660
 				$stripe_source   = $stripe_token;
661 661
 				$stripe_customer = false;
662 662
 			}
663
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
663
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
664 664
 			// Use an existing token, and then process the payment
665 665
 
666
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
667
-			$token    = WC_Payment_Tokens::get( $token_id );
666
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
667
+			$token    = WC_Payment_Tokens::get($token_id);
668 668
 
669
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
670
-				WC()->session->set( 'refresh_totals', true );
671
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
669
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
670
+				WC()->session->set('refresh_totals', true);
671
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
672 672
 			}
673 673
 
674 674
 			$stripe_source = $token->get_token();
@@ -692,19 +692,19 @@  discard block
 block discarded – undo
692 692
 	 * @param object $order
693 693
 	 * @return object
694 694
 	 */
695
-	protected function get_order_source( $order = null ) {
695
+	protected function get_order_source($order = null) {
696 696
 		$stripe_customer = new WC_Stripe_Customer();
697 697
 		$stripe_source   = false;
698 698
 		$token_id        = false;
699 699
 
700
-		if ( $order ) {
701
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
700
+		if ($order) {
701
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
702 702
 
703
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) {
704
-				$stripe_customer->set_id( $meta_value );
703
+			if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) {
704
+				$stripe_customer->set_id($meta_value);
705 705
 			}
706 706
 
707
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) {
707
+			if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) {
708 708
 				$stripe_source = $meta_value;
709 709
 			}
710 710
 		}
@@ -727,57 +727,57 @@  discard block
 block discarded – undo
727 727
 	 *
728 728
 	 * @return array|void
729 729
 	 */
730
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
730
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
731 731
 		try {
732
-			$order  = wc_get_order( $order_id );
733
-			$source = $this->get_source( get_current_user_id(), $force_customer );
732
+			$order  = wc_get_order($order_id);
733
+			$source = $this->get_source(get_current_user_id(), $force_customer);
734 734
 
735
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
736
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
737
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
738
-				throw new Exception( $error_msg );
735
+			if (empty($source->source) && empty($source->customer)) {
736
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
737
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
738
+				throw new Exception($error_msg);
739 739
 			}
740 740
 
741 741
 			// Store source to order meta.
742
-			$this->save_source( $order, $source );
742
+			$this->save_source($order, $source);
743 743
 
744 744
 			// Handle payment.
745
-			if ( $order->get_total() > 0 ) {
745
+			if ($order->get_total() > 0) {
746 746
 
747
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
748
-					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::get_minimum_amount() / 100 ) ) );
747
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
748
+					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::get_minimum_amount() / 100)));
749 749
 				}
750 750
 
751
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
751
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
752 752
 
753 753
 				// Make the request.
754
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
754
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
755 755
 
756
-				if ( is_wp_error( $response ) ) {
756
+				if (is_wp_error($response)) {
757 757
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
758
-					if ( 'customer' === $response->get_error_code() && $retry ) {
759
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
760
-						return $this->process_payment( $order_id, false, $force_customer );
758
+					if ('customer' === $response->get_error_code() && $retry) {
759
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
760
+						return $this->process_payment($order_id, false, $force_customer);
761 761
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
762
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
763
-						$token = WC_Payment_Tokens::get( $source->token_id );
762
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
763
+						$token = WC_Payment_Tokens::get($source->token_id);
764 764
 						$token->delete();
765
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
766
-						$order->add_order_note( $message );
767
-						throw new Exception( $message );
765
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
766
+						$order->add_order_note($message);
767
+						throw new Exception($message);
768 768
 					}
769 769
 
770 770
 					$localized_messages = $this->get_localized_messages();
771 771
 
772
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
772
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
773 773
 
774
-					$order->add_order_note( $message );
774
+					$order->add_order_note($message);
775 775
 
776
-					throw new Exception( $message );
776
+					throw new Exception($message);
777 777
 				}
778 778
 
779 779
 				// Process valid response.
780
-				$this->process_response( $response, $order );
780
+				$this->process_response($response, $order);
781 781
 			} else {
782 782
 				$order->payment_complete();
783 783
 			}
@@ -785,23 +785,23 @@  discard block
 block discarded – undo
785 785
 			// Remove cart.
786 786
 			WC()->cart->empty_cart();
787 787
 
788
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
788
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
789 789
 
790 790
 			// Return thank you page redirect.
791 791
 			return array(
792 792
 				'result'   => 'success',
793
-				'redirect' => $this->get_return_url( $order ),
793
+				'redirect' => $this->get_return_url($order),
794 794
 			);
795 795
 
796
-		} catch ( Exception $e ) {
797
-			wc_add_notice( $e->getMessage(), 'error' );
798
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
796
+		} catch (Exception $e) {
797
+			wc_add_notice($e->getMessage(), 'error');
798
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
799 799
 
800
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
801
-				$this->send_failed_order_email( $order_id );
800
+			if ($order->has_status(array('pending', 'failed'))) {
801
+				$this->send_failed_order_email($order_id);
802 802
 			}
803 803
 
804
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
804
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
805 805
 
806 806
 			return array(
807 807
 				'result'   => 'fail',
@@ -816,56 +816,56 @@  discard block
 block discarded – undo
816 816
 	 * @param WC_Order $order For to which the source applies.
817 817
 	 * @param stdClass $source Source information.
818 818
 	 */
819
-	protected function save_source( $order, $source ) {
820
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
819
+	protected function save_source($order, $source) {
820
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
821 821
 
822 822
 		// Store source in the order.
823
-		if ( $source->customer ) {
824
-			update_post_meta( $order_id, '_stripe_customer_id', $source->customer );
823
+		if ($source->customer) {
824
+			update_post_meta($order_id, '_stripe_customer_id', $source->customer);
825 825
 		}
826
-		if ( $source->source ) {
827
-			update_post_meta( $order_id, '_stripe_card_id', $source->source );
826
+		if ($source->source) {
827
+			update_post_meta($order_id, '_stripe_card_id', $source->source);
828 828
 		}
829 829
 	}
830 830
 
831 831
 	/**
832 832
 	 * Store extra meta data for an order from a Stripe Response.
833 833
 	 */
834
-	public function process_response( $response, $order ) {
835
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
834
+	public function process_response($response, $order) {
835
+		$this->log('Processing response: ' . print_r($response, true));
836 836
 
837
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
837
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
838 838
 
839 839
 		// Store charge data
840
-		update_post_meta( $order_id, '_stripe_charge_id', $response->id );
841
-		update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
840
+		update_post_meta($order_id, '_stripe_charge_id', $response->id);
841
+		update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
842 842
 
843 843
 		// Store other data such as fees
844
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
844
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
845 845
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
846 846
 			// values are in the local currency of the Stripe account, not from WC.
847
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe::format_number( $response->balance_transaction, 'fee' ) : 0;
848
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe::format_number( $response->balance_transaction, 'net' ) : 0;
849
-			update_post_meta( $order_id, 'Stripe Fee', $fee );
850
-			update_post_meta( $order_id, 'Net Revenue From Stripe', $net );
847
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe::format_number($response->balance_transaction, 'fee') : 0;
848
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe::format_number($response->balance_transaction, 'net') : 0;
849
+			update_post_meta($order_id, 'Stripe Fee', $fee);
850
+			update_post_meta($order_id, 'Net Revenue From Stripe', $net);
851 851
 		}
852 852
 
853
-		if ( $response->captured ) {
854
-			$order->payment_complete( $response->id );
853
+		if ($response->captured) {
854
+			$order->payment_complete($response->id);
855 855
 
856
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
857
-			$order->add_order_note( $message );
858
-			$this->log( 'Success: ' . $message );
856
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
857
+			$order->add_order_note($message);
858
+			$this->log('Success: ' . $message);
859 859
 
860 860
 		} else {
861
-			add_post_meta( $order_id, '_transaction_id', $response->id, true );
861
+			add_post_meta($order_id, '_transaction_id', $response->id, true);
862 862
 
863
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
864
-				version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
863
+			if ($order->has_status(array('pending', 'failed'))) {
864
+				version_compare(WC_VERSION, '3.0.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
865 865
 			}
866 866
 
867
-			$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 ) );
868
-			$this->log( "Successful auth: $response->id" );
867
+			$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));
868
+			$this->log("Successful auth: $response->id");
869 869
 		}
870 870
 
871 871
 		return $response;
@@ -877,32 +877,32 @@  discard block
 block discarded – undo
877 877
 	 * @since 3.0.0
878 878
 	 */
879 879
 	public function add_payment_method() {
880
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
881
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
880
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
881
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
882 882
 			return;
883 883
 		}
884 884
 
885
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
886
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
885
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
886
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
887 887
 
888
-		if ( is_wp_error( $card ) ) {
888
+		if (is_wp_error($card)) {
889 889
 			$localized_messages = $this->get_localized_messages();
890
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
890
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
891 891
 
892 892
 			// loop through the errors to find matching localized message
893
-			foreach ( $card->errors as $error => $msg ) {
894
-				if ( isset( $localized_messages[ $error ] ) ) {
895
-					$error_msg = $localized_messages[ $error ];
893
+			foreach ($card->errors as $error => $msg) {
894
+				if (isset($localized_messages[$error])) {
895
+					$error_msg = $localized_messages[$error];
896 896
 				}
897 897
 			}
898 898
 
899
-			wc_add_notice( $error_msg, 'error' );
899
+			wc_add_notice($error_msg, 'error');
900 900
 			return;
901 901
 		}
902 902
 
903 903
 		return array(
904 904
 			'result'   => 'success',
905
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
905
+			'redirect' => wc_get_endpoint_url('payment-methods'),
906 906
 		);
907 907
 	}
908 908
 
@@ -912,36 +912,36 @@  discard block
 block discarded – undo
912 912
 	 * @param  float $amount
913 913
 	 * @return bool
914 914
 	 */
915
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
916
-		$order = wc_get_order( $order_id );
915
+	public function process_refund($order_id, $amount = null, $reason = '') {
916
+		$order = wc_get_order($order_id);
917 917
 
918
-		if ( ! $order || ! $order->get_transaction_id() ) {
918
+		if ( ! $order || ! $order->get_transaction_id()) {
919 919
 			return false;
920 920
 		}
921 921
 
922 922
 		$body = array();
923 923
 
924
-		if ( ! is_null( $amount ) ) {
925
-			$body['amount']	= $this->get_stripe_amount( $amount );
924
+		if ( ! is_null($amount)) {
925
+			$body['amount'] = $this->get_stripe_amount($amount);
926 926
 		}
927 927
 
928
-		if ( $reason ) {
928
+		if ($reason) {
929 929
 			$body['metadata'] = array(
930 930
 				'reason'	=> $reason,
931 931
 			);
932 932
 		}
933 933
 
934
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
934
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
935 935
 
936
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
936
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
937 937
 
938
-		if ( is_wp_error( $response ) ) {
939
-			$this->log( 'Error: ' . $response->get_error_message() );
938
+		if (is_wp_error($response)) {
939
+			$this->log('Error: ' . $response->get_error_message());
940 940
 			return $response;
941
-		} elseif ( ! empty( $response->id ) ) {
942
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
943
-			$order->add_order_note( $refund_message );
944
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
941
+		} elseif ( ! empty($response->id)) {
942
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
943
+			$order->add_order_note($refund_message);
944
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
945 945
 			return true;
946 946
 		}
947 947
 	}
@@ -954,10 +954,10 @@  discard block
 block discarded – undo
954 954
 	 * @param int $order_id
955 955
 	 * @return null
956 956
 	 */
957
-	public function send_failed_order_email( $order_id ) {
957
+	public function send_failed_order_email($order_id) {
958 958
 		$emails = WC()->mailer()->get_emails();
959
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
960
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
959
+		if ( ! empty($emails) && ! empty($order_id)) {
960
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
961 961
 		}
962 962
 	}
963 963
 
@@ -969,9 +969,9 @@  discard block
 block discarded – undo
969 969
 	 *
970 970
 	 * @param string $message
971 971
 	 */
972
-	public function log( $message ) {
973
-		if ( $this->logging ) {
974
-			WC_Stripe::log( $message );
972
+	public function log($message) {
973
+		if ($this->logging) {
974
+			WC_Stripe::log($message);
975 975
 		}
976 976
 	}
977 977
 }
Please login to merge, or discard this patch.
woocommerce-gateway-stripe.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -25,21 +25,21 @@  discard block
 block discarded – undo
25 25
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26
 */
27 27
 
28
-if ( ! defined( 'ABSPATH' ) ) {
28
+if ( ! defined('ABSPATH')) {
29 29
 	exit;
30 30
 }
31 31
 
32 32
 /**
33 33
  * Required minimums and constants
34 34
  */
35
-define( 'WC_STRIPE_VERSION', '3.1.2' );
36
-define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' );
37
-define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' );
38
-define( 'WC_STRIPE_MAIN_FILE', __FILE__ );
39
-define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
40
-define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
35
+define('WC_STRIPE_VERSION', '3.1.2');
36
+define('WC_STRIPE_MIN_PHP_VER', '5.6.0');
37
+define('WC_STRIPE_MIN_WC_VER', '2.5.0');
38
+define('WC_STRIPE_MAIN_FILE', __FILE__);
39
+define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
40
+define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
41 41
 
42
-if ( ! class_exists( 'WC_Stripe' ) ) :
42
+if ( ! class_exists('WC_Stripe')) :
43 43
 
44 44
 	class WC_Stripe {
45 45
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		 * @return Singleton The *Singleton* instance.
60 60
 		 */
61 61
 		public static function get_instance() {
62
-			if ( null === self::$instance ) {
62
+			if (null === self::$instance) {
63 63
 				self::$instance = new self();
64 64
 			}
65 65
 			return self::$instance;
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 		 * *Singleton* via the `new` operator from outside of this class.
109 109
 		 */
110 110
 		protected function __construct() {
111
-			add_action( 'admin_init', array( $this, 'check_environment' ) );
112
-			add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
113
-			add_action( 'plugins_loaded', array( $this, 'init' ) );
111
+			add_action('admin_init', array($this, 'check_environment'));
112
+			add_action('admin_notices', array($this, 'admin_notices'), 15);
113
+			add_action('plugins_loaded', array($this, 'init'));
114 114
 		}
115 115
 
116 116
 		/**
@@ -118,35 +118,35 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 		public function init() {
120 120
 			// Don't hook anything else in the plugin if we're in an incompatible environment
121
-			if ( self::get_environment_warning() ) {
121
+			if (self::get_environment_warning()) {
122 122
 				return;
123 123
 			}
124 124
 
125
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
126
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' );
125
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
126
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php');
127 127
 
128 128
 			// Init the gateway itself
129 129
 			$this->init_gateways();
130 130
 
131
-			add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
132
-			add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
133
-			add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
134
-			add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
135
-			add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
136
-			add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 );
137
-			add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 );
138
-			add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) );
139
-			add_action( 'wp_ajax_stripe_dismiss_request_api_notice', array( $this, 'dismiss_request_api_notice' ) );
140
-			add_action( 'wp_ajax_stripe_dismiss_apple_pay_notice', array( $this, 'dismiss_apple_pay_notice' ) );
141
-
142
-			include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' );
131
+			add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));
132
+			add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
133
+			add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
134
+			add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
135
+			add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
136
+			add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3);
137
+			add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2);
138
+			add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default'));
139
+			add_action('wp_ajax_stripe_dismiss_request_api_notice', array($this, 'dismiss_request_api_notice'));
140
+			add_action('wp_ajax_stripe_dismiss_apple_pay_notice', array($this, 'dismiss_apple_pay_notice'));
141
+
142
+			include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php');
143 143
 		}
144 144
 
145 145
 		/**
146 146
 		 * Allow this class and other classes to add slug keyed notices (to avoid duplication)
147 147
 		 */
148
-		public function add_admin_notice( $slug, $class, $message ) {
149
-			$this->notices[ $slug ] = array(
148
+		public function add_admin_notice($slug, $class, $message) {
149
+			$this->notices[$slug] = array(
150 150
 				'class'   => $class,
151 151
 				'message' => $message,
152 152
 			);
@@ -157,29 +157,29 @@  discard block
 block discarded – undo
157 157
 		 * or the environment changes after activation. Also handles upgrade routines.
158 158
 		 */
159 159
 		public function check_environment() {
160
-			if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'woocommerce_stripe_version' ) ) ) {
160
+			if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('woocommerce_stripe_version'))) {
161 161
 				$this->install();
162 162
 
163
-				do_action( 'woocommerce_stripe_updated' );
163
+				do_action('woocommerce_stripe_updated');
164 164
 			}
165 165
 
166 166
 			$environment_warning = self::get_environment_warning();
167 167
 
168
-			if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
169
-				$this->add_admin_notice( 'bad_environment', 'error', $environment_warning );
168
+			if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) {
169
+				$this->add_admin_notice('bad_environment', 'error', $environment_warning);
170 170
 			}
171 171
 
172 172
 			// Check if secret key present. Otherwise prompt, via notice, to go to
173 173
 			// setting.
174
-			if ( ! class_exists( 'WC_Stripe_API' ) ) {
175
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' );
174
+			if ( ! class_exists('WC_Stripe_API')) {
175
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php');
176 176
 			}
177 177
 
178 178
 			$secret = WC_Stripe_API::get_secret_key();
179 179
 
180
-			if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
180
+			if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
181 181
 				$setting_link = $this->get_setting_link();
182
-				$this->add_admin_notice( 'prompt_connect', '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 ) );
182
+				$this->add_admin_notice('prompt_connect', '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));
183 183
 			}
184 184
 		}
185 185
 
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 		 * @return bool
192 192
 		 */
193 193
 		private static function _update_plugin_version() {
194
-			delete_option( 'wc_stripe_version' );
195
-			add_option( 'wc_stripe_version', WC_STRIPE_VERSION );
194
+			delete_option('wc_stripe_version');
195
+			add_option('wc_stripe_version', WC_STRIPE_VERSION);
196 196
 
197 197
 			return true;
198 198
 		}
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 		 * @version 3.1.0
205 205
 		 */
206 206
 		public function dismiss_request_api_notice() {
207
-			add_option( 'wc_stripe_show_request_api_notice', 'no' );
207
+			add_option('wc_stripe_show_request_api_notice', 'no');
208 208
 		}
209 209
 
210 210
 		/**
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 		 * @version 3.1.0
215 215
 		 */
216 216
 		public function dismiss_apple_pay_notice() {
217
-			add_option( 'wc_stripe_show_apple_pay_notice', 'no' );
217
+			add_option('wc_stripe_show_apple_pay_notice', 'no');
218 218
 		}
219 219
 
220 220
 		/**
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 		 * @version 3.1.0
225 225
 		 */
226 226
 		public function install() {
227
-			if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) {
228
-				define( 'WC_STRIPE_INSTALLING', true );
227
+			if ( ! defined('WC_STRIPE_INSTALLING')) {
228
+				define('WC_STRIPE_INSTALLING', true);
229 229
 			}
230 230
 
231 231
 			$this->_update_plugin_version();
@@ -236,24 +236,24 @@  discard block
 block discarded – undo
236 236
 		 * found or false if the environment has no problems.
237 237
 		 */
238 238
 		static function get_environment_warning() {
239
-			if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
240
-				$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
239
+			if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
240
+				$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
241 241
 
242
-				return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() );
242
+				return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion());
243 243
 			}
244 244
 
245
-			if ( ! defined( 'WC_VERSION' ) ) {
246
-				return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' );
245
+			if ( ! defined('WC_VERSION')) {
246
+				return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe');
247 247
 			}
248 248
 
249
-			if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
250
-				$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
249
+			if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
250
+				$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
251 251
 
252
-				return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION );
252
+				return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION);
253 253
 			}
254 254
 
255
-			if ( ! function_exists( 'curl_init' ) ) {
256
-				return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' );
255
+			if ( ! function_exists('curl_init')) {
256
+				return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe');
257 257
 			}
258 258
 
259 259
 			return false;
@@ -264,15 +264,15 @@  discard block
 block discarded – undo
264 264
 		 *
265 265
 		 * @since 1.0.0
266 266
 		 */
267
-		public function plugin_action_links( $links ) {
267
+		public function plugin_action_links($links) {
268 268
 			$setting_link = $this->get_setting_link();
269 269
 
270 270
 			$plugin_links = array(
271
-				'<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>',
272
-				'<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>',
273
-				'<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>',
271
+				'<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>',
272
+				'<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>',
273
+				'<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>',
274 274
 			);
275
-			return array_merge( $plugin_links, $links );
275
+			return array_merge($plugin_links, $links);
276 276
 		}
277 277
 
278 278
 		/**
@@ -283,24 +283,24 @@  discard block
 block discarded – undo
283 283
 		 * @return string Setting link
284 284
 		 */
285 285
 		public function get_setting_link() {
286
-			$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
286
+			$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
287 287
 
288
-			$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
288
+			$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
289 289
 
290
-			return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
290
+			return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
291 291
 		}
292 292
 
293 293
 		/**
294 294
 		 * Display any notices we've collected thus far (e.g. for connection, disconnection)
295 295
 		 */
296 296
 		public function admin_notices() {
297
-			$show_request_api_notice = get_option( 'wc_stripe_show_request_api_notice' );
298
-			$show_apple_pay_notice   = get_option( 'wc_stripe_show_apple_pay_notice' );
297
+			$show_request_api_notice = get_option('wc_stripe_show_request_api_notice');
298
+			$show_apple_pay_notice   = get_option('wc_stripe_show_apple_pay_notice');
299 299
 
300
-			if ( empty( $show_apple_pay_notice ) ) {
300
+			if (empty($show_apple_pay_notice)) {
301 301
 				// @TODO remove this notice in the future.
302 302
 				?>
303
-				<div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php esc_html_e( 'New Feature! Stripe now supports Apple Pay. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe' ); ?></p></div>
303
+				<div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php esc_html_e('New Feature! Stripe now supports Apple Pay. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe'); ?></p></div>
304 304
 
305 305
 				<script type="application/javascript">
306 306
 					jQuery( '.wc-stripe-apple-pay-notice' ).on( 'click', '.notice-dismiss', function() {
@@ -308,17 +308,17 @@  discard block
 block discarded – undo
308 308
 							action: 'stripe_dismiss_apple_pay_notice'
309 309
 						};
310 310
 
311
-						jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data );
311
+						jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data );
312 312
 					});
313 313
 				</script>
314 314
 
315 315
 				<?php
316 316
 			}
317 317
 
318
-			if ( empty( $show_request_api_notice ) ) {
318
+			if (empty($show_request_api_notice)) {
319 319
 				// @TODO remove this notice in the future.
320 320
 				?>
321
-				<div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e( 'New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe' ); ?></p></div>
321
+				<div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e('New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe'); ?></p></div>
322 322
 				
323 323
 				<script type="application/javascript">
324 324
 					jQuery( '.wc-stripe-request-api-notice' ).on( 'click', '.notice-dismiss', function() {
@@ -326,16 +326,16 @@  discard block
 block discarded – undo
326 326
 							action: 'stripe_dismiss_request_api_notice'
327 327
 						};
328 328
 
329
-						jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data );
329
+						jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data );
330 330
 					});
331 331
 				</script>
332 332
 
333 333
 				<?php
334 334
 			}
335 335
 			
336
-			foreach ( (array) $this->notices as $notice_key => $notice ) {
337
-				echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>";
338
-				echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
336
+			foreach ((array) $this->notices as $notice_key => $notice) {
337
+				echo "<div class='" . esc_attr($notice['class']) . "'><p>";
338
+				echo wp_kses($notice['message'], array('a' => array('href' => array())));
339 339
 				echo '</p></div>';
340 340
 			}
341 341
 		}
@@ -346,28 +346,28 @@  discard block
 block discarded – undo
346 346
 		 * @since 1.0.0
347 347
 		 */
348 348
 		public function init_gateways() {
349
-			if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) {
349
+			if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) {
350 350
 				$this->subscription_support_enabled = true;
351 351
 			}
352 352
 
353
-			if ( class_exists( 'WC_Pre_Orders_Order' ) ) {
353
+			if (class_exists('WC_Pre_Orders_Order')) {
354 354
 				$this->pre_order_enabled = true;
355 355
 			}
356 356
 
357
-			if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
357
+			if ( ! class_exists('WC_Payment_Gateway')) {
358 358
 				return;
359 359
 			}
360 360
 
361
-			if ( class_exists( 'WC_Payment_Gateway_CC' ) ) {
362
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' );
363
-				include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' );
361
+			if (class_exists('WC_Payment_Gateway_CC')) {
362
+				include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php');
363
+				include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php');
364 364
 			} else {
365
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' );
366
-				include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' );
365
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php');
366
+				include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php');
367 367
 			}
368 368
 
369
-			load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
370
-			add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) );
369
+			load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages');
370
+			add_filter('woocommerce_payment_gateways', array($this, 'add_gateways'));
371 371
 			
372 372
 			$load_addons = (
373 373
 				$this->subscription_support_enabled
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 				$this->pre_order_enabled
376 376
 			);
377 377
 
378
-			if ( $load_addons ) {
379
-				require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' );
378
+			if ($load_addons) {
379
+				require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php');
380 380
 			}
381 381
 		}
382 382
 
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
 		 *
386 386
 		 * @since 1.0.0
387 387
 		 */
388
-		public function add_gateways( $methods ) {
389
-			if ( $this->subscription_support_enabled || $this->pre_order_enabled ) {
388
+		public function add_gateways($methods) {
389
+			if ($this->subscription_support_enabled || $this->pre_order_enabled) {
390 390
 				$methods[] = 'WC_Gateway_Stripe_Addons';
391 391
 			} else {
392 392
 				$methods[] = 'WC_Gateway_Stripe';
@@ -426,24 +426,24 @@  discard block
 block discarded – undo
426 426
 		 * @param object $balance_transaction
427 427
 		 * @param string $type Type of number to format
428 428
 		 */
429
-		public static function format_number( $balance_transaction, $type = 'fee' ) {
430
-			if ( ! is_object( $balance_transaction ) ) {
429
+		public static function format_number($balance_transaction, $type = 'fee') {
430
+			if ( ! is_object($balance_transaction)) {
431 431
 				return;
432 432
 			}
433 433
 
434
-			if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) {
435
-				if ( 'fee' === $type ) {
434
+			if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) {
435
+				if ('fee' === $type) {
436 436
 					return $balance_transaction->fee;
437 437
 				}
438 438
 
439 439
 				return $balance_transaction->net;
440 440
 			}
441 441
 
442
-			if ( 'fee' === $type ) {
443
-				return number_format( $balance_transaction->fee / 100, 2, '.', '' );
442
+			if ('fee' === $type) {
443
+				return number_format($balance_transaction->fee / 100, 2, '.', '');
444 444
 			}
445 445
 
446
-			return number_format( $balance_transaction->net / 100, 2, '.', '' ); 
446
+			return number_format($balance_transaction->net / 100, 2, '.', ''); 
447 447
 		}
448 448
 
449 449
 		/**
@@ -451,35 +451,35 @@  discard block
 block discarded – undo
451 451
 		 *
452 452
 		 * @param  int $order_id
453 453
 		 */
454
-		public function capture_payment( $order_id ) {
455
-			$order = wc_get_order( $order_id );
454
+		public function capture_payment($order_id) {
455
+			$order = wc_get_order($order_id);
456 456
 
457
-			if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) {
458
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
459
-				$captured = get_post_meta( $order_id, '_stripe_charge_captured', true );
457
+			if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) {
458
+				$charge   = get_post_meta($order_id, '_stripe_charge_id', true);
459
+				$captured = get_post_meta($order_id, '_stripe_charge_captured', true);
460 460
 
461
-				if ( $charge && 'no' === $captured ) {
462
-					$result = WC_Stripe_API::request( array(
461
+				if ($charge && 'no' === $captured) {
462
+					$result = WC_Stripe_API::request(array(
463 463
 						'amount'   => $order->get_total() * 100,
464 464
 						'expand[]' => 'balance_transaction',
465
-					), 'charges/' . $charge . '/capture' );
465
+					), 'charges/' . $charge . '/capture');
466 466
 
467
-					if ( is_wp_error( $result ) ) {
468
-						$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
467
+					if (is_wp_error($result)) {
468
+						$order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
469 469
 					} else {
470
-						$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
471
-						update_post_meta( $order_id, '_stripe_charge_captured', 'yes' );
470
+						$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
471
+						update_post_meta($order_id, '_stripe_charge_captured', 'yes');
472 472
 
473 473
 						// Store other data such as fees
474
-						update_post_meta( $order_id, 'Stripe Payment ID', $result->id );
474
+						update_post_meta($order_id, 'Stripe Payment ID', $result->id);
475 475
 
476
-						if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
476
+						if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
477 477
 							// Fees and Net needs to both come from Stripe to be accurate as the returned
478 478
 							// values are in the local currency of the Stripe account, not from WC.
479
-							$fee = ! empty( $result->balance_transaction->fee ) ? self::format_number( $result->balance_transaction, 'fee' ) : 0;
480
-							$net = ! empty( $result->balance_transaction->net ) ? self::format_number( $result->balance_transaction, 'net' ) : 0;
481
-							update_post_meta( $order_id, 'Stripe Fee', $fee );
482
-							update_post_meta( $order_id, 'Net Revenue From Stripe', $net );
479
+							$fee = ! empty($result->balance_transaction->fee) ? self::format_number($result->balance_transaction, 'fee') : 0;
480
+							$net = ! empty($result->balance_transaction->net) ? self::format_number($result->balance_transaction, 'net') : 0;
481
+							update_post_meta($order_id, 'Stripe Fee', $fee);
482
+							update_post_meta($order_id, 'Net Revenue From Stripe', $net);
483 483
 						}
484 484
 					}
485 485
 				}
@@ -491,23 +491,23 @@  discard block
 block discarded – undo
491 491
 		 *
492 492
 		 * @param  int $order_id
493 493
 		 */
494
-		public function cancel_payment( $order_id ) {
495
-			$order = wc_get_order( $order_id );
494
+		public function cancel_payment($order_id) {
495
+			$order = wc_get_order($order_id);
496 496
 
497
-			if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) {
498
-				$charge   = get_post_meta( $order_id, '_stripe_charge_id', true );
497
+			if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) {
498
+				$charge = get_post_meta($order_id, '_stripe_charge_id', true);
499 499
 
500
-				if ( $charge ) {
501
-					$result = WC_Stripe_API::request( array(
500
+				if ($charge) {
501
+					$result = WC_Stripe_API::request(array(
502 502
 						'amount' => $order->get_total() * 100,
503
-					), 'charges/' . $charge . '/refund' );
503
+					), 'charges/' . $charge . '/refund');
504 504
 
505
-					if ( is_wp_error( $result ) ) {
506
-						$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() );
505
+					if (is_wp_error($result)) {
506
+						$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message());
507 507
 					} else {
508
-						$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
509
-						delete_post_meta( $order_id, '_stripe_charge_captured' );
510
-						delete_post_meta( $order_id, '_stripe_charge_id' );
508
+						$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
509
+						delete_post_meta($order_id, '_stripe_charge_captured');
510
+						delete_post_meta($order_id, '_stripe_charge_id');
511 511
 					}
512 512
 				}
513 513
 			}
@@ -518,28 +518,28 @@  discard block
 block discarded – undo
518 518
 		 * @param array $tokens
519 519
 		 * @return array
520 520
 		 */
521
-		public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) {
522
-			if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) {
523
-				$stripe_customer = new WC_Stripe_Customer( $customer_id );
521
+		public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) {
522
+			if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) {
523
+				$stripe_customer = new WC_Stripe_Customer($customer_id);
524 524
 				$stripe_cards    = $stripe_customer->get_cards();
525 525
 				$stored_tokens   = array();
526 526
 
527
-				foreach ( $tokens as $token ) {
527
+				foreach ($tokens as $token) {
528 528
 					$stored_tokens[] = $token->get_token();
529 529
 				}
530 530
 
531
-				foreach ( $stripe_cards as $card ) {
532
-					if ( ! in_array( $card->id, $stored_tokens ) ) {
531
+				foreach ($stripe_cards as $card) {
532
+					if ( ! in_array($card->id, $stored_tokens)) {
533 533
 						$token = new WC_Payment_Token_CC();
534
-						$token->set_token( $card->id );
535
-						$token->set_gateway_id( 'stripe' );
536
-						$token->set_card_type( strtolower( $card->brand ) );
537
-						$token->set_last4( $card->last4 );
538
-						$token->set_expiry_month( $card->exp_month );
539
-						$token->set_expiry_year( $card->exp_year );
540
-						$token->set_user_id( $customer_id );
534
+						$token->set_token($card->id);
535
+						$token->set_gateway_id('stripe');
536
+						$token->set_card_type(strtolower($card->brand));
537
+						$token->set_last4($card->last4);
538
+						$token->set_expiry_month($card->exp_month);
539
+						$token->set_expiry_year($card->exp_year);
540
+						$token->set_user_id($customer_id);
541 541
 						$token->save();
542
-						$tokens[ $token->get_id() ] = $token;
542
+						$tokens[$token->get_id()] = $token;
543 543
 					}
544 544
 				}
545 545
 			}
@@ -549,21 +549,21 @@  discard block
 block discarded – undo
549 549
 		/**
550 550
 		 * Delete token from Stripe
551 551
 		 */
552
-		public function woocommerce_payment_token_deleted( $token_id, $token ) {
553
-			if ( 'stripe' === $token->get_gateway_id() ) {
554
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
555
-				$stripe_customer->delete_card( $token->get_token() );
552
+		public function woocommerce_payment_token_deleted($token_id, $token) {
553
+			if ('stripe' === $token->get_gateway_id()) {
554
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
555
+				$stripe_customer->delete_card($token->get_token());
556 556
 			}
557 557
 		}
558 558
 
559 559
 		/**
560 560
 		 * Set as default in Stripe
561 561
 		 */
562
-		public function woocommerce_payment_token_set_default( $token_id ) {
563
-			$token = WC_Payment_Tokens::get( $token_id );
564
-			if ( 'stripe' === $token->get_gateway_id() ) {
565
-				$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
566
-				$stripe_customer->set_default_card( $token->get_token() );
562
+		public function woocommerce_payment_token_set_default($token_id) {
563
+			$token = WC_Payment_Tokens::get($token_id);
564
+			if ('stripe' === $token->get_gateway_id()) {
565
+				$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
566
+				$stripe_customer->set_default_card($token->get_token());
567 567
 			}
568 568
 		}
569 569
 
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 		 */
573 573
 		public static function get_minimum_amount() {
574 574
 			// Check order amount
575
-			switch ( get_woocommerce_currency() ) {
575
+			switch (get_woocommerce_currency()) {
576 576
 				case 'USD':
577 577
 				case 'CAD':
578 578
 				case 'EUR':
@@ -616,12 +616,12 @@  discard block
 block discarded – undo
616 616
 		 * And fits on your back?
617 617
 		 * It's log, log, log
618 618
 		 */
619
-		public static function log( $message ) {
620
-			if ( empty( self::$log ) ) {
619
+		public static function log($message) {
620
+			if (empty(self::$log)) {
621 621
 				self::$log = new WC_Logger();
622 622
 			}
623 623
 
624
-			self::$log->add( 'woocommerce-gateway-stripe', $message );
624
+			self::$log->add('woocommerce-gateway-stripe', $message);
625 625
 		}
626 626
 	}
627 627
 
Please login to merge, or discard this patch.