Completed
Push — master ( 352120...2afc1b )
by Roy
02:29
created
includes/class-wc-gateway-stripe.php 1 patch
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function __construct() {
115 115
 		$this->id                   = 'stripe';
116
-		$this->method_title         = __( 'Stripe', 'woocommerce-gateway-stripe' );
117
-		$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' );
116
+		$this->method_title         = __('Stripe', 'woocommerce-gateway-stripe');
117
+		$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');
118 118
 		$this->has_fields           = true;
119 119
 		$this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s';
120 120
 		$this->supports             = array(
@@ -142,39 +142,39 @@  discard block
 block discarded – undo
142 142
 		$this->init_settings();
143 143
 
144 144
 		// Get setting values.
145
-		$this->title                  = $this->get_option( 'title' );
146
-		$this->description            = $this->get_option( 'description' );
147
-		$this->enabled                = $this->get_option( 'enabled' );
148
-		$this->testmode               = 'yes' === $this->get_option( 'testmode' );
149
-		$this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
150
-		$this->statement_descriptor   = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
151
-		$this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
152
-		$this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
153
-		$this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
154
-		$this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
155
-		$this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
156
-		$this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
157
-		$this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
158
-		$this->apple_pay              = 'yes' === $this->get_option( 'apple_pay' );
159
-		$this->apple_pay_button       = $this->get_option( 'apple_pay_button', 'black' );
160
-		$this->logging                = 'yes' === $this->get_option( 'logging' );
161
-		$this->allow_remember_me      = 'yes' === $this->get_option( 'allow_remember_me', 'no' );
162
-
163
-		if ( $this->stripe_checkout ) {
164
-			$this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' );
165
-		}
166
-
167
-		if ( $this->testmode ) {
168
-			$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' );
169
-			$this->description  = trim( $this->description );
170
-		}
171
-
172
-		WC_Stripe_API::set_secret_key( $this->secret_key );
145
+		$this->title                  = $this->get_option('title');
146
+		$this->description            = $this->get_option('description');
147
+		$this->enabled                = $this->get_option('enabled');
148
+		$this->testmode               = 'yes' === $this->get_option('testmode');
149
+		$this->capture                = 'yes' === $this->get_option('capture', 'yes');
150
+		$this->statement_descriptor   = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
151
+		$this->stripe_checkout        = 'yes' === $this->get_option('stripe_checkout');
152
+		$this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale');
153
+		$this->stripe_checkout_image  = $this->get_option('stripe_checkout_image', '');
154
+		$this->saved_cards            = 'yes' === $this->get_option('saved_cards');
155
+		$this->secret_key             = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key');
156
+		$this->publishable_key        = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key');
157
+		$this->bitcoin                = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin');
158
+		$this->apple_pay              = 'yes' === $this->get_option('apple_pay');
159
+		$this->apple_pay_button       = $this->get_option('apple_pay_button', 'black');
160
+		$this->logging                = 'yes' === $this->get_option('logging');
161
+		$this->allow_remember_me      = 'yes' === $this->get_option('allow_remember_me', 'no');
162
+
163
+		if ($this->stripe_checkout) {
164
+			$this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe');
165
+		}
166
+
167
+		if ($this->testmode) {
168
+			$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');
169
+			$this->description  = trim($this->description);
170
+		}
171
+
172
+		WC_Stripe_API::set_secret_key($this->secret_key);
173 173
 
174 174
 		// Hooks.
175
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
176
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
177
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
175
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
176
+		add_action('admin_notices', array($this, 'admin_notices'));
177
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
178 178
 	}
179 179
 
180 180
 	/**
@@ -184,24 +184,24 @@  discard block
 block discarded – undo
184 184
 	 * @return string
185 185
 	 */
186 186
 	public function get_icon() {
187
-		$ext   = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png';
188
-		$style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : '';
187
+		$ext   = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png';
188
+		$style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : '';
189 189
 
190
-		$icon  = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />';
191
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />';
192
-		$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />';
190
+		$icon  = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />';
191
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />';
192
+		$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />';
193 193
 
194
-		if ( 'USD' === get_woocommerce_currency() ) {
195
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />';
196
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />';
197
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />';
194
+		if ('USD' === get_woocommerce_currency()) {
195
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />';
196
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />';
197
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />';
198 198
 		}
199 199
 
200
-		if ( $this->bitcoin && $this->stripe_checkout ) {
201
-			$icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />';
200
+		if ($this->bitcoin && $this->stripe_checkout) {
201
+			$icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />';
202 202
 		}
203 203
 
204
-		return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
204
+		return apply_filters('woocommerce_gateway_icon', $icon, $this->id);
205 205
 	}
206 206
 
207 207
 	/**
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return float|int
214 214
 	 */
215
-	public function get_stripe_amount( $total, $currency = '' ) {
216
-		if ( ! $currency ) {
215
+	public function get_stripe_amount($total, $currency = '') {
216
+		if ( ! $currency) {
217 217
 			$currency = get_woocommerce_currency();
218 218
 		}
219
-		switch ( strtoupper( $currency ) ) {
219
+		switch (strtoupper($currency)) {
220 220
 			// Zero decimal currencies.
221 221
 			case 'BIF' :
222 222
 			case 'CLP' :
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
 			case 'XAF' :
234 234
 			case 'XOF' :
235 235
 			case 'XPF' :
236
-				$total = absint( $total );
236
+				$total = absint($total);
237 237
 				break;
238 238
 			default :
239
-				$total = round( $total, 2 ) * 100; // In cents.
239
+				$total = round($total, 2) * 100; // In cents.
240 240
 				break;
241 241
 		}
242 242
 		return $total;
@@ -246,13 +246,13 @@  discard block
 block discarded – undo
246 246
 	 * Check if SSL is enabled and notify the user
247 247
 	 */
248 248
 	public function admin_notices() {
249
-		if ( 'no' === $this->enabled ) {
249
+		if ('no' === $this->enabled) {
250 250
 			return;
251 251
 		}
252 252
 
253 253
 		// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
254
-		if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) {
255
-			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>';
254
+		if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) {
255
+			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>';
256 256
 		}
257 257
 	}
258 258
 
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
 	 * Check if this gateway is enabled
261 261
 	 */
262 262
 	public function is_available() {
263
-		if ( 'yes' === $this->enabled ) {
264
-			if ( ! $this->testmode && is_checkout() && ! is_ssl() ) {
263
+		if ('yes' === $this->enabled) {
264
+			if ( ! $this->testmode && is_checkout() && ! is_ssl()) {
265 265
 				return false;
266 266
 			}
267
-			if ( ! $this->secret_key || ! $this->publishable_key ) {
267
+			if ( ! $this->secret_key || ! $this->publishable_key) {
268 268
 				return false;
269 269
 			}
270 270
 			return true;
@@ -276,17 +276,17 @@  discard block
 block discarded – undo
276 276
 	 * Initialise Gateway Settings Form Fields
277 277
 	 */
278 278
 	public function init_form_fields() {
279
-		if ( ! isset( $_GET['page'] ) || ! isset( $_GET['tab'] ) || ! isset( $_GET['section'] ) ) {
279
+		if ( ! isset($_GET['page']) || ! isset($_GET['tab']) || ! isset($_GET['section'])) {
280 280
 			return;
281 281
 		}
282 282
 		
283
-		if ( 'wc-settings' !== $_GET['page'] || 'checkout' !== $_GET['tab'] || 'stripe' !== $_GET['section'] ) {
283
+		if ('wc-settings' !== $_GET['page'] || 'checkout' !== $_GET['tab'] || 'stripe' !== $_GET['section']) {
284 284
 			return;
285 285
 		}
286 286
 
287
-		$this->form_fields = include( 'settings-stripe.php' );
287
+		$this->form_fields = include('settings-stripe.php');
288 288
 
289
-		wc_enqueue_js( "
289
+		wc_enqueue_js("
290 290
 			jQuery( function( $ ) {
291 291
 				$( document.body ).on( 'change', '#woocommerce_stripe_testmode', function() {
292 292
 					var test_secret_key = $( '#woocommerce_stripe_test_secret_key' ).parents( 'tr' ).eq( 0 ),
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 					var value = $( this ).val();
332 332
 
333 333
 					if ( value.indexOf( '_test_' ) >= 0 ) {
334
-						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ) . "</span>' );
334
+						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe') . "</span>' );
335 335
 					} else {
336 336
 						$( this ).css( 'border-color', '' );
337 337
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 					var value = $( this ).val();
343 343
 
344 344
 					if ( value.indexOf( '_live_' ) >= 0 ) {
345
-						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ) . "</span>' );
345
+						$( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe') . "</span>' );
346 346
 					} else {
347 347
 						$( this ).css( 'border-color', '' );
348 348
 						$( '.stripe-error-description', $( this ).parent() ).remove();
@@ -357,54 +357,54 @@  discard block
 block discarded – undo
357 357
 	 */
358 358
 	public function payment_fields() {
359 359
 		$user                 = wp_get_current_user();
360
-		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards;
360
+		$display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards;
361 361
 		$total                = WC()->cart->total;
362 362
 
363 363
 		// If paying from order, we need to get total from order not cart.
364
-		if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) {
365
-			$order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) );
364
+		if (isset($_GET['pay_for_order']) && isset($_GET['key'])) {
365
+			$order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key'])));
366 366
 			$total = $order->get_total();
367 367
 		}
368 368
 
369
-		if ( $user->ID ) {
370
-			$user_email = get_user_meta( $user->ID, 'billing_email', true );
369
+		if ($user->ID) {
370
+			$user_email = get_user_meta($user->ID, 'billing_email', true);
371 371
 			$user_email = $user_email ? $user_email : $user->user_email;
372 372
 		} else {
373 373
 			$user_email = '';
374 374
 		}
375 375
 
376
-		if ( is_add_payment_method_page() ) {
377
-			$pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' );
376
+		if (is_add_payment_method_page()) {
377
+			$pay_button_text = __('Add Card', 'woocommerce-gateway-stripe');
378 378
 		} else {
379 379
 			$pay_button_text = '';
380 380
 		}
381 381
 
382 382
 		echo '<div
383 383
 			id="stripe-payment-data"
384
-			data-panel-label="' . esc_attr( $pay_button_text ) . '"
384
+			data-panel-label="' . esc_attr($pay_button_text) . '"
385 385
 			data-description=""
386
-			data-email="' . esc_attr( $user_email ) . '"
387
-			data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '"
388
-			data-name="' . esc_attr( $this->statement_descriptor ) . '"
389
-			data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '"
390
-			data-image="' . esc_attr( $this->stripe_checkout_image ) . '"
391
-			data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '"
392
-			data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '"
393
-			data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">';
386
+			data-email="' . esc_attr($user_email) . '"
387
+			data-amount="' . esc_attr($this->get_stripe_amount($total)) . '"
388
+			data-name="' . esc_attr($this->statement_descriptor) . '"
389
+			data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '"
390
+			data-image="' . esc_attr($this->stripe_checkout_image) . '"
391
+			data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '"
392
+			data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '"
393
+			data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">';
394 394
 
395
-		if ( $this->description ) {
396
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) );
395
+		if ($this->description) {
396
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)));
397 397
 		}
398 398
 
399
-		if ( $display_tokenization ) {
399
+		if ($display_tokenization) {
400 400
 			$this->tokenization_script();
401 401
 			$this->saved_payment_methods();
402 402
 		}
403 403
 
404
-		if ( ! $this->stripe_checkout ) {
404
+		if ( ! $this->stripe_checkout) {
405 405
 			$this->form();
406 406
 
407
-			if ( $display_tokenization ) {
407
+			if ($display_tokenization) {
408 408
 				$this->save_payment_method_checkbox();
409 409
 			}
410 410
 		}
@@ -420,20 +420,20 @@  discard block
 block discarded – undo
420 420
 	 * @return array
421 421
 	 */
422 422
 	public function get_localized_messages() {
423
-		return apply_filters( 'wc_stripe_localized_messages', array(
424
-			'invalid_number'        => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
425
-			'invalid_expiry_month'  => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
426
-			'invalid_expiry_year'   => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
427
-			'invalid_cvc'           => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
428
-			'incorrect_number'      => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
429
-			'expired_card'          => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
430
-			'incorrect_cvc'         => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
431
-			'incorrect_zip'         => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
432
-			'card_declined'         => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
433
-			'missing'               => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
434
-			'processing_error'      => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
435
-			'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ),
436
-		) );
423
+		return apply_filters('wc_stripe_localized_messages', array(
424
+			'invalid_number'        => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
425
+			'invalid_expiry_month'  => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
426
+			'invalid_expiry_year'   => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
427
+			'invalid_cvc'           => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
428
+			'incorrect_number'      => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
429
+			'expired_card'          => __('The card has expired.', 'woocommerce-gateway-stripe'),
430
+			'incorrect_cvc'         => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
431
+			'incorrect_zip'         => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
432
+			'card_declined'         => __('The card was declined.', 'woocommerce-gateway-stripe'),
433
+			'missing'               => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
434
+			'processing_error'      => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
435
+			'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'),
436
+		));
437 437
 	}
438 438
 
439 439
 	/**
@@ -444,30 +444,30 @@  discard block
 block discarded – undo
444 444
 	 * @access public
445 445
 	 */
446 446
 	public function payment_scripts() {
447
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
447
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) {
448 448
 			return;
449 449
 		}
450 450
 
451
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
451
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
452 452
 
453
-		if ( $this->stripe_checkout ) {
454
-			wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true );
455
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true );
453
+		if ($this->stripe_checkout) {
454
+			wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true);
455
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true);
456 456
 		} else {
457
-			wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true );
458
-			wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true );
457
+			wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true);
458
+			wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true);
459 459
 		}
460 460
 
461 461
 		$stripe_params = array(
462 462
 			'key'                  => $this->publishable_key,
463
-			'i18n_terms'           => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ),
464
-			'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ),
463
+			'i18n_terms'           => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'),
464
+			'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'),
465 465
 		);
466 466
 
467 467
 		// If we're on the pay page we need to pass stripe.js the address of the order.
468
-		if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
469
-			$order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) );
470
-			$order    = wc_get_order( $order_id );
468
+		if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) {
469
+			$order_id = wc_get_order_id_by_order_key(urldecode($_GET['key']));
470
+			$order    = wc_get_order($order_id);
471 471
 
472 472
 			$stripe_params['billing_first_name'] = $order->billing_first_name;
473 473
 			$stripe_params['billing_last_name']  = $order->billing_last_name;
@@ -479,14 +479,14 @@  discard block
 block discarded – undo
479 479
 			$stripe_params['billing_country']    = $order->billing_country;
480 480
 		}
481 481
 
482
-		$stripe_params['no_prepaid_card_msg']                     = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' );
483
-		$stripe_params['allow_prepaid_card']                      = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no';
484
-		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no';
482
+		$stripe_params['no_prepaid_card_msg']                     = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe');
483
+		$stripe_params['allow_prepaid_card']                      = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no';
484
+		$stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no';
485 485
 
486 486
 		// merge localized messages to be use in JS
487
-		$stripe_params = array_merge( $stripe_params, $this->get_localized_messages() );
487
+		$stripe_params = array_merge($stripe_params, $this->get_localized_messages());
488 488
 
489
-		wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) );
489
+		wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params));
490 490
 	}
491 491
 
492 492
 	/**
@@ -495,31 +495,31 @@  discard block
 block discarded – undo
495 495
 	 * @param  object $source
496 496
 	 * @return array()
497 497
 	 */
498
-	protected function generate_payment_request( $order, $source ) {
498
+	protected function generate_payment_request($order, $source) {
499 499
 		$post_data                = array();
500
-		$post_data['currency']    = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() );
501
-		$post_data['amount']      = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] );
502
-		$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() );
500
+		$post_data['currency']    = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
501
+		$post_data['amount']      = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
502
+		$post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number());
503 503
 		$post_data['capture']     = $this->capture ? 'true' : 'false';
