Completed
Push — master ( 07cc8d...bbe4a8 )
by Roy
01:59
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +289 added lines, -289 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   = sprintf( __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' );
123
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
124
+		$this->method_description   = sprintf(__('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys');
125 125
 		$this->has_fields           = true;
126 126
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
127 127
 		$this->supports             = array(
@@ -149,43 +149,43 @@  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' );
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 169
 		$this->apple_pay_verify_notice = '';
170 170
 
171
-		if ( $this->stripe_checkout ) {
172
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
171
+		if ($this->stripe_checkout) {
172
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
173 173
 		}
174 174
 
175
-		if ( $this->testmode ) {
176
-			$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' );
177
-			$this->description  = trim( $this->description );
175
+		if ($this->testmode) {
176
+			$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');
177
+			$this->description  = trim($this->description);
178 178
 		}
179 179
 
180
-		WC_Stripe_API::set_secret_key( $this->secret_key );
180
+		WC_Stripe_API::set_secret_key($this->secret_key);
181 181
 
182 182
 		$this->init_apple_pay();
183 183
 
184 184
 		// Hooks.
185
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
186
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
187
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
188
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
185
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
186
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
187
+		add_action('admin_notices', array($this, 'admin_notices'));
188
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
189 189
 	}
190 190
 
191 191
 	/**
@@ -196,33 +196,33 @@  discard block
 block discarded – undo
196 196
 	 * @return string
197 197
 	 */
198 198
 	public function get_icon() {
199
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
200
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
199
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
200
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
201 201
 
202 202
 		$icons = array();
203 203
 
204
-		$icons['visa']       = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
205
-		$icons['mastercard'] = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
206
-		$icons['amex']       = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
204
+		$icons['visa']       = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
205
+		$icons['mastercard'] = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
206
+		$icons['amex']       = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
207 207
 
208 208
 		$base_location = wc_get_base_location();
209 209
 
210
-		if ( 'US' === $base_location['country'] ) {
211
-			$icons['discover'] = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
212
-			$icons['jcb']      = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
213
-			$icons['diners']   = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
210
+		if ('US' === $base_location['country']) {
211
+			$icons['discover'] = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
212
+			$icons['jcb']      = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
213
+			$icons['diners']   = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
214 214
 		}
215 215
 
216
-		if ( $this->bitcoin && $this->stripe_checkout ) {
217
-			$icons['bitcoin'] = '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
216
+		if ($this->bitcoin && $this->stripe_checkout) {
217
+			$icons['bitcoin'] = '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
218 218
 		}
219 219
 
220
-		$icons = apply_filters( 'woocommerce_gateway_icon', $icons, $this->id );
220
+		$icons = apply_filters('woocommerce_gateway_icon', $icons, $this->id);
221 221
 
222 222
 		$icon_html = '';
223 223
 
224 224
 		// Build the icons into string.
225
-		foreach ( $icons as $icon ) {
225
+		foreach ($icons as $icon) {
226 226
 			$icon_html .= $icon;
227 227
 		}
228 228
 
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @return float|int
239 239
 	 */
240
-	public function get_stripe_amount( $total, $currency = '' ) {
241
-		if ( ! $currency ) {
240
+	public function get_stripe_amount($total, $currency = '') {
241
+		if ( ! $currency) {
242 242
 			$currency = get_woocommerce_currency();
243 243
 		}
244
-		switch ( strtoupper( $currency ) ) {
244
+		switch (strtoupper($currency)) {
245 245
 			// Zero decimal currencies.
246 246
 			case 'BIF' :
247 247
 			case 'CLP' :
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
 			case 'XAF' :
259 259
 			case 'XOF' :
260 260
 			case 'XPF' :
261
-				$total = absint( $total );
261
+				$total = absint($total);
262 262
 				break;
263 263
 			default :
264
-				$total = round( $total, 2 ) * 100; // In cents.
264
+				$total = round($total, 2) * 100; // In cents.
265 265
 				break;
266 266
 		}
267 267
 		return $total;
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
 	public function init_apple_pay() {
277 277
 		if (
278 278
 			is_admin() &&
279
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] &&
280
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
281
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section'] &&
279
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] &&
280
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
281
+			isset($_GET['section']) && 'stripe' === $_GET['section'] &&
282 282
 			$this->apple_pay
283 283
 		) {
284 284
 			$this->process_apple_pay_verification();
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
 	 * @version 3.1.0
293 293
 	 * @param string $secret_key
294 294
 	 */
295
-	private function register_apple_pay_domain( $secret_key = '' ) {
296
-		if ( empty( $secret_key ) ) {
297
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
295
+	private function register_apple_pay_domain($secret_key = '') {
296
+		if (empty($secret_key)) {
297
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
298 298
 		}
299 299
 
300 300
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -308,21 +308,21 @@  discard block
 block discarded – undo
308 308
 			'Authorization' => 'Bearer ' . $secret_key,
309 309
 		);
310 310
 
311
-		$response = wp_remote_post( $endpoint, array(
311
+		$response = wp_remote_post($endpoint, array(
312 312
 			'headers' => $headers,
313
-			'body'    => http_build_query( $data ),
314
-		) );
313
+			'body'    => http_build_query($data),
314
+		));
315 315
 
316
-		if ( is_wp_error( $response ) ) {
317
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) );
316
+		if (is_wp_error($response)) {
317
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message()));
318 318
 		}
319 319
 
320
-		if ( 200 !== $response['response']['code'] ) {
321
-			$parsed_response = json_decode( $response['body'] );
320
+		if (200 !== $response['response']['code']) {
321
+			$parsed_response = json_decode($response['body']);
322 322
 
323 323
 			$this->apple_pay_verify_notice = $parsed_response->error->message;
324 324
 
325
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) );
325
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message));
326 326
 		}
327 327
 	}
328 328
 
@@ -333,48 +333,48 @@  discard block
 block discarded – undo
333 333
 	 * @version 3.1.0
334 334
 	 */
335 335
 	public function process_apple_pay_verification() {
336
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
336
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
337 337
 
338 338
 		try {
339
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
339
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
340 340
 			$dir      = '.well-known';
341 341
 			$file     = 'apple-developer-merchantid-domain-association';
342 342
 			$fullpath = $path . '/' . $dir . '/' . $file;
343 343
 
344
-			if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
344
+			if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
345 345
 				return;
346 346
 			}
347 347
 
348
-			if ( ! file_exists( $path . '/' . $dir ) ) {
349
-				if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) {
350
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
348
+			if ( ! file_exists($path . '/' . $dir)) {
349
+				if ( ! @mkdir($path . '/' . $dir, 0755)) {
350
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
351 351
 				}
352 352
 			}
353 353
 
354
-			if ( ! file_exists( $fullpath ) ) {
355
-				if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
356
-					throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
354
+			if ( ! file_exists($fullpath)) {
355
+				if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
356
+					throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
357 357
 				}
358 358
 			}
359 359
 
360 360
 			// At this point then the domain association folder and file should be available.
361 361
 			// Proceed to verify/and or verify again.
362
-			$this->register_apple_pay_domain( $this->secret_key );
362
+			$this->register_apple_pay_domain($this->secret_key);
363 363
 
364 364
 			// No errors to this point, verification success!
365 365
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
366 366
 			$this->apple_pay_domain_set = true;
367 367
 
368
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
368
+			update_option('woocommerce_stripe_settings', $gateway_settings);
369 369
 
370
-			$this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) );
370
+			$this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe'));
371 371
 
372
-		} catch ( Exception $e ) {
372
+		} catch (Exception $e) {
373 373
 			$gateway_settings['apple_pay_domain_set'] = 'no';
374 374
 
375
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
375
+			update_option('woocommerce_stripe_settings', $gateway_settings);
376 376
 
377
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
377
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
378 378
 		}
379 379
 	}
380 380
 
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	 * Check if SSL is enabled and notify the user
383 383
 	 */
384 384
 	public function admin_notices() {
385
-		if ( 'no' === $this->enabled ) {
385
+		if ('no' === $this->enabled) {
386 386
 			return;
387 387
 		}
388 388
 
389
-		if ( $this->apple_pay && ! empty( $this->apple_pay_verify_notice ) ) {
389
+		if ($this->apple_pay && ! empty($this->apple_pay_verify_notice)) {
390 390
 			$allowed_html = array(
391 391
 				'a' => array(
392 392
 					'href' => array(),
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 				),
395 395
 			);
396 396
 
397
-			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>';
397
+			echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>';
398 398
 		}
399 399
 
400 400
 		/**
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
 		 * when setting screen is displayed. So if domain verification is not set,
403 403
 		 * something went wrong so lets notify user.
404 404
 		 */
405
-		if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) {
406
-			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. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
405
+		if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) {
406
+			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. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
407 407
 		}
408 408
 
409 409
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
410
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
411
-			echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ) . '</p></div>';
410
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
411
+			echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security') . '</p></div>';
412 412
 		}
413 413
 	}
414 414
 
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
416 416
 	 * Check if this gateway is enabled
417 417
 	 */
418 418
 	public function is_available() {
419
-		if ( 'yes' === $this->enabled ) {
420
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
419
+		if ('yes' === $this->enabled) {
420
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
421 421
 				return false;
422 422
 			}
423
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
423
+			if ( ! $this->secret_key || ! $this->publishable_key) {
424 424
 				return false;
425 425
 			}
426 426
 			return true;
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	 * Initialise Gateway Settings Form Fields
433 433
 	 */
434 434
 	public function init_form_fields() {
435
-		$this->form_fields = include( 'settings-stripe.php' );
435
+		$this->form_fields = include('settings-stripe.php');
436 436
 	}
437 437
 
438 438
 	/**
@@ -440,55 +440,55 @@  discard block
 block discarded – undo
440 440
 	 */
441 441
 	public function payment_fields() {
442 442
 		$user                 = wp_get_current_user();
443
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
443
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
444 444
 		$total                = WC()->cart->total;
445 445
 
446 446
 		// If paying from order, we need to get total from order not cart.
447
-		if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) {
448
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
447
+		if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) {
448
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
449 449
 			$total = $order->get_total();
450 450
 		}
451 451
 
452
-		if ( $user->ID ) {
453
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
452
+		if ($user->ID) {
453
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
454 454
 			$user_email = $user_email ? $user_email : $user->user_email;
455 455
 		} else {
456 456
 			$user_email = '';
457 457
 		}
458 458
 
459
-		if ( is_add_payment_method_page() ) {
460
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
461
-			$total        = '';
459
+		if (is_add_payment_method_page()) {
460
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
461
+			$total = '';
462 462
 		} else {
463 463
 			$pay_button_text = '';
464 464
 		}
465 465
 
466 466
 		echo '<div
467 467
 			id="stripe-payment-data"
468
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
468
+			data-panel-label="' . esc_attr($pay_button_text) . '"
469 469
 			data-description=""
470
-			data-email="' . esc_attr( $user_email ) . '"
471
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
472
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
473
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
474
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
475
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
476
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
477
-			data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">';
470
+			data-email="' . esc_attr($user_email) . '"
471
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
472
+			data-name="' . esc_attr($this->statement_descriptor) . '"
473
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
474
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
475
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
476
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
477
+			data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">';
478 478
 
479
-		if ( $this->description ) {
480
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
479
+		if ($this->description) {
480
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
481 481
 		}
482 482
 
483
-		if ( $display_tokenization ) {
483
+		if ($display_tokenization) {
484 484
 			$this->tokenization_script();
485 485
 			$this->saved_payment_methods();
486 486
 		}
487 487
 
488
-		if ( ! $this->stripe_checkout ) {
488
+		if ( ! $this->stripe_checkout) {
489 489
 			$this->form();
490 490
 
491
-			if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) ) {
491
+			if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization)) {
492 492
 				$this->save_payment_method_checkbox();
493 493
 			}
494 494
 		}
@@ -504,20 +504,20 @@  discard block
 block discarded – undo
504 504
 	 * @return array
505 505
 	 */
506 506
 	public function get_localized_messages() {
507
-		return apply_filters( 'wc_stripe_localized_messages', array(
508
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
509
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
510
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
511
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
512
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
513
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
514
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
515
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
516
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
517
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
518
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
519
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
520
-		) );
507
+		return apply_filters('wc_stripe_localized_messages', array(
508
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
509
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
510
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
511
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
512
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
513
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
514
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
515
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
516
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
517
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
518
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
519
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
520
+		));
521 521
 	}
522 522
 
523 523
 	/**
@@ -527,28 +527,28 @@  discard block
 block discarded – undo
527 527
 	 * @version 3.1.0
528 528
 	 */
529 529
 	public function admin_scripts() {
530
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
530
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
531 531
 			return;
532 532
 		}
533 533
 
534
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
534
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
535 535
 
536
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
536
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
537 537
 
538 538
 		$stripe_admin_params = array(
539 539
 			'localized_messages' => array(
540
-				'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ),
541
-				'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ),
542
-				're_verify_button_text'  => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ),
543
-				'missing_secret_key'     => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ),
540
+				'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'),
541
+				'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'),
542
+				're_verify_button_text'  => __('Re-verify Domain', 'woocommerce-gateway-stripe'),
543
+				'missing_secret_key'     => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'),
544 544
 			),
545
-			'ajaxurl'            => admin_url( 'admin-ajax.php' ),
545
+			'ajaxurl'            => admin_url('admin-ajax.php'),
546 546
 			'nonce'              => array(
547
-				'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ),
547
+				'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'),
548 548
 			),
549 549
 		);
550 550
 
551
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) );
551
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params));
552 552
 	}
