Completed
Push — master ( e50beb...9d6b36 )
by Roy
02:28
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +270 added lines, -270 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,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' );
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
-		}
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 );
178
-		}
179
-
180
-		WC_Stripe_API::set_secret_key( $this->secret_key );
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
+		}
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);
178
+		}
179
+
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
 	/**
@@ -195,24 +195,24 @@  discard block
 block discarded – undo
195 195
 	 * @return string
196 196
 	 */
197 197
 	public function get_icon() {
198
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
199
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
198
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
199
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
200 200
 
201
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
202
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
203
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
201
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
202
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
203
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
204 204
 
205
-		if ( 'USD' === get_woocommerce_currency() ) {
206
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
207
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
208
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
205
+		if ('USD' === get_woocommerce_currency()) {
206
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
207
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
208
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
209 209
 		}
210 210
 
211
-		if ( $this->bitcoin && $this->stripe_checkout ) {
212
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
211
+		if ($this->bitcoin && $this->stripe_checkout) {
212
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
213 213
 		}
214 214
 
215
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
215
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
216 216
 	}
217 217
 
218 218
 	/**
@@ -223,11 +223,11 @@  discard block
 block discarded – undo
223 223
 	 *
224 224
 	 * @return float|int
225 225
 	 */
226
-	public function get_stripe_amount( $total, $currency = '' ) {
227
-		if ( ! $currency ) {
226
+	public function get_stripe_amount($total, $currency = '') {
227
+		if ( ! $currency) {
228 228
 			$currency = get_woocommerce_currency();
229 229
 		}
230
-		switch ( strtoupper( $currency ) ) {
230
+		switch (strtoupper($currency)) {
231 231
 			// Zero decimal currencies.
232 232
 			case 'BIF' :
233 233
 			case 'CLP' :
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
 			case 'XAF' :
245 245
 			case 'XOF' :
246 246
 			case 'XPF' :
247
-				$total = absint( $total );
247
+				$total = absint($total);
248 248
 				break;
249 249
 			default :
250
-				$total = round( $total, 2 ) * 100; // In cents.
250
+				$total = round($total, 2) * 100; // In cents.
251 251
 				break;
252 252
 		}
253 253
 		return $total;
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 	public function init_apple_pay() {
263 263
 		if ( 
264 264
 			is_admin() && 
265
-			isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && 
266
-			isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] &&
267
-			isset( $_GET['section'] ) && 'stripe' === $_GET['section']
265
+			isset($_GET['page']) && 'wc-settings' === $_GET['page'] && 
266
+			isset($_GET['tab']) && 'checkout' === $_GET['tab'] &&
267
+			isset($_GET['section']) && 'stripe' === $_GET['section']
268 268
 		) {
269 269
 			$this->process_apple_pay_verification();
270 270
 		}
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
 	 * @version 3.1.0
278 278
 	 * @param string $secret_key
279 279
 	 */
280
-	private function _register_apple_pay_domain( $secret_key = '' ) {
281
-		if ( empty( $secret_key ) ) {
282
-			throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) );
280
+	private function _register_apple_pay_domain($secret_key = '') {
281
+		if (empty($secret_key)) {
282
+			throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe'));
283 283
 		}
284 284
 
285 285
 		$endpoint = 'https://api.stripe.com/v1/apple_pay/domains';
@@ -293,13 +293,13 @@  discard block
 block discarded – undo
293 293
 			'Authorization' => 'Bearer ' . $secret_key,
294 294
 		);
295 295
 
296
-		$response = wp_remote_post( $endpoint, array(
296
+		$response = wp_remote_post($endpoint, array(
297 297
 			'headers' => $headers,
298
-			'body'    => http_build_query( $data ),
299
-		) );
298
+			'body'    => http_build_query($data),
299
+		));
300 300
 
301
-		if ( 200 !== $response['response']['code'] ) {
302
-			throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response['response']['message'] ) );
301
+		if (200 !== $response['response']['code']) {
302
+			throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response['response']['message']));
303 303
 		}
304 304
 	}
305 305
 
@@ -310,48 +310,48 @@  discard block
 block discarded – undo
310 310
 	 * @version 3.1.0
311 311
 	 */
312 312
 	public function process_apple_pay_verification() {
313
-		$gateway_settings = get_option( 'woocommerce_stripe_settings', '' );
313
+		$gateway_settings = get_option('woocommerce_stripe_settings', '');
314 314
 
315 315
 		try {
316
-			$path     = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) );
316
+			$path     = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']));
317 317
 			$dir      = '.well-known';
318 318
 			$file     = 'apple-developer-merchantid-domain-association';
319 319
 			$fullpath = $path . '/' . $dir . '/' . $file;
320 320
 
321
-			if ( 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) {
321
+			if ('yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) {
322 322
 				return;
323 323
 			}
324 324
 
325
-			if ( ! file_exists( $path . '/' . $dir ) || ! file_exists( $fullpath ) ) {
326
-				if ( ! mkdir( $path . '/' . $dir, 0755 ) ) {
327
-					throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) );
325
+			if ( ! file_exists($path . '/' . $dir) || ! file_exists($fullpath)) {
326
+				if ( ! mkdir($path . '/' . $dir, 0755)) {
327
+					throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe'));
328 328
 				}
329 329
 
330
-				if ( ! file_exists( $path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association' ) ) {
331
-					if ( ! copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) {
332
-						throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) );
330
+				if ( ! file_exists($path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association')) {
331
+					if ( ! copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) {
332
+						throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe'));
333 333
 					}
334 334
 				}
335 335
 			}
336 336
 
337 337
 			// At this point then the domain association folder and file should be available.
338 338
 			// Proceed to verify/and or verify again.
339
-			$this->_register_apple_pay_domain( $this->secret_key );
339
+			$this->_register_apple_pay_domain($this->secret_key);
340 340
 
341 341
 			// No errors to this point, verification success!
342 342
 			$gateway_settings['apple_pay_domain_set'] = 'yes';
343 343
 			$this->apple_pay_domain_set = true;
344 344
 
345
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
345
+			update_option('woocommerce_stripe_settings', $gateway_settings);
346 346
 
347
-			$this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) );
347
+			$this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe'));
348 348
 
349
-		} catch ( Exception $e ) {
349
+		} catch (Exception $e) {
350 350
 			$gateway_settings['apple_pay_domain_set'] = 'no';
351 351
 
352
-			update_option( 'woocommerce_stripe_settings', $gateway_settings );
352
+			update_option('woocommerce_stripe_settings', $gateway_settings);
353 353
 
354
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
354
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
355 355
 		}
356 356
 	}
357 357
 
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 * Check if SSL is enabled and notify the user
360 360
 	 */
361 361
 	public function admin_notices() {
362
-		if ( 'no' === $this->enabled ) {
362
+		if ('no' === $this->enabled) {
363 363
 			return;
364 364
 		}
365 365
 
@@ -368,13 +368,13 @@  discard block
 block discarded – undo
368 368
 		 * when setting screen is displayed. So if domain verification is not set,
369 369
 		 * something went wrong so lets notify user.
370 370
 		 */
371
-		if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) {
372
-			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( 'page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>';
371
+		if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) {
372
+			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('page=wc-status&tab=logs') . '">', '</a>') . '</p></div>';
373 373
 		}
374 374
 
375 375
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
376
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
377
-			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>';
376
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
377
+			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>';
378 378
 		}
379 379
 	}