504 504
 
505
-		if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
505
+		if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
506 506
 			$post_data['receipt_email'] = $order->billing_email;
507 507
 		}
508 508
 
509
-		$post_data['expand[]']    = 'balance_transaction';
509
+		$post_data['expand[]'] = 'balance_transaction';
510 510
 
511 511
 		$metadata = array(
512
-			__( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $order->billing_first_name ) . ' ' . sanitize_text_field( $order->billing_last_name ),
513
-			__( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $order->billing_email ),
512
+			__('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($order->billing_first_name) . ' ' . sanitize_text_field($order->billing_last_name),
513
+			__('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($order->billing_email),
514 514
 		);
515 515
 
516
-		$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source );
516
+		$post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source);
517 517
 
518
-		if ( $source->customer ) {
518
+		if ($source->customer) {
519 519
 			$post_data['customer'] = $source->customer;
520 520
 		}
521 521
 
522
-		if ( $source->source ) {
522
+		if ($source->source) {
523 523
 			$post_data['source'] = $source->source;
524 524
 		}
525 525
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 		 * @param WC_Order $order
532 532
 		 * @param object $source
533 533
 		 */
534
-		return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source );
534
+		return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source);
535 535
 	}
536 536
 
537 537
 	/**
@@ -543,37 +543,37 @@  discard block
 block discarded – undo
543 543
 	 * @throws Exception When card was not added or for and invalid card.
544 544
 	 * @return object
545 545
 	 */