553 553
 
554 554
 	/**
@@ -559,49 +559,49 @@  discard block
 block discarded – undo
559 559
 	 * @access public
560 560
 	 */
561 561
 	public function payment_scripts() {
562
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
562
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
563 563
 			return;
564 564
 		}
565 565
 
566
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
566
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
567 567
 
568
-		if ( $this->stripe_checkout ) {
569
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true );
570
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe_checkout' ), WC_STRIPE_VERSION, true );
568
+		if ($this->stripe_checkout) {
569
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true);
570
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe_checkout'), WC_STRIPE_VERSION, true);
571 571
 		} else {
572
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '2.0', true );
573
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
572
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '2.0', true);
573
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
574 574
 		}
575 575
 
576 576
 		$stripe_params = array(
577 577
 			'key'                  => $this->publishable_key,
578
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
579
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
578
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
579
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
580 580
 		);
581 581
 
582 582
 		// If we're on the pay page we need to pass stripe.js the address of the order.
583
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
584
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
585
-			$order    = wc_get_order( $order_id );
583
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
584
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
585
+			$order    = wc_get_order($order_id);
586 586
 
587
-			$stripe_params['billing_first_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
588
-			$stripe_params['billing_last_name']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
589
-			$stripe_params['billing_address_1']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1();
590
-			$stripe_params['billing_address_2']  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2();
591
-			$stripe_params['billing_state']      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_state : $order->get_billing_state();
592
-			$stripe_params['billing_city']       = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_city : $order->get_billing_city();
593
-			$stripe_params['billing_postcode']   = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode();
594
-			$stripe_params['billing_country']    = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_country : $order->get_billing_country();
587
+			$stripe_params['billing_first_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
588
+			$stripe_params['billing_last_name']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
589
+			$stripe_params['billing_address_1']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1();
590
+			$stripe_params['billing_address_2']  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2();
591
+			$stripe_params['billing_state']      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_state : $order->get_billing_state();
592
+			$stripe_params['billing_city']       = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_city : $order->get_billing_city();
593
+			$stripe_params['billing_postcode']   = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_postcode : $order->get_billing_postcode();
594
+			$stripe_params['billing_country']    = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_country : $order->get_billing_country();
595 595
 		}
596 596
 
597
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
598
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
599
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
597
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
598
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
599
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
600 600
 
601 601
 		// merge localized messages to be use in JS
602
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
602
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
603 603
 
604
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
604
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
605 605
 	}