380 380
 
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	 * Check if this gateway is enabled
383 383
 	 */
384 384
 	public function is_available() {
385
-		if ( 'yes' === $this->enabled ) {
386
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
385
+		if ('yes' === $this->enabled) {
386
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
387 387
 				return false;
388 388
 			}
389
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
389
+			if ( ! $this->secret_key || ! $this->publishable_key) {
390 390
 				return false;
391 391
 			}
392 392
 			return true;
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	 * Initialise Gateway Settings Form Fields
399 399
 	 */
400 400
 	public function init_form_fields() {
401
-		$this->form_fields = include( 'settings-stripe.php' );
401
+		$this->form_fields = include('settings-stripe.php');
402 402
 	}
403 403
 
404 404
 	/**
@@ -406,54 +406,54 @@  discard block
 block discarded – undo
406 406
 	 */
407 407
 	public function payment_fields() {
408 408
 		$user                 = wp_get_current_user();
409
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
409
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
410 410
 		$total                = WC()->cart->total;
411 411
 
412 412
 		// If paying from order, we need to get total from order not cart.
413
-		if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) {
414
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
413
+		if (isset($_GET['pay_for_order']) && isset($_GET['key'])) {
414
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
415 415
 			$total = $order->get_total();
416 416
 		}
417 417
 
418
-		if ( $user->ID ) {
419
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
418
+		if ($user->ID) {
419
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
420 420
 			$user_email = $user_email ? $user_email : $user->user_email;
421 421
 		} else {
422 422
 			$user_email = '';
423 423
 		}
424 424
 
425
-		if ( is_add_payment_method_page() ) {
426
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
425
+		if (is_add_payment_method_page()) {
426
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
427 427
 		} else {
428 428
 			$pay_button_text = '';
429 429
 		}
430 430
 
431 431
 		echo '<div
432 432
 			id="stripe-payment-data"
433
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
433
+			data-panel-label="' . esc_attr($pay_button_text) . '"
434 434
 			data-description=""
435
-			data-email="' . esc_attr( $user_email ) . '"
436
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
437
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
438
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
439
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
440
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
441
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
442
-			data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">';
435
+			data-email="' . esc_attr($user_email) . '"
436
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
437
+			data-name="' . esc_attr($this->statement_descriptor) . '"
438
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
439
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
440
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
441
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
442
+			data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">';
443 443
 
444
-		if ( $this->description ) {
445
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
444
+		if ($this->description) {
445
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
446 446
 		}
447 447
 
448
-		if ( $display_tokenization ) {
448
+		if ($display_tokenization) {
449 449
 			$this->tokenization_script();
450 450
 			$this->saved_payment_methods();
451 451
 		}
452 452
 
453
-		if ( ! $this->stripe_checkout ) {
453
+		if ( ! $this->stripe_checkout) {
454 454
 			$this->form();
455 455
 
456
-			if ( $display_tokenization ) {
456
+			if ($display_tokenization) {
457 457
 				$this->save_payment_method_checkbox();
458 458
 			}
459 459
 		}
@@ -469,20 +469,20 @@  discard block
 block discarded – undo
469 469
 	 * @return array
470 470
 	 */
471 471
 	public function get_localized_messages() {
472
-		return apply_filters( 'wc_stripe_localized_messages', array(
473
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
474
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
475
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
476
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
477
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
478
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
479
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
480
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
481
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
482
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
483
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
484
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
485
-		) );
472
+		return apply_filters('wc_stripe_localized_messages', array(
473
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
474
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
475
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
476
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
477
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
478
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
479
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
480
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
481
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
482
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
483
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
484
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
485
+		));
486 486
 	}
487 487
 
488 488
 	/**
@@ -492,28 +492,28 @@  discard block
 block discarded – undo
492 492
 	 * @version 3.1.0
493 493
 	 */
494 494
 	public function admin_scripts() {
495
-		if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
495
+		if ('woocommerce_page_wc-settings' !== get_current_screen()->id) {
496 496
 			return;
497 497
 		}
498 498
 
499
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
499
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
500 500
 
501
-		wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true );
501
+		wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true);
502 502
 
503 503
 		$stripe_admin_params = array(
504 504
 			'localized_messages' => array(
505
-				'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ),
506
-				'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ),
507
-				're_verify_button_text'  => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ),
508
-				'missing_secret_key'     => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ),
505
+				'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'),
506
+				'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'),
507
+				're_verify_button_text'  => __('Re-verify Domain', 'woocommerce-gateway-stripe'),
508
+				'missing_secret_key'     => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'),
509 509
 			),
510
-			'ajaxurl'            => admin_url( 'admin-ajax.php' ),
510
+			'ajaxurl'            => admin_url('admin-ajax.php'),
511 511
 			'nonce'              => array( 
512
-				'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ),
512
+				'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'),
513 513
 			),
514 514
 		);
515 515
 
516
-		wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) );
516
+		wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params));
517 517
 	}