546
-	protected function get_source( $user_id, $force_customer = false ) {
547
-		$stripe_customer = new WC_Stripe_Customer( $user_id );
546
+	protected function get_source($user_id, $force_customer = false) {
547
+		$stripe_customer = new WC_Stripe_Customer($user_id);
548 548
 		$stripe_source   = false;
549 549
 		$token_id        = false;
550 550
 
551 551
 		// New CC info was entered and we have a new token to process
552
-		if ( isset( $_POST['stripe_token'] ) ) {
553
-			$stripe_token     = wc_clean( $_POST['stripe_token'] );
554
-			$maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] );
552
+		if (isset($_POST['stripe_token'])) {
553
+			$stripe_token     = wc_clean($_POST['stripe_token']);
554
+			$maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']);
555 555
 
556 556
 			// This is true if the user wants to store the card to their account.
557
-			if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) {
558
-				$stripe_source = $stripe_customer->add_card( $stripe_token );
557
+			if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) {
558
+				$stripe_source = $stripe_customer->add_card($stripe_token);
559 559
 
560
-				if ( is_wp_error( $stripe_source ) ) {
561
-					throw new Exception( $stripe_source->get_error_message() );
560
+				if (is_wp_error($stripe_source)) {
561
+					throw new Exception($stripe_source->get_error_message());
562 562
 				}
563 563
 			} else {
564 564
 				// Not saving token, so don't define customer either.
565 565
 				$stripe_source   = $stripe_token;
566 566
 				$stripe_customer = false;
567 567
 			}
568
-		} elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) {
568
+		} elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) {
569 569
 			// Use an existing token, and then process the payment
570 570
 
571
-			$token_id = wc_clean( $_POST['wc-stripe-payment-token'] );
572
-			$token    = WC_Payment_Tokens::get( $token_id );
571
+			$token_id = wc_clean($_POST['wc-stripe-payment-token']);
572
+			$token    = WC_Payment_Tokens::get($token_id);
573 573
 
574
-			if ( ! $token || $token->get_user_id() !== get_current_user_id() ) {
575
-				WC()->session->set( 'refresh_totals', true );
576
-				throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) );
574
+			if ( ! $token || $token->get_user_id() !== get_current_user_id()) {
575
+				WC()->session->set('refresh_totals', true);
576
+				throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe'));
577 577
 			}