606 606
 
607 607
 	/**
@@ -610,35 +610,35 @@  discard block
 block discarded – undo
610 610
 	 * @param  object $source
611 611
 	 * @return array()
612 612
 	 */
613
-	protected function generate_payment_request( $order, $source ) {
613
+	protected function generate_payment_request($order, $source) {
614 614
 		$post_data                = array();
615
-		$post_data['currency']    = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() );
616
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
617
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
615
+		$post_data['currency']    = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency());
616
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
617
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
618 618
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
619 619
 
620
-		$billing_email      = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email();
621
-		$billing_first_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name();
622
-		$billing_last_name  = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name();
620
+		$billing_email      = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email();
621
+		$billing_first_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name();
622
+		$billing_last_name  = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name();
623 623
 
624
-		if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
624
+		if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
625 625
 			$post_data['receipt_email'] = $billing_email;
626 626
 		}
627 627
 
628
-		$post_data['expand[]']    = 'balance_transaction';
628
+		$post_data['expand[]'] = 'balance_transaction';
629 629
 
630 630
 		$metadata = array(
631
-			__( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
632
-			__( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
631
+			__('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name),
632
+			__('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email),
633 633
 		);
634 634
 
635
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
635
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
636 636
 
637
-		if ( $source->customer ) {
637
+		if ($source->customer) {
638 638
 			$post_data['customer'] = $source->customer;
639 639
 		}
640 640
 
641
-		if ( $source->source ) {
641
+		if ($source->source) {
642 642
 			$post_data['source'] = $source->source;
643 643
 		}
644 644
 
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 		 * @param WC_Order $order
651 651
 		 * @param object $source
652 652
 		 */
653
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
653
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
654 654
 	}
655 655
 
656 656
 	/**
@@ -662,38 +662,38 @@  discard block
 block discarded – undo
662 662
 	 * @throws Exception When card was not added or for and invalid card.
663 663
 	 * @return object
664 664
 	 */
665
-	protected function get_source( $user_id, $force_customer = false ) {
666
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
667
-		$force_customer  = apply_filters( 'wc_stripe_force_customer_creation', $force_customer, $stripe_customer );
665
+	protected function get_source($user_id, $force_customer = false) {
666
+		$stripe_customer = new WC_Stripe_Customer($user_id);
667
+		$force_customer  = apply_filters('wc_stripe_force_customer_creation', $force_customer, $stripe_customer);
668 668
 		$stripe_source   = false;
669 669
 		$token_id        = false;
670 670
 
671 671
 		// New CC info was entered and we have a new token to process
672
-		if ( isset( $_POST['stripe_token'] ) ) {
673
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
674
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
672
+		if (isset($_POST['stripe_token'])) {
673
+			$stripe_token     = wc_clean($_POST['stripe_token']);
674
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
675 675
 
676 676
 			// This is true if the user wants to store the card to their account.
677
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
678
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
677
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
678
+				$stripe_source = $stripe_customer->add_card($stripe_token);
679 679
 
680
-				if ( is_wp_error( $stripe_source ) ) {
681
-					throw new Exception( $stripe_source->get_error_message() );
680
+				if (is_wp_error($stripe_source)) {
681
+					throw new Exception($stripe_source->get_error_message());
682 682
 				}
683 683
 			} else {
684 684
 				// Not saving token, so don't define customer either.
685 685
 				$stripe_source   = $stripe_token;
686 686
 				$stripe_customer = false;
687 687
 			}
688
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
688
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
689 689
 			// Use an existing token, and then process the payment
690 690
 
691
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
692
-			$token    = WC_Payment_Tokens::get( $token_id );
691
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
692
+			$token    = WC_Payment_Tokens::get($token_id);
693 693
 
694
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
695
-				WC()->session->set( 'refresh_totals', true );
696
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
694
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
695
+				WC()->session->set('refresh_totals', true);
696
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
697 697
 			}
698 698
 
699 699
 			$stripe_source = $token->get_token();
@@ -717,19 +717,19 @@  discard block
 block discarded – undo
717 717
 	 * @param object $order
718 718
 	 * @return object
719 719
 	 */
720
-	protected function get_order_source( $order = null ) {
720
+	protected function get_order_source($order = null) {
721 721
 		$stripe_customer = new WC_Stripe_Customer();
722 722
 		$stripe_source   = false;
723 723
 		$token_id        = false;
724 724
 
725
-		if ( $order ) {
726
-			$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
725
+		if ($order) {
726
+			$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
727 727
 
728
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) {
729
-				$stripe_customer->set_id( $meta_value );
728
+			if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) {
729
+				$stripe_customer->set_id($meta_value);
730 730
 			}
731 731
 
732
-			if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) {
732
+			if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) {
733 733
 				$stripe_source = $meta_value;
734 734
 			}
735 735
 		}
@@ -752,60 +752,60 @@  discard block
 block discarded – undo
752 752
 	 *
753 753
 	 * @return array|void
754 754
 	 */
755
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
755
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
756 756
 		try {
757
-			$order  = wc_get_order( $order_id );
758
-			$source = $this->get_source( get_current_user_id(), $force_customer );
757
+			$order  = wc_get_order($order_id);
758
+			$source = $this->get_source(get_current_user_id(), $force_customer);
759 759
 
760
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
761
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
762
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
763
-				throw new Exception( $error_msg );
760
+			if (empty($source->source) && empty($source->customer)) {
761
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
762
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
763
+				throw new Exception($error_msg);
764 764
 			}
765 765
 
766 766
 			// Store source to order meta.
767
-			$this->save_source( $order, $source );
767
+			$this->save_source($order, $source);
768 768
 
769 769
 			// Result from Stripe API request.
770 770
 			$response = null;
771 771
 
772 772
 			// Handle payment.
773
-			if ( $order->get_total() > 0 ) {
773
+			if ($order->get_total() > 0) {
774 774
 
775
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
776
-					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 ) ) );
775
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
776
+					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)));
777 777
 				}
778 778
 
779
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
779
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
780 780
 
781 781
 				// Make the request.
782
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
782
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
783 783
 
784
-				if ( is_wp_error( $response ) ) {
784
+				if (is_wp_error($response)) {
785 785
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
786
-					if ( 'customer' === $response->get_error_code() && $retry ) {
787
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
788
-						return $this->process_payment( $order_id, false, $force_customer );
786
+					if ('customer' === $response->get_error_code() && $retry) {
787
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
788
+						return $this->process_payment($order_id, false, $force_customer);
789 789
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
790
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
791
-						$token = WC_Payment_Tokens::get( $source->token_id );
790
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
791
+						$token = WC_Payment_Tokens::get($source->token_id);
792 792
 						$token->delete();
793
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
794
-						$order->add_order_note( $message );
795
-						throw new Exception( $message );
793
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
794
+						$order->add_order_note($message);
795
+						throw new Exception($message);
796 796
 					}
797 797
 
798 798
 					$localized_messages = $this->get_localized_messages();
799 799
 
800
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
800
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
801 801
 
802
-					$order->add_order_note( $message );
802
+					$order->add_order_note($message);
803 803
 
804
-					throw new Exception( $message );
804
+					throw new Exception($message);
805 805
 				}
806 806
 
807 807
 				// Process valid response.
808
-				$this->process_response( $response, $order );
808
+				$this->process_response($response, $order);
809 809
 			} else {
810 810
 				$order->payment_complete();
811 811
 			}
@@ -813,23 +813,23 @@  discard block
 block discarded – undo
813 813
 			// Remove cart.
814 814
 			WC()->cart->empty_cart();
815 815
 
816
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
816
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
817 817
 
818 818
 			// Return thank you page redirect.
819 819
 			return array(
820 820
 				'result'   => 'success',
821
-				'redirect' => $this->get_return_url( $order ),
821
+				'redirect' => $this->get_return_url($order),
822 822
 			);
823 823
 
824
-		} catch ( Exception $e ) {
825
-			wc_add_notice( $e->getMessage(), 'error' );
826
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
824
+		} catch (Exception $e) {
825
+			wc_add_notice($e->getMessage(), 'error');
826
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
827 827
 
828
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
829
-				$this->send_failed_order_email( $order_id );
828
+			if ($order->has_status(array('pending', 'failed'))) {
829
+				$this->send_failed_order_email($order_id);
830 830
 			}
831 831
 
832
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
832
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
833 833
 
834 834
 			return array(
835 835
 				'result'   => 'fail',
@@ -844,18 +844,18 @@  discard block
 block discarded – undo
844 844
 	 * @param WC_Order $order For to which the source applies.
845 845
 	 * @param stdClass $source Source information.
846 846
 	 */
847
-	protected function save_source( $order, $source ) {
848
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
847
+	protected function save_source($order, $source) {
848
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
849 849
 
850 850
 		// Store source in the order.
851
-		if ( $source->customer ) {
852
-			version_compare( WC_VERSION, '3.0.0', '<' ) ? update_post_meta( $order_id, '_stripe_customer_id', $source->customer ) : $order->update_meta_data( '_stripe_customer_id', $source->customer );
851
+		if ($source->customer) {
852
+			version_compare(WC_VERSION, '3.0.0', '<') ? update_post_meta($order_id, '_stripe_customer_id', $source->customer) : $order->update_meta_data('_stripe_customer_id', $source->customer);
853 853
 		}
854
-		if ( $source->source ) {
855
-			version_compare( WC_VERSION, '3.0.0', '<' ) ? update_post_meta( $order_id, '_stripe_card_id', $source->source ) : $order->update_meta_data( '_stripe_card_id', $source->source );
854
+		if ($source->source) {
855
+			version_compare(WC_VERSION, '3.0.0', '<') ? update_post_meta($order_id, '_stripe_card_id', $source->source) : $order->update_meta_data('_stripe_card_id', $source->source);
856 856
 		}
857 857
 
858
-		if ( is_callable( array( $order, 'save' ) ) ) {
858
+		if (is_callable(array($order, 'save'))) {
859 859
 			$order->save();
860 860
 		}
861 861
 	}
@@ -863,44 +863,44 @@  discard block
 block discarded – undo
863 863
 	/**
864 864
 	 * Store extra meta data for an order from a Stripe Response.
865 865
 	 */
866
-	public function process_response( $response, $order ) {
867
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
866
+	public function process_response($response, $order) {
867
+		$this->log('Processing response: ' . print_r($response, true));
868 868
 
869
-		$order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
869
+		$order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id();
870 870
 
871 871
 		// Store charge data
872
-		update_post_meta( $order_id, '_stripe_charge_id', $response->id );
873
-		update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
872
+		update_post_meta($order_id, '_stripe_charge_id', $response->id);
873
+		update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
874 874
 
875 875
 		// Store other data such as fees
876
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
876
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
877 877
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
878 878
 			// values are in the local currency of the Stripe account, not from WC.
879
-			$fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe::format_number( $response->balance_transaction, 'fee' ) : 0;
880
-			$net = ! empty( $response->balance_transaction->net ) ? WC_Stripe::format_number( $response->balance_transaction, 'net' ) : 0;
881
-			update_post_meta( $order_id, 'Stripe Fee', $fee );
882
-			update_post_meta( $order_id, 'Net Revenue From Stripe', $net );
879
+			$fee = ! empty($response->balance_transaction->fee) ? WC_Stripe::format_number($response->balance_transaction, 'fee') : 0;
880
+			$net = ! empty($response->balance_transaction->net) ? WC_Stripe::format_number($response->balance_transaction, 'net') : 0;
881
+			update_post_meta($order_id, 'Stripe Fee', $fee);
882
+			update_post_meta($order_id, 'Net Revenue From Stripe', $net);
883 883
 		}
884 884
 
885
-		if ( $response->captured ) {
886
-			$order->payment_complete( $response->id );
885
+		if ($response->captured) {
886
+			$order->payment_complete($response->id);
887 887
 
888
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
889
-			$order->add_order_note( $message );
890
-			$this->log( 'Success: ' . $message );
888
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
889
+			$order->add_order_note($message);
890
+			$this->log('Success: ' . $message);
891 891
 
892 892
 		} else {
893
-			update_post_meta( $order_id, '_transaction_id', $response->id, true );
893
+			update_post_meta($order_id, '_transaction_id', $response->id, true);
894 894
 
895
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
896
-				version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id );
895
+			if ($order->has_status(array('pending', 'failed'))) {
896
+				version_compare(WC_VERSION, '3.0.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id);
897 897
 			}
898 898
 
899
-			$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 ) );
900
-			$this->log( "Successful auth: $response->id" );
899
+			$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));
900
+			$this->log("Successful auth: $response->id");
901 901
 		}
902 902
 
903
-		do_action( 'wc_gateway_stripe_process_response', $response, $order );
903
+		do_action('wc_gateway_stripe_process_response', $response, $order);
904 904
 
905 905
 		return $response;
906 906
 	}
@@ -911,32 +911,32 @@  discard block
 block discarded – undo
911 911
 	 * @since 3.0.0
912 912
 	 */
913 913
 	public function add_payment_method() {
914
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
915
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
914
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
915
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
916 916
 			return;
917 917
 		}
918 918
 
919
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
920
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
919
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
920
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
921 921
 
922
-		if ( is_wp_error( $card ) ) {
922
+		if (is_wp_error($card)) {
923 923
 			$localized_messages = $this->get_localized_messages();
924
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
924
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
925 925
 
926 926
 			// loop through the errors to find matching localized message
927
-			foreach ( $card->errors as $error => $msg ) {
928
-				if ( isset( $localized_messages[ $error ] ) ) {
929
-					$error_msg = $localized_messages[ $error ];
927
+			foreach ($card->errors as $error => $msg) {
928
+				if (isset($localized_messages[$error])) {
929
+					$error_msg = $localized_messages[$error];
930 930
 				}
931 931
 			}
932 932
 
933
-			wc_add_notice( $error_msg, 'error' );
933
+			wc_add_notice($error_msg, 'error');
934 934
 			return;
935 935
 		}
936 936
 
937 937
 		return array(
938 938
 			'result'   => 'success',
939
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
939
+			'redirect' => wc_get_endpoint_url('payment-methods'),
940 940
 		);
941 941
 	}
942 942
 
@@ -946,36 +946,36 @@  discard block
 block discarded – undo
946 946
 	 * @param  float $amount
947 947
 	 * @return bool
948 948
 	 */
949
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
950
-		$order = wc_get_order( $order_id );
949
+	public function process_refund($order_id, $amount = null, $reason = '') {
950
+		$order = wc_get_order($order_id);
951 951
 
952
-		if ( ! $order || ! $order->get_transaction_id() ) {
952
+		if ( ! $order || ! $order->get_transaction_id()) {
953 953
 			return false;
954 954
 		}
955 955
 
956 956
 		$body = array();
957 957
 
958
-		if ( ! is_null( $amount ) ) {
959
-			$body['amount']	= $this->get_stripe_amount( $amount );
958
+		if ( ! is_null($amount)) {
959
+			$body['amount'] = $this->get_stripe_amount($amount);
960 960
 		}
961 961
 
962
-		if ( $reason ) {
962
+		if ($reason) {
963 963
 			$body['metadata'] = array(
964 964
 				'reason'	=> $reason,
965 965
 			);
966 966
 		}
967 967
 
968
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
968
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
969 969
 
970
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
970
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
971 971
 
972
-		if ( is_wp_error( $response ) ) {
973
-			$this->log( 'Error: ' . $response->get_error_message() );
972
+		if (is_wp_error($response)) {
973
+			$this->log('Error: ' . $response->get_error_message());
974 974
 			return $response;
975
-		} elseif ( ! empty( $response->id ) ) {
976
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
977
-			$order->add_order_note( $refund_message );
978
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
975
+		} elseif ( ! empty($response->id)) {
976
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
977
+			$order->add_order_note($refund_message);
978
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
979 979
 			return true;
980 980
 		}
981 981
 	}
@@ -988,10 +988,10 @@  discard block
 block discarded – undo
988 988
 	 * @param int $order_id
989 989
 	 * @return null
990 990
 	 */
991
-	public function send_failed_order_email( $order_id ) {
991
+	public function send_failed_order_email($order_id) {
992 992
 		$emails = WC()->mailer()->get_emails();
993
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
994
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
993
+		if ( ! empty($emails) && ! empty($order_id)) {
994
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
995 995
 		}
996 996
 	}
997 997
 
@@ -1003,9 +1003,9 @@  discard block
 block discarded – undo
1003 1003
 	 *
1004 1004
 	 * @param string $message
1005 1005
 	 */
1006
-	public function log( $message ) {
1007
-		if ( $this->logging ) {
1008
-			WC_Stripe::log( $message );
1006
+	public function log($message) {
1007
+		if ($this->logging) {
1008
+			WC_Stripe::log($message);
1009 1009
 		}
1010 1010
 	}
1011 1011
 }
Please login to merge, or discard this patch.