518 518
 
519 519
 	/**
@@ -524,30 +524,30 @@  discard block
 block discarded – undo
524 524
 	 * @access public
525 525
 	 */
526 526
 	public function payment_scripts() {
527
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
527
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
528 528
 			return;
529 529
 		}
530 530
 
531
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
531
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
532 532
 
533
-		if ( $this->stripe_checkout ) {
534
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
535
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
533
+		if ($this->stripe_checkout) {
534
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
535
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
536 536
 		} else {
537
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
538
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
537
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
538
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
539 539
 		}
540 540
 
541 541
 		$stripe_params = array(
542 542
 			'key'                  => $this->publishable_key,
543
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
544
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
543
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
544
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
545 545
 		);
546 546
 
547 547
 		// If we're on the pay page we need to pass stripe.js the address of the order.
548
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
549
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
550
-			$order    = wc_get_order( $order_id );
548
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
549
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
550
+			$order    = wc_get_order($order_id);
551 551
 
552 552
 			$stripe_params['billing_first_name'] = $order->billing_first_name;
553 553
 			$stripe_params['billing_last_name']  = $order->billing_last_name;
@@ -559,14 +559,14 @@  discard block
 block discarded – undo
559 559
 			$stripe_params['billing_country']    = $order->billing_country;
560 560
 		}