578 578
 
579 579
 			$stripe_source = $token->get_token();
@@ -597,16 +597,16 @@  discard block
 block discarded – undo
597 597
 	 * @param object $order
598 598
 	 * @return object
599 599
 	 */
600
-	protected function get_order_source( $order = null ) {
600
+	protected function get_order_source($order = null) {
601 601
 		$stripe_customer = new WC_Stripe_Customer();
602 602
 		$stripe_source   = false;
603 603
 		$token_id        = false;
604 604
 
605
-		if ( $order ) {
606
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) {
607
-				$stripe_customer->set_id( $meta_value );
605
+		if ($order) {
606
+			if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
607
+				$stripe_customer->set_id($meta_value);
608 608
 			}
609
-			if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) {
609
+			if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
610 610
 				$stripe_source = $meta_value;
611 611
 			}
612 612
 		}
@@ -629,57 +629,57 @@  discard block
 block discarded – undo
629 629
 	 *
630 630
 	 * @return array|void
631 631
 	 */
632
-	public function process_payment( $order_id, $retry = true, $force_customer = false ) {
632
+	public function process_payment($order_id, $retry = true, $force_customer = false) {
633 633
 		try {
634
-			$order  = wc_get_order( $order_id );
635
-			$source = $this->get_source( get_current_user_id(), $force_customer );
634
+			$order  = wc_get_order($order_id);
635
+			$source = $this->get_source(get_current_user_id(), $force_customer);
636 636
 
637
-			if ( empty( $source->source ) && empty( $source->customer ) ) {
638
-				$error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' );
639
-				$error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' );
640
-				throw new Exception( $error_msg );
637
+			if (empty($source->source) && empty($source->customer)) {
638
+				$error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe');
639
+				$error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe');
640
+				throw new Exception($error_msg);
641 641
 			}
642 642
 
643 643
 			// Store source to order meta.
644
-			$this->save_source( $order, $source );
644
+			$this->save_source($order, $source);
645 645
 
646 646
 			// Handle payment.
647
-			if ( $order->get_total() > 0 ) {
647
+			if ($order->get_total() > 0) {
648 648
 
649
-				if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) {
650
-					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 ) ) );
649
+				if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) {
650
+					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)));
651 651
 				}
652 652
 
653
-				$this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
653
+				$this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}");
654 654
 
655 655
 				// Make the request.
656
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
656
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
657 657
 
658
-				if ( is_wp_error( $response ) ) {
658
+				if (is_wp_error($response)) {
659 659
 					// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
660
-					if ( 'customer' === $response->get_error_code() && $retry ) {
661
-						delete_user_meta( get_current_user_id(), '_stripe_customer_id' );
662
-						return $this->process_payment( $order_id, false, $force_customer );
660
+					if ('customer' === $response->get_error_code() && $retry) {
661
+						delete_user_meta(get_current_user_id(), '_stripe_customer_id');
662
+						return $this->process_payment($order_id, false, $force_customer);
663 663
 						// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
664
-					} elseif ( 'source' === $response->get_error_code() && $source->token_id ) {
665
-						$token = WC_Payment_Tokens::get( $source->token_id );
664
+					} elseif ('source' === $response->get_error_code() && $source->token_id) {
665
+						$token = WC_Payment_Tokens::get($source->token_id);
666 666
 						$token->delete();
667
-						$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
668
-						$order->add_order_note( $message );
669
-						throw new Exception( $message );
667
+						$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
668
+						$order->add_order_note($message);
669
+						throw new Exception($message);
670 670
 					}
671 671
 
672 672
 					$localized_messages = $this->get_localized_messages();
673 673
 
674
-					$message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message();
674
+					$message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message();
675 675
 
676
-					$order->add_order_note( $message );
676
+					$order->add_order_note($message);
677 677
 
678
-					throw new Exception( $message );
678
+					throw new Exception($message);
679 679
 				}
680 680
 
681 681
 				// Process valid response.
682
-				$this->process_response( $response, $order );
682
+				$this->process_response($response, $order);
683 683
 			} else {
684 684
 				$order->payment_complete();
685 685
 			}
@@ -687,23 +687,23 @@  discard block
 block discarded – undo
687 687
 			// Remove cart.
688 688
 			WC()->cart->empty_cart();
689 689
 
690
-			do_action( 'wc_gateway_stripe_process_payment', $response, $order );
690
+			do_action('wc_gateway_stripe_process_payment', $response, $order);
691 691
 
692 692
 			// Return thank you page redirect.
693 693
 			return array(
694 694
 				'result'   => 'success',
695
-				'redirect' => $this->get_return_url( $order ),
695
+				'redirect' => $this->get_return_url($order),
696 696
 			);
697 697
 
698
-		} catch ( Exception $e ) {
699
-			wc_add_notice( $e->getMessage(), 'error' );
700
-			$this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
698
+		} catch (Exception $e) {
699
+			wc_add_notice($e->getMessage(), 'error');
700
+			$this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage()));
701 701
 