561 561
 
562
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
563
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
564
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
562
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
563
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
564
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
565 565
 
566 566
 		// merge localized messages to be use in JS
567
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
567
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
568 568
 
569
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
569
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
570 570
 	}
571 571
 
572 572
 	/**
@@ -575,31 +575,31 @@  discard block
 block discarded – undo
575 575
 	 * @param  object $source
576 576
 	 * @return array()
577 577
 	 */
578
-	protected function generate_payment_request( $order, $source ) {
578
+	protected function generate_payment_request($order, $source) {
579 579
 		$post_data                = array();
580
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
581
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
582
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
580
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
581
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
582
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
583 583
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
584 584
 
585
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
585
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
586 586
 			$post_data['receipt_email'] = $order->billing_email;
587 587
 		}
588 588
 
589
-		$post_data['expand[]']    = 'balance_transaction';
589
+		$post_data['expand[]'] = 'balance_transaction';
590 590
 
591 591
 		$metadata = array(
592
-			__( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $order->billing_first_name ) . ' ' . sanitize_text_field( $order->billing_last_name ),
593
-			__( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $order->billing_email ),
592
+			__('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($order->billing_first_name) . ' ' . sanitize_text_field($order->billing_last_name),
593
+			__('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($order->billing_email),
594 594
 		);
595 595
 
596
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
596
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
597 597
 
598
-		if ( $source->customer ) {
598
+		if ($source->customer) {
599 599
 			$post_data['customer'] = $source->customer;
600 600
 		}
601 601
 
602
-		if ( $source->source ) {
602
+		if ($source->source) {
603 603
 			$post_data['source'] = $source->source;
604 604
 		}
605 605
 
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 		 * @param WC_Order $order
612 612
 		 * @param object $source
613 613
 		 */
614
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
614
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
615 615
 	}
616 616
 
617 617
 	/**
@@ -623,37 +623,37 @@  discard block
 block discarded – undo
623 623
 	 * @throws Exception When card was not added or for and invalid card.
624 624
 	 * @return object
625 625
 	 */
626
-	protected function get_source( $user_id, $force_customer = false ) {
627
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
626
+	protected function get_source($user_id, $force_customer = false) {
627
+		$stripe_customer = new WC_Stripe_Customer($user_id);
628 628
 		$stripe_source   = false;
629 629
 		$token_id        = false;
630 630
 
631 631
 		// New CC info was entered and we have a new token to process
632
-		if ( isset( $_POST['stripe_token'] ) ) {
633
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
634
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
632
+		if (isset($_POST['stripe_token'])) {
633
+			$stripe_token     = wc_clean($_POST['stripe_token']);
634
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
635 635
 
636 636
 			// This is true if the user wants to store the card to their account.
637
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
638
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
637
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
638
+				$stripe_source = $stripe_customer->add_card($stripe_token);
639 639
 
640
-				if ( is_wp_error( $stripe_source ) ) {
641
-					throw new Exception( $stripe_source->get_error_message() );
640
+				if (is_wp_error($stripe_source)) {
641
+					throw new Exception($stripe_source->get_error_message());
642 642
 				}
643 643
 			} else {
644 644
 				// Not saving token, so don't define customer either.
645 645
 				$stripe_source   = $stripe_token;
646 646
 				$stripe_customer = false;
647 647
 			}
648
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
648
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
649 649
 			// Use an existing token, and then process the payment
650 650
 
651
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
652
-			$token    = WC_Payment_Tokens::get( $token_id );
651
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
652
+			$token    = WC_Payment_Tokens::get($token_id);
653 653
 
654
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
655
-				WC()->session->set( 'refresh_totals', true );
656
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
654
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
655
+				WC()->session->set('refresh_totals', true);
656
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
657 657
 			}
658 658
 
659 659
 			$stripe_source = $token->get_token();
@@ -677,16 +677,16 @@  discard block
 block discarded – undo
677 677
 	 * @param object $order
678 678
 	 * @return object
679 679
 	 */
680
-	protected function get_order_source( $order = null ) {
680
+	protected function get_order_source($order = null) {
681 681
 		$stripe_customer = new WC_Stripe_Customer();
682 682
 		$stripe_source   = false;
683 683
 		$token_id        = false;
684 684
 
685
-		if ( $order ) {
686
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
687
-				$stripe_customer->set_id( $meta_value );
685
+		if ($order) {
686
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
687
+				$stripe_customer->set_id($meta_value);
688 688
 			}
689
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
689
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
690 690
 				$stripe_source = $meta_value;
691 691
 			}
692 692
 		}
@@ -709,57 +709,57 @@  discard block
 block discarded – undo
709 709
 	 *
710 710
 	 * @return array|void
711 711
 	 */
712
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
712
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
713 713
 		try {
714
-			$order  = wc_get_order( $order_id );
715
-			$source = $this->get_source( get_current_user_id(), $force_customer );
714
+			$order  = wc_get_order($order_id);
715
+			$source = $this->get_source(get_current_user_id(), $force_customer);
716 716
 
717
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
718
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
719
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
720
-				throw new Exception( $error_msg );
717
+			if (empty($source->source) && empty($source->customer)) {
718
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
719
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
720
+				throw new Exception($error_msg);
721 721
 			}
722 722
 
723 723
 			// Store source to order meta.
724
-			$this->save_source( $order, $source );
724
+			$this->save_source($order, $source);
725 725
 
726 726
 			// Handle payment.
727
-			if ( $order->get_total() > 0 ) {
727
+			if ($order->get_total() > 0) {
728 728
 
729
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
730
-					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 ) ) );
729
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
730
+					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)));
731 731
 				}
732 732
 
733
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
733
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
734 734
 
735 735
 				// Make the request.
736
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
736
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
737 737
 
738
-				if ( is_wp_error( $response ) ) {
738
+				if (is_wp_error($response)) {
739 739
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
740
-					if ( 'customer' === $response->get_error_code() && $retry ) {
741
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
742
-						return $this->process_payment( $order_id, false, $force_customer );
740
+					if ('customer' === $response->get_error_code() && $retry) {
741
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
742
+						return $this->process_payment($order_id, false, $force_customer);
743 743
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
744
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
745
-						$token = WC_Payment_Tokens::get( $source->token_id );
744
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
745
+						$token = WC_Payment_Tokens::get($source->token_id);
746 746
 						$token->delete();
747
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
748
-						$order->add_order_note( $message );
749
-						throw new Exception( $message );
747
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
748
+						$order->add_order_note($message);
749
+						throw new Exception($message);
750 750
 					}
751 751
 
752 752
 					$localized_messages = $this->get_localized_messages();
753 753
 
754
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
754
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
755 755
 
756
-					$order->add_order_note( $message );
756
+					$order->add_order_note($message);
757 757
 
758
-					throw new Exception( $message );
758
+					throw new Exception($message);
759 759
 				}
760 760
 
761 761
 				// Process valid response.
762
-				$this->process_response( $response, $order );
762
+				$this->process_response($response, $order);
763 763
 			} else {
764 764
 				$order->payment_complete();
765 765
 			}
@@ -767,23 +767,23 @@  discard block
 block discarded – undo
767 767
 			// Remove cart.
768 768
 			WC()->cart->empty_cart();
769 769
 
770
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
770
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
771 771
 
772 772
 			// Return thank you page redirect.
773 773
 			return array(
774 774
 				'result'   => 'success',
775
-				'redirect' => $this->get_return_url( $order ),
775
+				'redirect' => $this->get_return_url($order),
776 776
 			);
777 777
 
778
-		} catch ( Exception $e ) {
779
-			wc_add_notice( $e->getMessage(), 'error' );
780
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
778
+		} catch (Exception $e) {
779
+			wc_add_notice($e->getMessage(), 'error');
780
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
781 781
 
782
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
783
-				$this->send_failed_order_email( $order_id );
782
+			if ($order->has_status(array('pending', 'failed'))) {
783
+				$this->send_failed_order_email($order_id);
784 784
 			}
785 785
 
786
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
786
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
787 787
 
788 788
 			return array(
789 789
 				'result'   => 'fail',
@@ -798,52 +798,52 @@  discard block
 block discarded – undo
798 798
 	 * @param WC_Order $order For to which the source applies.
799 799
 	 * @param stdClass $source Source information.
800 800
 	 */
801
-	protected function save_source( $order, $source ) {
801
+	protected function save_source($order, $source) {
802 802
 		// Store source in the order.
803
-		if ( $source->customer ) {
804
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
803
+		if ($source->customer) {
804
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
805 805
 		}
806
-		if ( $source->source ) {
807
-			update_post_meta( $order->id, '_stripe_card_id', $source->source );
806
+		if ($source->source) {
807
+			update_post_meta($order->id, '_stripe_card_id', $source->source);
808 808
 		}
809 809
 	}
810 810
 
811 811
 	/**
812 812
 	 * Store extra meta data for an order from a Stripe Response.
813 813
 	 */
814
-	public function process_response( $response, $order ) {
815
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
814
+	public function process_response($response, $order) {
815
+		$this->log('Processing response: ' . print_r($response, true));
816 816
 
817 817
 		// Store charge data
818
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
819
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
818
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
819
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
820 820
 
821 821
 		// Store other data such as fees
822
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
822
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
823 823
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
824 824
 			// values are in the local currency of the Stripe account, not from WC.
825
-			$fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0;
826
-			$net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0;
827
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
828
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
825
+			$fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0;
826
+			$net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0;
827
+			update_post_meta($order->id, 'Stripe Fee', $fee);
828
+			update_post_meta($order->id, 'Net Revenue From Stripe', $net);
829 829
 		}
830 830
 
831
-		if ( $response->captured ) {
832
-			$order->payment_complete( $response->id );
831
+		if ($response->captured) {
832
+			$order->payment_complete($response->id);
833 833
 
834
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
835
-			$order->add_order_note( $message );
836
-			$this->log( 'Success: ' . $message );
834
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
835
+			$order->add_order_note($message);
836
+			$this->log('Success: ' . $message);
837 837
 
838 838
 		} else {
839
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
839
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
840 840
 
841
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
841
+			if ($order->has_status(array('pending', 'failed'))) {
842 842
 				$order->reduce_order_stock();
843 843
 			}
844 844
 
845
-			$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 ) );
846
-			$this->log( "Successful auth: $response->id" );
845
+			$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));
846
+			$this->log("Successful auth: $response->id");
847 847
 		}
848 848
 
849 849
 		return $response;
@@ -855,32 +855,32 @@  discard block
 block discarded – undo
855 855
 	 * @since 3.0.0
856 856
 	 */
857 857
 	public function add_payment_method() {
858
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
859
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
858
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
859
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
860 860
 			return;
861 861
 		}
862 862
 
863
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
864
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
863
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
864
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
865 865
 
866
-		if ( is_wp_error( $card ) ) {
866
+		if (is_wp_error($card)) {
867 867
 			$localized_messages = $this->get_localized_messages();
868
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
868
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
869 869
 
870 870
 			// loop through the errors to find matching localized message
871
-			foreach ( $card->errors as $error => $msg ) {
872
-				if ( isset( $localized_messages[ $error ] ) ) {
873
-					$error_msg = $localized_messages[ $error ];
871
+			foreach ($card->errors as $error => $msg) {
872
+				if (isset($localized_messages[$error])) {
873
+					$error_msg = $localized_messages[$error];
874 874
 				}
875 875
 			}
876 876
 
877
-			wc_add_notice( $error_msg, 'error' );
877
+			wc_add_notice($error_msg, 'error');
878 878
 			return;
879 879
 		}
880 880
 
881 881
 		return array(
882 882
 			'result'   => 'success',
883
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
883
+			'redirect' => wc_get_endpoint_url('payment-methods'),
884 884
 		);
885 885
 	}
886 886
 
@@ -890,36 +890,36 @@  discard block
 block discarded – undo
890 890
 	 * @param  float $amount
891 891
 	 * @return bool
892 892
 	 */
893
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
894
-		$order = wc_get_order( $order_id );
893
+	public function process_refund($order_id, $amount = null, $reason = '') {
894
+		$order = wc_get_order($order_id);
895 895
 
896
-		if ( ! $order || ! $order->get_transaction_id() ) {
896
+		if ( ! $order || ! $order->get_transaction_id()) {
897 897
 			return false;
898 898
 		}
899 899
 
900 900
 		$body = array();
901 901
 
902
-		if ( ! is_null( $amount ) ) {
903
-			$body['amount']	= $this->get_stripe_amount( $amount );
902
+		if ( ! is_null($amount)) {
903
+			$body['amount'] = $this->get_stripe_amount($amount);
904 904
 		}
905 905
 
906
-		if ( $reason ) {
906
+		if ($reason) {
907 907
 			$body['metadata'] = array(
908 908
 				'reason'	=> $reason,
909 909
 			);
910 910
 		}
911 911
 
912
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
912
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
913 913
 
914
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
914
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
915 915
 
916
-		if ( is_wp_error( $response ) ) {
917
-			$this->log( 'Error: ' . $response->get_error_message() );
916
+		if (is_wp_error($response)) {
917
+			$this->log('Error: ' . $response->get_error_message());
918 918
 			return $response;
919
-		} elseif ( ! empty( $response->id ) ) {
920
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
921
-			$order->add_order_note( $refund_message );
922
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
919
+		} elseif ( ! empty($response->id)) {
920
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
921
+			$order->add_order_note($refund_message);
922
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
923 923
 			return true;
924 924
 		}
925 925
 	}
@@ -932,10 +932,10 @@  discard block
 block discarded – undo
932 932
 	 * @param int $order_id
933 933
 	 * @return null
934 934
 	 */
935
-	public function send_failed_order_email( $order_id ) {
935
+	public function send_failed_order_email($order_id) {
936 936
 		$emails = WC()->mailer()->get_emails();
937
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
938
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
937
+		if ( ! empty($emails) && ! empty($order_id)) {
938
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
939 939
 		}
940 940
 	}
941 941
 
@@ -947,9 +947,9 @@  discard block
 block discarded – undo
947 947
 	 *
948 948
 	 * @param string $message
949 949
 	 */
950
-	public function log( $message ) {
951
-		if ( $this->logging ) {
952
-			WC_Stripe::log( $message );
950
+	public function log($message) {
951
+		if ($this->logging) {
952
+			WC_Stripe::log($message);
953 953
 		}
954 954
 	}
955 955
 }
Please login to merge, or discard this patch.