702
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
703
-				$this->send_failed_order_email( $order_id );
702
+			if ($order->has_status(array('pending', 'failed'))) {
703
+				$this->send_failed_order_email($order_id);
704 704
 			}
705 705
 
706
-			do_action( 'wc_gateway_stripe_process_payment_error', $e, $order );
706
+			do_action('wc_gateway_stripe_process_payment_error', $e, $order);
707 707
 
708 708
 			return array(
709 709
 				'result'   => 'fail',
@@ -718,52 +718,52 @@  discard block
 block discarded – undo
718 718
 	 * @param WC_Order $order For to which the source applies.
719 719
 	 * @param stdClass $source Source information.
720 720
 	 */
721
-	protected function save_source( $order, $source ) {
721
+	protected function save_source($order, $source) {
722 722
 		// Store source in the order.
723
-		if ( $source->customer ) {
724
-			update_post_meta( $order->id, '_stripe_customer_id', $source->customer );
723
+		if ($source->customer) {
724
+			update_post_meta($order->id, '_stripe_customer_id', $source->customer);
725 725
 		}
726
-		if ( $source->source ) {
727
-			update_post_meta( $order->id, '_stripe_card_id', $source->source );
726
+		if ($source->source) {
727
+			update_post_meta($order->id, '_stripe_card_id', $source->source);
728 728
 		}
729 729
 	}
730 730
 
731 731
 	/**
732 732
 	 * Store extra meta data for an order from a Stripe Response.
733 733
 	 */
734
-	public function process_response( $response, $order ) {
735
-		$this->log( 'Processing response: ' . print_r( $response, true ) );
734
+	public function process_response($response, $order) {
735
+		$this->log('Processing response: ' . print_r($response, true));
736 736
 
737 737
 		// Store charge data
738
-		update_post_meta( $order->id, '_stripe_charge_id', $response->id );
739
-		update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' );
738
+		update_post_meta($order->id, '_stripe_charge_id', $response->id);
739
+		update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no');
740 740
 
741 741
 		// Store other data such as fees
742
-		if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) {
742
+		if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) {
743 743
 			// Fees and Net needs to both come from Stripe to be accurate as the returned
744 744
 			// values are in the local currency of the Stripe account, not from WC.
745
-			$fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0;
746
-			$net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0;
747
-			update_post_meta( $order->id, 'Stripe Fee', $fee );
748
-			update_post_meta( $order->id, 'Net Revenue From Stripe', $net );
745
+			$fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0;
746
+			$net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0;
747
+			update_post_meta($order->id, 'Stripe Fee', $fee);
748
+			update_post_meta($order->id, 'Net Revenue From Stripe', $net);
749 749
 		}
750 750
 
751
-		if ( $response->captured ) {
752
-			$order->payment_complete( $response->id );
751
+		if ($response->captured) {
752
+			$order->payment_complete($response->id);
753 753
 
754
-			$message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id );
755
-			$order->add_order_note( $message );
756
-			$this->log( 'Success: ' . $message );
754
+			$message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id);
755
+			$order->add_order_note($message);
756
+			$this->log('Success: ' . $message);
757 757
 
758 758
 		} else {
759
-			add_post_meta( $order->id, '_transaction_id', $response->id, true );
759
+			add_post_meta($order->id, '_transaction_id', $response->id, true);
760 760
 
761
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
761
+			if ($order->has_status(array('pending', 'failed'))) {
762 762
 				$order->reduce_order_stock();
763 763
 			}
764 764
 
765
-			$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 ) );
766
-			$this->log( "Successful auth: $response->id" );
765
+			$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));
766
+			$this->log("Successful auth: $response->id");
767 767
 		}
768 768
 
769 769
 		return $response;
@@ -775,32 +775,32 @@  discard block
 block discarded – undo
775 775
 	 * @since 3.0.0
776 776
 	 */
777 777
 	public function add_payment_method() {
778
-		if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) {
779
-			wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' );
778
+		if (empty($_POST['stripe_token']) || ! is_user_logged_in()) {
779
+			wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error');
780 780
 			return;
781 781
 		}
782 782
 
783
-		$stripe_customer = new WC_Stripe_Customer( get_current_user_id() );
784
-		$card            = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) );
783
+		$stripe_customer = new WC_Stripe_Customer(get_current_user_id());
784
+		$card            = $stripe_customer->add_card(wc_clean($_POST['stripe_token']));
785 785
 
786
-		if ( is_wp_error( $card ) ) {
786
+		if (is_wp_error($card)) {
787 787
 			$localized_messages = $this->get_localized_messages();
788
-			$error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' );
788
+			$error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe');
789 789
 
790 790
 			// loop through the errors to find matching localized message
791
-			foreach ( $card->errors as $error => $msg ) {
792
-				if ( isset( $localized_messages[ $error ] ) ) {
793
-					$error_msg = $localized_messages[ $error ];
791
+			foreach ($card->errors as $error => $msg) {
792
+				if (isset($localized_messages[$error])) {
793
+					$error_msg = $localized_messages[$error];
794 794
 				}
795 795
 			}
796 796
 
797
-			wc_add_notice( $error_msg, 'error' );
797
+			wc_add_notice($error_msg, 'error');
798 798
 			return;
799 799
 		}
800 800
 
801 801
 		return array(
802 802
 			'result'   => 'success',
803
-			'redirect' => wc_get_endpoint_url( 'payment-methods' ),
803
+			'redirect' => wc_get_endpoint_url('payment-methods'),
804 804
 		);
805 805
 	}
806 806
 
@@ -810,36 +810,36 @@  discard block
 block discarded – undo
810 810
 	 * @param  float $amount
811 811
 	 * @return bool
812 812
 	 */
813
-	public function process_refund( $order_id, $amount = null, $reason = '' ) {
814
-		$order = wc_get_order( $order_id );
813
+	public function process_refund($order_id, $amount = null, $reason = '') {
814
+		$order = wc_get_order($order_id);
815 815
 
816
-		if ( ! $order || ! $order->get_transaction_id() ) {
816
+		if ( ! $order || ! $order->get_transaction_id()) {
817 817
 			return false;
818 818
 		}
819 819
 
820 820
 		$body = array();
821 821
 
822
-		if ( ! is_null( $amount ) ) {
823
-			$body['amount']	= $this->get_stripe_amount( $amount );
822
+		if ( ! is_null($amount)) {
823
+			$body['amount'] = $this->get_stripe_amount($amount);
824 824
 		}
825 825
 
826
-		if ( $reason ) {
826
+		if ($reason) {
827 827
 			$body['metadata'] = array(
828 828
 				'reason'	=> $reason,
829 829
 			);
830 830
 		}
831 831
 
832
-		$this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
832
+		$this->log("Info: Beginning refund for order $order_id for the amount of {$amount}");
833 833
 
834
-		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
834
+		$response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds');
835 835
 
836
-		if ( is_wp_error( $response ) ) {
837
-			$this->log( 'Error: ' . $response->get_error_message() );
836
+		if (is_wp_error($response)) {
837
+			$this->log('Error: ' . $response->get_error_message());
838 838
 			return $response;
839
-		} elseif ( ! empty( $response->id ) ) {
840
-			$refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
841
-			$order->add_order_note( $refund_message );
842
-			$this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) );
839
+		} elseif ( ! empty($response->id)) {
840
+			$refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason);
841
+			$order->add_order_note($refund_message);
842
+			$this->log('Success: ' . html_entity_decode(strip_tags($refund_message)));
843 843
 			return true;
844 844
 		}
845 845
 	}
@@ -852,10 +852,10 @@  discard block
 block discarded – undo
852 852
 	 * @param int $order_id
853 853
 	 * @return null
854 854
 	 */
855
-	public function send_failed_order_email( $order_id ) {
855
+	public function send_failed_order_email($order_id) {
856 856
 		$emails = WC()->mailer()->get_emails();
857
-		if ( ! empty( $emails ) && ! empty( $order_id ) ) {
858
-			$emails['WC_Email_Failed_Order']->trigger( $order_id );
857
+		if ( ! empty($emails) && ! empty($order_id)) {
858
+			$emails['WC_Email_Failed_Order']->trigger($order_id);
859 859
 		}
860 860
 	}
861 861
 
@@ -867,9 +867,9 @@  discard block
 block discarded – undo
867 867
 	 *
868 868
 	 * @param string $message
869 869
 	 */
870
-	public function log( $message ) {
871
-		if ( $this->logging ) {
872
-			WC_Stripe::log( $message );
870
+	public function log($message) {
871
+		if ($this->logging) {
872
+			WC_Stripe::log($message);
873 873
 		}
874 874
 	}
875 875
 }
Please login to merge, or discard this patch.